@Test public void getFileTest() throws CatalogDBException { File file = user3.getProjects().get(0).getStudies().get(0).getFiles().get(0); QueryResult<File> fileQueryResult = catalogFileDBAdaptor.get(file.getUid(), null); System.out.println(fileQueryResult); try { System.out.println(catalogFileDBAdaptor.get(-1, null)); fail("Expected \"FileId not found\" exception"); } catch (CatalogDBException e) { System.out.println(e); } }
@Test public void getAllFilesTest() throws CatalogDBException { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); QueryResult<File> allFiles = catalogFileDBAdaptor.getAllInStudy(studyId, null); List<File> files = allFiles.getResult(); List<File> expectedFiles = user3.getProjects().get(0).getStudies().get(0).getFiles(); assertEquals(expectedFiles.size(), files.size()); for (File expectedFile : expectedFiles) { boolean found = false; for (File fileResult : allFiles.getResult()) { if (fileResult.getUid() == expectedFile.getUid()) found = true; } if (!found) { throw new CatalogDBException("The file " + expectedFile.getName() + " could not be found."); } } }
@Test public void modifyFileTest() throws CatalogDBException, IOException { File file = user3.getProjects().get(0).getStudies().get(0).getFiles().get(0); long fileId = file.getUid(); Document stats = new Document("stat1", 1).append("stat2", true).append("stat3", "ok" + StringUtils.randomString(20)); ObjectMap parameters = new ObjectMap(); parameters.put("status.name", File.FileStatus.READY); parameters.put("stats", stats); System.out.println(catalogFileDBAdaptor.update(fileId, parameters, QueryOptions.empty())); file = catalogFileDBAdaptor.get(fileId, null).first(); assertEquals(file.getStatus().getName(), File.FileStatus.READY); assertEquals(file.getStats(), stats); parameters = new ObjectMap(); parameters.put("stats", "{}"); System.out.println(catalogFileDBAdaptor.update(fileId, parameters, QueryOptions.empty())); file = catalogFileDBAdaptor.get(fileId, null).first(); assertEquals(file.getStats(), new LinkedHashMap<String, Object>()); }
@Test public void testAddSamples() throws Exception { long studyUid = user3.getProjects().get(0).getStudies().get(0).getUid(); Sample sample1 = catalogDBAdaptor.getCatalogSampleDBAdaptor().insert(studyUid, new Sample().setId("sample1").setStatus(new Status()), QueryOptions.empty()).first(); Sample sample2 = catalogDBAdaptor.getCatalogSampleDBAdaptor().insert(studyUid, new Sample().setId("sample2").setStatus(new Status()), QueryOptions.empty()).first(); File file = user3.getProjects().get(0).getStudies().get(0).getFiles().get(0); catalogFileDBAdaptor.addSamplesToFile(file.getUid(), Arrays.asList(sample1, sample2)); QueryResult<File> fileQueryResult = catalogFileDBAdaptor.get(file.getUid(), QueryOptions.empty()); assertEquals(2, fileQueryResult.first().getSamples().size()); assertTrue(Arrays.asList(sample1.getUid(), sample2.getUid()).containsAll( fileQueryResult.first().getSamples().stream().map(Sample::getUid).collect(Collectors.toList()))); Sample sample3 = catalogDBAdaptor.getCatalogSampleDBAdaptor().insert(studyUid, new Sample().setId("sample3").setStatus(new Status()), QueryOptions.empty()).first(); // Test we avoid duplicities catalogFileDBAdaptor.addSamplesToFile(file.getUid(), Arrays.asList(sample1, sample2, sample2, sample3)); fileQueryResult = catalogFileDBAdaptor.get(file.getUid(), QueryOptions.empty()); assertEquals(3, fileQueryResult.first().getSamples().size()); assertTrue(Arrays.asList(sample1.getUid(), sample2.getUid(), sample3.getUid()).containsAll( fileQueryResult.first().getSamples().stream().map(Sample::getUid).collect(Collectors.toList()))); }
List<File> files = study.getFiles(); study.setFiles(Collections.emptyList());
@Test public void testRemoveSamples() throws Exception { long studyUid = user3.getProjects().get(0).getStudies().get(0).getUid(); Sample sample1 = catalogDBAdaptor.getCatalogSampleDBAdaptor().insert(studyUid, new Sample().setId("sample1").setStatus(new Status()), QueryOptions.empty()).first(); Sample sample2 = catalogDBAdaptor.getCatalogSampleDBAdaptor().insert(studyUid, new Sample().setId("sample2").setStatus(new Status()), QueryOptions.empty()).first(); Sample sample3 = catalogDBAdaptor.getCatalogSampleDBAdaptor().insert(studyUid, new Sample().setId("sample3").setStatus(new Status()), QueryOptions.empty()).first(); File file = user3.getProjects().get(0).getStudies().get(0).getFiles().get(0); catalogFileDBAdaptor.addSamplesToFile(file.getUid(), Arrays.asList(sample1, sample2, sample3)); QueryResult<File> fileQueryResult = catalogFileDBAdaptor.get(file.getUid(), QueryOptions.empty()); assertEquals(3, fileQueryResult.first().getSamples().size()); assertTrue(Arrays.asList(sample1.getUid(), sample2.getUid(), sample3.getUid()) .containsAll(fileQueryResult.first().getSamples().stream().map(Sample::getUid).collect(Collectors.toList()))); catalogFileDBAdaptor.extractSampleFromFiles(new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), Arrays.asList(sample1.getUid(), sample3.getUid())); fileQueryResult = catalogFileDBAdaptor.get(file.getUid(), QueryOptions.empty()); assertEquals(1, fileQueryResult.first().getSamples().size()); assertTrue(fileQueryResult.first().getSamples().get(0).getUid() == sample2.getUid()); }