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