@Override public void after() { super.after(); close(solrClient); }
@Override protected void before() throws Throwable { super.before(); catalogManagerExternalResource.before(); // if (storageHadoop) { // try { // String name = HadoopVariantStorageTest.class.getName(); // Class.forName(name); // } catch (ClassNotFoundException e) { // logger.error("Missing dependency opencga-storage-hadoop!"); // throw e; // } // } // if (storageHadoop) { // hadoopExternalResource = new HadoopVariantStorageTest.HadoopExternalResource(); // hadoopExternalResource.before(); // } opencgaHome = isolateOpenCGA(); Files.createDirectory(opencgaHome.resolve("storage")); VariantStorageBaseTest.setRootDir(opencgaHome.resolve("storage")); // ExecutorManager.LOCAL_EXECUTOR_FACTORY.set((c, s) -> new StorageLocalExecutorManager(s)); }
public CatalogManager getCatalogManager() { return catalogManagerExternalResource.getCatalogManager(); }
@Override public void before() throws Exception { int c = 0; do { opencgaHome = Paths.get("target/test-data").resolve("junit_opencga_home_" + TimeUtils.getTimeMillis() + (c > 0 ? "_" + c : "")); c++; } while (opencgaHome.toFile().exists()); Files.createDirectories(opencgaHome); configuration = Configuration.load(getClass().getResource("/configuration-test.yml").openStream()); configuration.getAdmin().setAlgorithm("HS256"); configuration.setDataDir(opencgaHome.resolve("sessions").toUri().toString()); configuration.setTempJobsDir(opencgaHome.resolve("jobs").toUri().toString()); catalogManager = new CatalogManager(configuration); try { catalogManager.deleteCatalogDB(false); } catch (Exception ignore) {} clearCatalog(configuration); if (!opencgaHome.toFile().exists()) { deleteFolderTree(opencgaHome.toFile()); Files.createDirectory(opencgaHome); } catalogManager.installCatalogDB("dummy", "admin"); }
public Path isolateOpenCGA() throws IOException { Path opencgaHome = catalogManagerExternalResource.getOpencgaHome(); Path userHome = opencgaHome.resolve("user_home"); Path conf = opencgaHome.resolve("conf"); Files.createDirectories(userHome); catalogManagerExternalResource.getConfiguration().serialize( new FileOutputStream(conf.resolve("configuration.yml").toFile())); InputStream inputStream = StorageManager.class.getClassLoader().getResourceAsStream("storage-configuration.yml");
@Before public void setUp() throws IOException, CatalogException, URISyntaxException { catalogManager = catalogManagerExternalResource.getCatalogManager(); catalogManager.getUserManager().create("user", "User Name", "mail@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); sessionIdUser = catalogManager.getUserManager().login("user", PASSWORD); project = catalogManager.getProjectManager().create("1000G", "Project about some genomes", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser).first(); study = catalogManager.getStudyManager().create(project.getId(), "phase1", null, "Phase 1", Study.Type.TRIO, null, "Done", null, null, null, null, null, null, null, null, sessionIdUser).first(); folder = catalogManager.getFileManager().createFolder(study.getId(), Paths.get("data/vcf/").toString(), null, true, null, QueryOptions.empty(), sessionIdUser).first(); Path vcfPath = catalogManagerExternalResource.getOpencgaHome().resolve(VCF_FILE_NAME); Files.copy(this.getClass().getClassLoader().getResourceAsStream("biofiles/" + VCF_FILE_NAME), vcfPath, StandardCopyOption.REPLACE_EXISTING); vcfFileUri = vcfPath.toUri(); Path bamPath = catalogManagerExternalResource.getOpencgaHome().resolve(BAM_FILE_NAME); Files.copy(this.getClass().getClassLoader().getResourceAsStream("biofiles/" + BAM_FILE_NAME), bamPath, StandardCopyOption.REPLACE_EXISTING); bamFileUri = bamPath.toUri(); }
@After public void tearDown() throws Exception { DummyProjectMetadataAdaptor.writeAndClear(catalogManagerExternalResource.getOpencgaHome()); DummyStudyConfigurationAdaptor.writeAndClear(catalogManagerExternalResource.getOpencgaHome()); }
@Test public void updateFamilyMissingPhenotype() throws JsonProcessingException, CatalogException { QueryResult<Family> originalFamily = createDummyFamily("Martinez-Martinez"); Phenotype phenotype1 = new Phenotype("dis1", "New name", "New source"); Family family = new Family(); family.setPhenotypes(Arrays.asList(phenotype1)); ObjectMapper jsonObjectMapper = catalogManagerResource.generateNewObjectMapper(); ObjectMap params = new ObjectMap(jsonObjectMapper.writeValueAsString(family)); params = new ObjectMap(FamilyDBAdaptor.QueryParams.PHENOTYPES.key(), params.get(FamilyDBAdaptor.QueryParams.PHENOTYPES.key())); thrown.expect(CatalogException.class); thrown.expectMessage("not present in any member of the family"); familyManager.update(STUDY, originalFamily.first().getName(), params, QueryOptions.empty(), sessionIdUser); }
public static void deleteFolderTree(java.io.File folder) { java.io.File[] files = folder.listFiles(); if (files != null) { for (java.io.File f : files) { if (f.isDirectory()) { deleteFolderTree(f); } else { f.delete(); } } } folder.delete(); } }
DataStoreServerAddress dataStoreServerAddress = new DataStoreServerAddress(split[0], Integer.parseInt(split[1])); CatalogManagerExternalResource.clearCatalog(configuration); catalogManager = new CatalogManager(configuration); catalogManager.installCatalogDB("dummy", "admin");
@Before public void setUp() throws IOException, CatalogException { catalogManager = catalogManagerExternalResource.getCatalogManager(); catalogManager.getUserManager().create("user", "User Name", "mail@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); sessionIdUser = catalogManager.getUserManager().login("user", PASSWORD); project = catalogManager.getProjectManager().create("1000G", "Project about some genomes", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser).first(); study = catalogManager.getStudyManager().create(project.getId(), "phase1", null, "Phase 1", Study.Type.TRIO, null, "Done", null, null, null, null, null, null, null, null, sessionIdUser).first(); folder = catalogManager.getFileManager().createFolder(study.getId(), Paths.get("data/test/folder/").toString(), null, true, null, QueryOptions.empty(), sessionIdUser).first(); directory = catalogManagerExternalResource.getOpencgaHome().resolve("catalog_scan_test_folder").toAbsolutePath(); if (directory.toFile().exists()) { IOUtils.deleteDirectory(directory); } Files.createDirectory(directory); }
@Test public void testCreateFileInLinkedFolder() throws Exception { // Create an empty folder Path dir = catalogManagerResource.getOpencgaHome().resolve("folder_to_link"); Files.createDirectory(dir); URI uri = dir.toUri(); // Link the folder in the root link(uri, "", studyFqn, new ObjectMap(), sessionIdUser); File file = catalogManager.getFileManager().create(studyFqn, File.Type.FILE, File.Format.PLAIN, File.Bioformat .NONE, "folder_to_link/file.txt", null, "", null, 0, -1, null, (long) -1, null, null, false, null, null, sessionIdUser).first(); assertEquals(uri.resolve("file.txt"), file.getUri()); }
@Test public void updateFamilyPhenotype() throws JsonProcessingException, CatalogException { QueryResult<Family> originalFamily = createDummyFamily("Martinez-Martinez"); Phenotype phenotype1 = new Phenotype("dis1", "New name", "New source"); Phenotype phenotype2 = new Phenotype("dis2", "New name", "New source"); Phenotype phenotype3 = new Phenotype("dis3", "New name", "New source"); Family family = new Family(); family.setPhenotypes(Arrays.asList(phenotype1, phenotype2, phenotype3)); ObjectMapper jsonObjectMapper = catalogManagerResource.generateNewObjectMapper(); ObjectMap params = new ObjectMap(jsonObjectMapper.writeValueAsString(family)); params = new ObjectMap(FamilyDBAdaptor.QueryParams.PHENOTYPES.key(), params.get(FamilyDBAdaptor.QueryParams.PHENOTYPES.key())); QueryResult<Family> updatedFamily = familyManager.update(STUDY, originalFamily.first().getName(), params, QueryOptions.empty(), sessionIdUser); assertEquals(3, updatedFamily.first().getPhenotypes().size()); // Only one id should be the same as in originalFamilyIds (father id) for (Phenotype phenotype : updatedFamily.first().getPhenotypes()) { assertEquals("New name", phenotype.getName()); assertEquals("New source", phenotype.getSource()); } }
deleteFolderTree(rootdir.toFile()); if (!configuration.getTempJobsDir().isEmpty()) { Path jobsDir = Paths.get(UriUtils.createDirectoryUri(configuration.getTempJobsDir())); if (jobsDir.toFile().exists()) { deleteFolderTree(jobsDir.toFile());
.openStream()); configuration.getAdmin().setAlgorithm("HS256"); CatalogManagerExternalResource.clearCatalog(configuration);
@Before public void setUp() throws IOException, CatalogException { catalogManager = catalogManagerResource.getCatalogManager(); setUpCatalogManager(catalogManager); }
sessionIdUser2); Path myStudy = Files.createDirectory(catalogManagerResource.getOpencgaHome().resolve("myStudy")); String newStudy = catalogManager.getStudyManager().create(project2, "alias", null, "name", Study.Type.CASE_CONTROL, "", "", null, null, null, myStudy.toUri(), null, null, null, null, sessionIdUser2).first().getFqn();
@Override protected void after() { super.after(); catalogManagerExternalResource.after(); // if (storageHadoop) { // hadoopExternalResource.after(); // } }
@Override public void before() throws Exception { super.before(); Path rootDir = getOpencgaHome(); // Copy configuration copyConfiguration("cohort-managed-schema.xml", CatalogSolrManager.COHORT_CONF_SET); copyConfiguration("family-managed-schema.xml", CatalogSolrManager.FAMILY_CONF_SET); copyConfiguration("file-managed-schema.xml", CatalogSolrManager.FILE_CONF_SET); copyConfiguration("individual-managed-schema.xml", CatalogSolrManager.INDIVIDUAL_CONF_SET); copyConfiguration("sample-managed-schema.xml", CatalogSolrManager.SAMPLE_CONF_SET); String solrHome = rootDir.resolve("solr").toString(); solrClient = create(solrHome, rootDir.resolve("solr/configsets").toString()); CoreAdminRequest.Create request = new CoreAdminRequest.Create(); request.setCoreName(getConfiguration().getDatabasePrefix() + "_" + CatalogSolrManager.COHORT_SOLR_COLLECTION); request.setConfigSet(CatalogSolrManager.COHORT_CONF_SET); request.process(solrClient); request.setCoreName(getConfiguration().getDatabasePrefix() + "_" + CatalogSolrManager.SAMPLE_SOLR_COLLECTION); request.setConfigSet(CatalogSolrManager.SAMPLE_CONF_SET); request.process(solrClient); request.setCoreName(getConfiguration().getDatabasePrefix() + "_" + CatalogSolrManager.INDIVIDUAL_SOLR_COLLECTION); request.setConfigSet(CatalogSolrManager.INDIVIDUAL_CONF_SET); request.process(solrClient); request.setCoreName(getConfiguration().getDatabasePrefix() + "_" + CatalogSolrManager.FILE_SOLR_COLLECTION); request.setConfigSet(CatalogSolrManager.FILE_CONF_SET); request.process(solrClient); request.setCoreName(getConfiguration().getDatabasePrefix() + "_" + CatalogSolrManager.FAMILY_SOLR_COLLECTION); request.setConfigSet(CatalogSolrManager.FAMILY_CONF_SET); request.process(solrClient); }
@Test public void updateFamilyMissingMember() throws CatalogException, JsonProcessingException { QueryResult<Family> originalFamily = createDummyFamily("Martinez-Martinez"); Individual father = new Individual().setId("father"); Individual mother = new Individual().setId("mother2"); // We create a new father and mother with the same information to mimic the behaviour of the webservices. Otherwise, we would be // ingesting references to exactly the same object and this test would not work exactly the same way. Individual relFather = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual relChild1 = new Individual().setId("child3") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis2", "dis2", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Family family = new Family(); family.setMembers(Arrays.asList(relChild1, relFather)); ObjectMapper jsonObjectMapper = catalogManagerResource.generateNewObjectMapper(); ObjectMap params = new ObjectMap(jsonObjectMapper.writeValueAsString(family)); params = new ObjectMap(FamilyDBAdaptor.QueryParams.MEMBERS.key(), params.get(FamilyDBAdaptor.QueryParams.MEMBERS.key())); thrown.expect(CatalogException.class); thrown.expectMessage("not present in the members list"); familyManager.update(STUDY, originalFamily.first().getName(), params, QueryOptions.empty(), sessionIdUser); }