Ejemplo n.º 1
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 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);
  }
  @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"));
  }
  @Before
  public void prepare() {
    MongoDBInstance.start();
    try {
      MongoProvider provider = new MongoProvider("localhost", 10000, "test", null, null);
      orgDao = new OrganizationDao();
      ReflectionTestUtils.setField(orgDao, "provider", provider);

      org = new Organization();
      org.setOrganizationId("orgId");
      org.setDatasets(new ArrayList<Dataset>());
      org.setOrganizationUri("testUri");
      org.setHarvestingMetadata(new HarvestingMetadata());
      ds = new Dataset();
      ds.setAccepted(true);
      ds.setAssignedToLdapId("Lemmy");
      ds.setCountry(Country.ALBANIA);
      ds.setCreated(new Date(1000));
      ds.setCreatedByLdapId("Lemmy");
      ds.setDataProvider("prov");
      ds.setDeaSigned(true);
      ds.setDescription("Test description");
      List<String> DQA = new ArrayList<>();
      DQA.add("test DQA");
      ds.setDQA(DQA);
      ds.setFirstPublished(new Date(1000));
      ds.setHarvestedAt(new Date(1000));
      ds.setLanguage(Language.AR);
      ds.setLastPublished(new Date(1000));
      ds.setMetadata(new OAIDatasetMetadata());
      ds.setName("testName");
      ds.setNotes("test Notes");
      ds.setRecordsPublished(100);
      ds.setRecordsSubmitted(199);
      ds.setReplacedBy("replacedBY");
      List<String> sources = new ArrayList<>();
      sources.add("testSource");
      ds.setSource(sources);
      List<String> subjects = new ArrayList<>();
      subjects.add("testSubject");
      ds.setSubject(subjects);
      ds.setSubmittedAt(new Date(1000));
      ds.setUpdated(new Date(1000));
      ds.setWorkflowStatus(WorkflowStatus.ACCEPTANCE);

      dsDao = new DatasetDao();
      ReflectionTestUtils.setField(dsDao, "provider", provider);

    } catch (IOException e) {
      e.printStackTrace();
    }
  }