diff --git a/ocd/arangoDB/config.properties b/ocd/arangoDB/config.properties index 8db05318..f7ecc4ae 100644 --- a/ocd/arangoDB/config.properties +++ b/ocd/arangoDB/config.properties @@ -1,6 +1,6 @@ -#Wed Sep 14 15:39:01 CEST 2022 PORT=8529 PASSWORD=password -DATABASENAME=ocd_db +DATABASENAME=ocdDB +TESTDATABASENAME=testDB HOST=127.0.0.1 USER=root diff --git a/ocd/arangoDB/config_test.properties b/ocd/arangoDB/config_test.properties deleted file mode 100644 index ee6bd20b..00000000 --- a/ocd/arangoDB/config_test.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Mon Sep 12 16:36:05 CEST 2022 -PORT=8529 -PASSWORD=password -DATABASENAME=test_db -HOST=127.0.0.1 -USER=root diff --git a/ocd/arangoDB/standard_config.properties b/ocd/arangoDB/standard_config.properties deleted file mode 100644 index b9112eef..00000000 --- a/ocd/arangoDB/standard_config.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Mon Sep 12 16:36:05 CEST 2022 -PORT=8529 -PASSWORD=password -DATABASENAME=ocd_db -HOST=127.0.0.1 -USER=root diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/ServiceClass.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/ServiceClass.java index 5d6c9500..eb78ee77 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/ServiceClass.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/ServiceClass.java @@ -154,8 +154,8 @@ protected void initResources() { } public ServiceClass() { - DatabaseConfig.setConfigFile(false); //TODO angeben ob test datenbank oder hauptdatenbank gewaehlt wird - database = new Database(); + + database = new Database(false); setFieldValues(); // instantiate inactivityHandler to regularly remove content of inactive users. inactivityHandler = new InactivityHandler(database, threadHandler, this); //TODO inactivity handler muss sich auf db beziehens @@ -164,6 +164,7 @@ public ServiceClass() { } + /////////////////////////////////////////////////////////// ///// ATTRIBUTES /////////////////////////////////////////////////////////// diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/AlgorithmRunnable.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/AlgorithmRunnable.java index 0d593810..209992e2 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/AlgorithmRunnable.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/AlgorithmRunnable.java @@ -62,9 +62,8 @@ public void run() { CoverId coverId = new CoverId(cKey, graphId); RequestHandler requestHandler = new RequestHandler(); - - DatabaseConfig.setConfigFile(false); - Database database = new Database(); + + Database database = new Database(false); try { Cover c = database.getCover(user, gKey, cKey); if(c == null) { diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/CentralityAlgorithmRunnable.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/CentralityAlgorithmRunnable.java index dfbd8efe..66a7bc07 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/CentralityAlgorithmRunnable.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/CentralityAlgorithmRunnable.java @@ -57,9 +57,8 @@ public void run() { CentralityMapId id = new CentralityMapId(mKey, graphId); RequestHandler requestHandler = new RequestHandler(); - - DatabaseConfig.setConfigFile(false); - Database database = new Database(); + + Database database = new Database(false); try { CentralityMap m = database.getCentralityMap(user, gKey, mKey); if(m == null) { diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/CentralitySimulationRunnable.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/CentralitySimulationRunnable.java index 9b17728b..830e5d90 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/CentralitySimulationRunnable.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/CentralitySimulationRunnable.java @@ -55,9 +55,8 @@ public void run() { CentralityMapId id = new CentralityMapId(mKey, graphId); RequestHandler requestHandler = new RequestHandler(); - - DatabaseConfig.setConfigFile(false); - Database database = new Database(); + + Database database = new Database(false); try { CentralityMap m = database.getCentralityMap(user, gKey, mKey); if(m == null) { diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/Database.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/Database.java index 321fa7d0..40d7dce5 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/Database.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/Database.java @@ -74,16 +74,23 @@ public class Database { private List collectionNames =new ArrayList(13); - public Database() { + public Database(boolean testDB) { Properties props = DBC.getConfigProperties(); HOST = props.getProperty("HOST"); String port = props.getProperty("PORT"); PORT = Integer.parseInt(props.getProperty("PORT")); USER = props.getProperty("USER"); PASSWORD = props.getProperty("PASSWORD"); - DBNAME_STRING = props.getProperty("DATABASENAME"); + if(!testDB) { + DBNAME_STRING = props.getProperty("DATABASENAME"); + }else{ + DBNAME_STRING = props.getProperty("TESTDATABASENAME"); + } DBNAME = DbName.of(DBNAME_STRING); - arangoDB = new ArangoDB.Builder().host(HOST, PORT).password(PASSWORD).serializer(new ArangoJack()).build(); + arangoDB = new ArangoDB.Builder() + .host(HOST, PORT) + .user(USER) + .password(PASSWORD).serializer(new ArangoJack()).build(); db = arangoDB.db(DBNAME); init(); } diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/DatabaseConfig.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/DatabaseConfig.java index 8f4ed52c..306725be 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/DatabaseConfig.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/DatabaseConfig.java @@ -11,39 +11,12 @@ import java.io.FileInputStream; public class DatabaseConfig { - private static final String PATH = "./ocd/arangoDB/"; + + private static final String PATH = "ocd/arangoDB/"; private static final String FILENAME = "config.properties"; - private static final String TESTFILENAME = "config_test.properties"; - private static final String STANDARD_CONFIG_FILENAME = "standard_config.properties"; private static final File CONFIG_FILE = new File(PATH+FILENAME); - private static final File TESTFILE = new File(PATH + TESTFILENAME); - private static final File STANDARD_CONFIG_FILE = new File(PATH + STANDARD_CONFIG_FILENAME); private static Properties props = new Properties(); - - public static void setConfigFile(boolean testFile) { - FileInputStream inputStream; - props.clear(); - try { - if(testFile) { - inputStream = new FileInputStream(TESTFILE); - } - else { - inputStream = new FileInputStream(STANDARD_CONFIG_FILE); - } - props.load(inputStream); - }catch(IOException e) { - e.printStackTrace(); - } - try { - FileOutputStream outputStream = new FileOutputStream(CONFIG_FILE); - props.store(outputStream, null); - outputStream.close(); - }catch(IOException e) { - e.printStackTrace(); - } - } - public Properties getConfigProperties() { try { FileInputStream inputStream = new FileInputStream(CONFIG_FILE); diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/GroundTruthBenchmarkRunnable.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/GroundTruthBenchmarkRunnable.java index 5de94352..93412115 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/GroundTruthBenchmarkRunnable.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/GroundTruthBenchmarkRunnable.java @@ -51,9 +51,8 @@ public void run() { * Set algorithm and benchmark status to running. */ RequestHandler requestHandler = new RequestHandler(); - - DatabaseConfig.setConfigFile(false); - Database database = new Database(); + + Database database = new Database(false); String cKey = coverId.getKey(); CustomGraphId gId = coverId.getGraphId(); diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/KnowledgeDrivenMeasureRunnable.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/KnowledgeDrivenMeasureRunnable.java index 6e4a9c60..3685b3b9 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/KnowledgeDrivenMeasureRunnable.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/KnowledgeDrivenMeasureRunnable.java @@ -66,8 +66,7 @@ public void run() { * Set metric state to running. */ RequestHandler requestHandler = new RequestHandler(); - DatabaseConfig.setConfigFile(false); - Database database = new Database(); + Database database = new Database(false); try { OcdMetricLog persistedLog = database.getOcdMetricLog(logId); diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/StatisticalMeasureRunnable.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/StatisticalMeasureRunnable.java index 4d96e12c..8d35ad04 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/StatisticalMeasureRunnable.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/StatisticalMeasureRunnable.java @@ -56,8 +56,7 @@ public void run() { * Set metric state to running. */ RequestHandler requestHandler = new RequestHandler(); - DatabaseConfig.setConfigFile(false); - Database database = new Database(); + Database database = new Database(false); try { OcdMetricLog persistedLog = database.getOcdMetricLog(logId); if(persistedLog == null) { diff --git a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/ThreadHandler.java b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/ThreadHandler.java index 45a3fea4..18e15e47 100644 --- a/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/ThreadHandler.java +++ b/rest_ocd_services/src/main/java/i5/las2peer/services/ocd/utils/ThreadHandler.java @@ -77,8 +77,7 @@ public class ThreadHandler { private static Database database; public ThreadHandler() { - DatabaseConfig.setConfigFile(false); - database = new Database(); + database = new Database(false); } /** * Runs an algorithm. diff --git a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/ServiceDatabaseTest.java b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/ServiceDatabaseTest.java index 066bfc8f..2b2ee549 100644 --- a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/ServiceDatabaseTest.java +++ b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/ServiceDatabaseTest.java @@ -22,8 +22,7 @@ public class ServiceDatabaseTest { @BeforeClass public static void clearDatabase() { - DatabaseConfig.setConfigFile(true); - database = new Database(); + database = new Database(true); } diff --git a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/ServiceTest.java b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/ServiceTest.java index cae9ef06..e0f26be1 100644 --- a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/ServiceTest.java +++ b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/ServiceTest.java @@ -56,11 +56,8 @@ public class ServiceTest { private static final String testServiceClass = "i5.las2peer.services.ocd.ServiceClass"; private static final String mainPath = "ocd/"; - private static long SawmillGraphId; private static String SawmillGraphKey; - private static long DolphinsGraphId; private static String DolphinsGraphKey; - private static long AperiodicTwoCommunitiesGraphId; private static String AperiodicTwoCommunitiesGraphKey; private static Database database; @@ -127,8 +124,7 @@ private static void setupDatabase() throws AdapterException, FileNotFoundExcepti /* * Set db content */ - DatabaseConfig.setConfigFile(false); - database = new Database(); + database = new Database(false); CustomGraph graph = OcdTestGraphFactory.getAperiodicTwoCommunitiesGraph(); createGraph(graph); AperiodicTwoCommunitiesGraphKey = graph.getKey(); @@ -319,7 +315,7 @@ public void getSimulation() throws AdapterException, FileNotFoundException { s1.setName("name"); String id1 = "0"; SimulationSeries s2 = new SimulationSeries(); - s1.setName("name2"); + s2.setName("name2"); String id2 = "0"; try { @@ -332,8 +328,9 @@ public void getSimulation() throws AdapterException, FileNotFoundException { try { c.setLogin(testAgent.getIdentifier(), testPass); + ClientResponse result; - ClientResponse result = c.sendRequest("GET", + result = c.sendRequest("GET", mainPath + "simulation/" + 124, ""); System.out.println("Result of 'getSimulation' " + result.getResponse().trim()); String resultString = result.getResponse().trim(); // trimmed response string diff --git a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/cooperation/data/SimulationPersistenceTest.java b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/cooperation/data/SimulationPersistenceTest.java index 46d7811c..2980f15f 100644 --- a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/cooperation/data/SimulationPersistenceTest.java +++ b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/cooperation/data/SimulationPersistenceTest.java @@ -25,8 +25,7 @@ public class SimulationPersistenceTest { @BeforeClass public static void clearDatabase() { - DatabaseConfig.setConfigFile(true); - database = new Database(); + database = new Database(true); } @AfterClass diff --git a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/graphs/CoverDatabaseTest.java b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/graphs/CoverDatabaseTest.java index fa576f90..bee31588 100644 --- a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/graphs/CoverDatabaseTest.java +++ b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/graphs/CoverDatabaseTest.java @@ -36,8 +36,7 @@ public class CoverDatabaseTest { @BeforeClass public static void clearDatabase() { - DatabaseConfig.setConfigFile(true); - database = new Database(); + database = new Database(true); } @AfterClass diff --git a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/graphs/CustomGraphDatabaseTest.java b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/graphs/CustomGraphDatabaseTest.java index 1eae20bd..29d52548 100644 --- a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/graphs/CustomGraphDatabaseTest.java +++ b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/graphs/CustomGraphDatabaseTest.java @@ -36,8 +36,7 @@ public class CustomGraphDatabaseTest { @BeforeClass public static void clearDatabase() { - DatabaseConfig.setConfigFile(true); - database = new Database(); + database = new Database(true); } @AfterClass diff --git a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseConfigTest.java b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseConfigTest.java index 834b93a3..c7ee0573 100644 --- a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseConfigTest.java +++ b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseConfigTest.java @@ -6,16 +6,9 @@ import org.junit.Ignore; import org.junit.Test; -@Ignore public class DatabaseConfigTest { private static DatabaseConfig dc = new DatabaseConfig(); - - @Test - public void test() { - System.out.println("config before dbconfigtest : " + dc.getConfigProperties().toString()); - DatabaseConfig.setConfigFile(false); - System.out.println("config after the main (non-test) database was set : " + dc.getConfigProperties().toString()); - } + @Test @@ -27,14 +20,18 @@ public void getPropertiesTest() { System.out.println("PORT:"+props.getProperty("PORT")); assertEquals("8529", props.getProperty("PORT")); - System.out.println("USER:"+props.getProperty("USER")); - assertEquals("root", props.getProperty("USER")); +// System.out.println("USER:"+props.getProperty("USER")); +// assertEquals("root", props.getProperty("USER")); - System.out.println("PASSWORD:"+props.getProperty("PASSWORD")); - assertEquals("password", props.getProperty("PASSWORD")); +// System.out.println("PASSWORD:"+props.getProperty("PASSWORD")); +// assertEquals("password", props.getProperty("PASSWORD")); System.out.println("DATABASENAME:"+props.getProperty("DATABASENAME")); - assertEquals("ocd_db", props.getProperty("DATABASENAME")); + String dbName = props.getProperty("DATABASENAME"); + assertEquals("ocdDB",dbName ); + + System.out.println("TESTDATABASENAME:"+props.getProperty("TESTDATABASENAME")); + assertEquals("testDB", props.getProperty("TESTDATABASENAME")); } diff --git a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseMethodTest.java b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseMethodTest.java index d3d05ba7..356f99a2 100644 --- a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseMethodTest.java +++ b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseMethodTest.java @@ -32,8 +32,7 @@ public class DatabaseMethodTest { @BeforeClass public static void setupTestDatabase() { - DatabaseConfig.setConfigFile(true); - database = new Database(); + database = new Database(true); } @Before diff --git a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseTest.java b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseTest.java index 1cf9a6d0..00024aa8 100644 --- a/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseTest.java +++ b/rest_ocd_services/src/test/java/i5/las2peer/services/ocd/utils/DatabaseTest.java @@ -45,8 +45,7 @@ public class DatabaseTest { @BeforeClass public static void clearDatabase() { - DatabaseConfig.setConfigFile(true); - database = new Database(); + database = new Database(true); } @AfterClass @@ -56,8 +55,7 @@ public static void deleteDatabase() { @Test public void test() { - DatabaseConfig.setConfigFile(false); - Database db = new Database(); + Database db = new Database(true); db.init(); List i = new ArrayList(); i.add(1);i.add(2); @@ -75,7 +73,7 @@ public void test() { //TODO: is this test needed? @Test public void persistFactoryGraph() { - Database db = new Database(); + Database db = new Database(true); db.init(); try { @@ -85,8 +83,7 @@ public void persistFactoryGraph() { @Test public void persistGraphs() { - DatabaseConfig.setConfigFile(true); - Database db = new Database(); + Database db = new Database(true); db.deleteDatabase(); db.init(); CustomGraph g1 = getGraph1(); @@ -96,12 +93,11 @@ public void persistGraphs() { System.out.println("start"); this.persistExampleGraphCoverCMap(g1); this.persistExampleGraphCoverCMap(g2); - this.persistExampleGraphCoverCMap(g3); this.persistExampleGraphCoverCMap(g4); } public void persistExampleGraphCoverCMap(CustomGraph g) { - Database db = new Database(); + Database db = new Database(true); db.init(); Cover c1 = getLOCCover(g);