@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"); }
/** * Populates the database with dummy data. * * @param configuration Catalog configuration file. * @param force Used in the case where a database already exists with the same name. When force = true, it will override it. * @throws CatalogException when there is already a database with the same name and force is false. * @throws URISyntaxException when there is a problem parsing the URI read from the configuration file. */ public static void createDemoDatabase(Configuration configuration, boolean force) throws CatalogException, URISyntaxException { CatalogManager catalogManager = new CatalogManager(configuration); if (catalogManager.existsCatalogDB()) { if (force) { catalogManager.deleteCatalogDB(force); } else { // throw new CatalogException("A database called " + catalogConfiguration.getDatabase().getDatabase() + " already exists"); throw new CatalogException("A database called " + catalogManager.getCatalogDatabase() + " already exists"); } } catalogManager.installCatalogDB(configuration.getAdmin().getSecretKey(), configuration.getAdmin().getPassword()); try { populateDatabase(catalogManager); } catch (IOException e) { throw new CatalogException(e.getMessage()); } }
@BeforeClass public static void beforeClass() throws IOException, CatalogException, URISyntaxException { Configuration configuration = Configuration.load(CatalogSampleAnnotationsLoaderTest.class.getClassLoader() .getClass().getResource("/configuration-test.yml").openStream()); configuration.getAdmin().setAlgorithm("HS256"); catalogManager = new CatalogManager(configuration); catalogManager.deleteCatalogDB(true); catalogManager.installCatalogDB("dummy", "admin"); loader = new CatalogSampleAnnotationsLoader(catalogManager); String pedFileName = "20130606_g1k.ped"; URL pedFileURL = CatalogSampleAnnotationsLoader.class.getClassLoader().getResource(pedFileName); pedigree = loader.readPedigree(pedFileURL.getPath()); userId = "user1"; catalogManager.getUserManager().create(userId, userId, "asdasd@asd.asd", userId, "", -1L, Account.FULL, QueryOptions.empty(), null); sessionId = catalogManager.getUserManager().login(userId, userId); Project project = catalogManager.getProjectManager().create("def", "default", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionId).getResult().get(0); Study study = catalogManager.getStudyManager().create(project.getFqn(), "def", null, "default", Study.Type.FAMILY, null, "", null, null, null, null, null, null, null, null, sessionId).getResult().get(0); studyId = study.getFqn(); pedFile = catalogManager.getFileManager().create(studyId, File.Type.FILE, File.Format.PED, File.Bioformat .OTHER_PED, "data/" + pedFileName, null, "", null, 0, -1, null, (long) -1, null, null, true, null, null, sessionId) .getResult().get(0); new FileUtils(catalogManager).upload(pedFileURL.toURI(), pedFile, null, sessionId, false, false, false, true, 10000000); pedFile = catalogManager.getFileManager().get(studyId, pedFile.getPath(), null, sessionId).getResult().get(0); }