private void joinFields(User user, QueryOptions options) throws CatalogDBException { if (options == null) { return; } if (user.getProjects() != null) { for (Project project : user.getProjects()) { joinFields(project, options); } } }
@Test public void createPanel() throws CatalogDBException { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); // DiseasePanel diseasePanel = new DiseasePanel("panel1", "Panel 1", 1, 1, "author", null, "description", Collections.emptyList(), // Arrays.asList(new VariantPanel().setId("variant1"), new VariantPanel().setId("variant2")), // Collections.emptyList(), Collections.emptyList(), null, Collections.emptyMap()); // QueryResult<DiseasePanel> panel = catalogPanelDBAdaptor.insert(studyId, diseasePanel, new QueryOptions()); // assertEquals(1, panel.getNumResults()); }
@Test public void getPanel() throws CatalogDBException { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); // DiseasePanel diseasePanel = new DiseasePanel("panel1", "Panel 1", 1, 1, "author", null, "description", Collections.emptyList(), Arrays.asList(new VariantPanel().setId("variant1"), // new VariantPanel().setId("variant2")), Collections.emptyList(), Collections.emptyList(), null, // Collections.emptyMap()); // QueryResult<DiseasePanel> panel = catalogPanelDBAdaptor.insert(studyId, diseasePanel, new QueryOptions()); // QueryResult<DiseasePanel> panel1 = catalogPanelDBAdaptor.get(panel.first().getUid(), new QueryOptions()); // assertEquals(1, panel1.getNumResults()); } }
@Test public void getAllJobTest() throws CatalogDBException { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); QueryResult<Job> allJobs = catalogJobDBAdaptor.getAllInStudy(studyId, null); System.out.println(allJobs); }
@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 testCreateIndividual() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); catalogIndividualDBAdaptor.insert(studyId, new Individual(), null); }
@Test public void testCreateIndividualAlreadyExists() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); catalogIndividualDBAdaptor.insert(studyId, new Individual("in1", "in1", null, "", null, 1, Collections .emptyList(), null), null); thrown.expect(CatalogDBException.class); //Name already exists catalogIndividualDBAdaptor.insert(studyId, new Individual("in1", "in1", null, "", null, 1, Collections .emptyList(), null), null); }
@Test public void testCreateIndividualFatherNotFound() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); thrown.expect(CatalogDBException.class); catalogIndividualDBAdaptor.insert(studyId, new Individual("in1", "in1", new Individual().setId("father").setUid(10), null, null, null, null, null, "", null, null, null, "", Collections.emptyList(), false, 1, Collections.emptyList(), Collections.emptyList(), null), null); }
@Test public void getProjectTest() throws CatalogDBException { long projectId = catalogProjectDBAdaptor.getId(user3.getId(), user3.getProjects().get(0).getId()); System.out.println("projectId = " + projectId); QueryResult<Project> project = catalogProjectDBAdaptor.get(projectId, null); System.out.println(project); assertNotNull(project.first()); thrown.expect(CatalogDBException.class); //"Expected \"bad id\" exception" catalogProjectDBAdaptor.get(-100, null); }
@Test public void testModifyIndividualBadFatherId() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); long individualId = catalogIndividualDBAdaptor.insert(studyId, new Individual("in1", "in1", IndividualProperty.Sex .UNKNOWN, "", null, 1, Collections.emptyList(), null), null).first().getUid(); thrown.expect(CatalogDBException.class); catalogIndividualDBAdaptor.update(individualId, new ObjectMap("fatherId", 4000), QueryOptions.empty()); }
@Test public void testModifyIndividualBadGender() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); long individualId = catalogIndividualDBAdaptor.insert(studyId, new Individual("in1", "in1", IndividualProperty.Sex .UNKNOWN, "", null, 1, Collections.emptyList(), null), null).first().getUid(); thrown.expect(CatalogDBException.class); catalogIndividualDBAdaptor.update(individualId, new ObjectMap("sex", "bad sex"), QueryOptions.empty()); }
@Test public void getProjectIdTest() throws CatalogDBException { assertTrue(catalogProjectDBAdaptor.getId(user3.getId(), user3.getProjects().get(0).getId()) != -1); assertTrue(catalogProjectDBAdaptor.getId(user3.getId(), "nonExistingProject") == -1); }
@Ignore @Test public void testModifyIndividualExistingName() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); long individualId = catalogIndividualDBAdaptor.insert(studyId, new Individual("in1", "in1", IndividualProperty.Sex .UNKNOWN, "", null, 1, Collections.emptyList(), null), null).first().getUid(); catalogIndividualDBAdaptor.insert(studyId, new Individual("in2", "in2", IndividualProperty.Sex.UNKNOWN, "", null, 1, Collections.emptyList(), null), null).first().getUid(); thrown.expect(CatalogDBException.class); catalogIndividualDBAdaptor.update(individualId, new ObjectMap("name", "in2"), QueryOptions.empty()); }
@Test public void testGetStudyIdByIndividualId() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); long individualId = catalogIndividualDBAdaptor.insert(studyId, new Individual().setStatus(new Status()), null).first().getUid(); long studyIdByIndividualId = catalogIndividualDBAdaptor.getStudyId(individualId); assertEquals(studyId, studyIdByIndividualId); }
@Test public void testGetIndividual() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); Individual individual = new Individual("an_individual", "An Individual", IndividualProperty.Sex.MALE, "", new Individual.Population(), 1, Collections.emptyList(), null); individual = catalogIndividualDBAdaptor.insert(studyId, individual, null).first(); Individual individual2 = catalogIndividualDBAdaptor.get(individual.getUid(), null).first(); assertEquals(individual.toString(), individual2.toString()); }
@Test public void testModifyIndividual() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); long individualId = catalogIndividualDBAdaptor.insert(studyId, new Individual("in1", "in1", IndividualProperty.Sex .UNKNOWN, "", null, 1, Collections.emptyList(), null), null).first().getUid(); ObjectMap params = new ObjectMap("sex", "MALE"); catalogIndividualDBAdaptor.update(individualId, params, QueryOptions.empty()); Individual individual = catalogIndividualDBAdaptor.get(individualId, null).first(); assertEquals(IndividualProperty.Sex.MALE, individual.getSex()); }
@Test @Ignore public void deleteSampleFail2Test() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); long fileId = dbAdaptorFactory.getCatalogFileDBAdaptor().getId(user3.getProjects().get(0).getStudies().get(0).getUid(), "data/file.vcf"); Sample hg0097 = new Sample("HG0097", "1000g", new Individual(), "A description", 1); QueryResult<Sample> createResult = dbAdaptorFactory.getCatalogSampleDBAdaptor().insert(studyId, hg0097, null); dbAdaptorFactory.getCatalogFileDBAdaptor().update(fileId, new ObjectMap(FileDBAdaptor.QueryParams.SAMPLES.key(), createResult.first().getUid()), QueryOptions.empty()); dbAdaptorFactory.getCatalogSampleDBAdaptor().delete(createResult.first().getUid()); }
@Test public void incrementCurrentRelease() throws CatalogDBException { long projectId = catalogProjectDBAdaptor.getId(user3.getId(), user3.getProjects().get(0).getId()); QueryResult<Project> projectQueryResult = catalogProjectDBAdaptor.get(projectId, new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.CURRENT_RELEASE.key())); assertEquals(1, projectQueryResult.first().getCurrentRelease()); assertEquals(2, catalogProjectDBAdaptor.incrementCurrentRelease(projectId).first().intValue()); assertEquals(3, catalogProjectDBAdaptor.incrementCurrentRelease(projectId).first().intValue()); }
@Test @Ignore // TODO: This should be tested in the sample manager, not here !!! public void deleteSampleFail3Test() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); Sample hg0097 = new Sample("HG0097", "1000g", new Individual(), "A description", 1); QueryResult<Sample> createResult = dbAdaptorFactory.getCatalogSampleDBAdaptor().insert(studyId, hg0097, null); dbAdaptorFactory.getCatalogCohortDBAdaptor().insert(studyId, new Cohort("Cohort", Study.Type.COLLECTION, "", "", Collections.singletonList(createResult.first()), 1, null), null); thrown.expect(CatalogDBException.class); dbAdaptorFactory.getCatalogSampleDBAdaptor().delete(createResult.first().getUid()); }
@Test public void deleteJobTest() throws CatalogException { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); Job job = catalogJobDBAdaptor.insert(new Job("name", user3.getId(), "", "", "", new File().setUid(4), Collections.emptyList(), 1), studyId, null).first(); long jobId = job.getUid(); assertEquals(Job.JobStatus.PREPARED, job.getStatus().getName()); catalogJobDBAdaptor.delete(jobId); thrown.expect(CatalogDBException.class); thrown.expectMessage("not exist"); catalogJobDBAdaptor.get(jobId, QueryOptions.empty()); }