@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(); } }
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(); } }