Commit b1dcd0a8 authored by Daniel Bluhm's avatar Daniel Bluhm
Browse files

Use TestConfig in Persistence Integration tests


Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent 89bffbcc
......@@ -55,5 +55,10 @@
<artifactId>mongo-java-driver</artifactId>
<version>3.12.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.ice</groupId>
<artifactId>org.eclipse.ice.tests.data</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -14,11 +14,13 @@ package org.eclipse.ice.tests.integration.dev.annotation;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Iterator;
import java.util.Map;
import org.bson.Document;
import org.eclipse.ice.tests.data.TestConfig;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
......@@ -29,12 +31,23 @@ import com.mongodb.client.MongoDatabase;
* @author Daniel Bluhm
*/
class TestElementPersistenceHandlerTest {
/**
* Logger.
*/
public final Logger logger = LoggerFactory.getLogger(
TestElementPersistenceHandlerTest.class
);
/**
* The name of the collection to use in testing.
*/
public static final String COLLECTION = "test";
/**
* Config file name.
*/
public static final String CONFIG = "mongo.properties";
/**
* Connection to MongoDB.
*/
......@@ -52,10 +65,10 @@ class TestElementPersistenceHandlerTest {
* defaults of "localhost", "27017", and "test" are used, respectively.
*/
public TestElementPersistenceHandlerTest() {
Map<String, String> env = System.getenv();
String host = env.getOrDefault("MONGO_HOST", "localhost");
String port = env.getOrDefault("MONGO_PORT", "27017");
String database = env.getOrDefault("MONGO_DB", "test");
TestConfig config = TestConfig.from(CONFIG);
String host = config.getProperty("host", "localhost");
String port = config.getProperty("port", "27017");
String database = config.getProperty("database", "test");
this.db = MongoClients.create(
String.format("mongodb://%s:%s", host, port)
).getDatabase(database);
......
......@@ -8,4 +8,16 @@
<modules>
<module>org.eclipse.ice.tests.integration.dev.annotation</module>
</modules>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -45,7 +45,11 @@ public class TestConfig extends Properties {
/**
* Retrieve a test configuration from the test data directory and load the
* properties contained therein.
* properties contained therein. If the file was not found, an empty
* TestConfig is returned. This is intended to enable usage of getProperty
* with a default value to statically provide defaults from code. If file
* non-existence is an error condition, verify the existence of the file
* with {@link TestDataPath#exists(String)}.
* @param propertyFilename name of the property file to load.
* @return loaded Properties, empty if any errors occur.
*/
......@@ -70,9 +74,11 @@ public class TestConfig extends Properties {
}
/**
* Load a test config from the test data directory
* @param propertyFilename
* @return
* Load a TestConfig from a property file in the default test data
* directory. See {@link TestConfig#load(String)}.
* @param propertyFilename filename of property file from which properties
* will be loaded.
* @return new TestConfig
*/
public static TestConfig from(String propertyFilename) {
TestConfig config = new TestConfig(new TestDataPath());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment