@Test
 public void testDeleteOrganization() {
   dsDao.create(ds);
   List<Dataset> datasets = new ArrayList<>();
   datasets.add(dsDao.getByName(ds.getName()));
   org.setDatasets(datasets);
   orgDao.create(org);
   orgDao.delete(org);
   Assert.assertNull(orgDao.getByOrganizationId(org.getOrganizationId()));
 }
 @Test
 public void testCreateRetrieveOrg() {
   dsDao.create(ds);
   List<Dataset> datasets = new ArrayList<>();
   datasets.add(dsDao.getByName(ds.getName()));
   org.setDatasets(datasets);
   orgDao.create(org);
   Organization retOrg = orgDao.getByOrganizationId(org.getOrganizationId());
   Assert.assertEquals(org.getOrganizationId(), retOrg.getOrganizationId());
   Assert.assertEquals(org.getOrganizationUri(), retOrg.getOrganizationUri());
   Assert.assertEquals(org.getDatasets().size(), retOrg.getDatasets().size());
 }
  @Test
  public void testGetAll() {
    dsDao.create(ds);
    List<Dataset> datasets = new ArrayList<>();
    datasets.add(dsDao.getByName(ds.getName()));
    org.setDatasets(datasets);
    orgDao.create(org);

    List<Organization> getAll = orgDao.getAll();

    Assert.assertTrue(getAll.size() == 1);
  }
Пример #4
0
  public void createDataset(Dataset dataset) {
    try {
      MongoProvider provider = new MongoProvider("localhost", 10000, "test", null, null);
      dsDao = new DatasetDao();
      orgDao = new OrganizationDao();
      org = new Organization();
      org.setOrganizationId("orgId");
      ArrayList<Dataset> datasets = new ArrayList<>();
      datasets.add(dataset);
      org.setDatasets(datasets);
      org.setOrganizationUri("testUri");
      org.setHarvestingMetadata(new HarvestingMetadata());

      Field field;
      try {
        field = DatasetDao.class.getDeclaredField("provider");
        field.setAccessible(true);
        field.set(dsDao, provider);

        field = OrganizationDao.class.getDeclaredField("provider");
        field.setAccessible(true);
        field.set(orgDao, provider);
      } catch (NoSuchFieldException e) {
        e.printStackTrace();
      } catch (SecurityException e) {
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      }
      dsDao.createDatasetForOrganization(org, dataset);
      orgDao.create(org);
      System.out.println(
          "Dataset: "
              + dsDao.getByName(dataset.getName()).getName()
              + " is saved in a virtual MongoDB");
      try {
        List<Dataset> allDatasetsByOrganization = orgDao.getAllDatasetsByOrganization("orgId");
        System.out.println("Datasets:");
        for (Dataset ds : allDatasetsByOrganization) {
          System.out.println(ds.getName());
        }
      } catch (NoOrganizationExceptionFound e) {
        e.printStackTrace();
      }
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }
  }
  @Test
  public void testDatasets() {
    dsDao.create(ds);
    List<Dataset> datasets = new ArrayList<>();
    datasets.add(dsDao.getByName(ds.getName()));
    org.setDatasets(datasets);
    orgDao.create(org);

    try {
      List<Dataset> dsRet = orgDao.getAllDatasetsByOrganization(org.getOrganizationId());
      Assert.assertTrue(dsRet.size() == 1);
    } catch (NoOrganizationExceptionFound e) {
      e.printStackTrace();
    }
  }
  @Test
  public void testUpdate() {
    dsDao.create(ds);
    List<Dataset> datasets = new ArrayList<>();
    datasets.add(dsDao.getByName(ds.getName()));
    org.setDatasets(datasets);
    orgDao.create(org);

    org.setOrganizationUri("testNew");
    org.setName("name");
    org.setModified(new Date());
    org.setCreated(new Date());
    List<Role> roles = new ArrayList<>();
    org.setRoles(roles);
    org.setAcronym("acronym");
    orgDao.update(org);
    Organization organization = orgDao.getByOrganizationId(org.getOrganizationId());

    Assert.assertTrue(StringUtils.equals(organization.getOrganizationUri(), "testNew"));
  }