diff --git a/src/test/java/com/redhat/lightblue/hook/audit/AbstractHookTest.java b/src/test/java/com/redhat/lightblue/hook/audit/AbstractHookTest.java index 1320e69..e19a78e 100644 --- a/src/test/java/com/redhat/lightblue/hook/audit/AbstractHookTest.java +++ b/src/test/java/com/redhat/lightblue/hook/audit/AbstractHookTest.java @@ -8,21 +8,20 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.redhat.lightblue.config.DataSourcesConfiguration; -import com.redhat.lightblue.config.LightblueFactory; import com.redhat.lightblue.metadata.EntityMetadata; import com.redhat.lightblue.metadata.mongo.MongoDataStoreParser; import com.redhat.lightblue.metadata.parser.Extensions; import com.redhat.lightblue.metadata.parser.JSONMetadataParser; import com.redhat.lightblue.metadata.types.DefaultTypes; import com.redhat.lightblue.mongo.config.MongoConfiguration; +import com.redhat.lightblue.mongo.test.EmbeddedMongo; import com.redhat.lightblue.util.JsonUtils; import com.redhat.lightblue.util.test.FileUtil; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; -import java.io.IOException; -import java.net.URISyntaxException; +import org.junit.After; /** * Abstract hook test assuming use of mongo backend and metadata for test as @@ -30,8 +29,9 @@ * * @author nmalik */ -public abstract class AbstractHookTest extends AbstractMongoTest { +public abstract class AbstractHookTest { + protected static EmbeddedMongo mongo = EmbeddedMongo.getInstance(); protected static final String DATASTORE_BACKEND = "mongo"; // reuse the json node factory, no need to create new ones each test @@ -40,12 +40,13 @@ public abstract class AbstractHookTest extends AbstractMongoTest { protected static AuditHookConfigurationParser hookParser; protected static JSONMetadataParser parser; + + @BeforeClass public static void beforeClass() throws Exception { AbstractMongoTest.setupClass(); DataSourcesConfiguration dsc = new DataSourcesConfiguration(); dsc.add(DATASTORE_BACKEND, new MongoConfiguration()); - LightblueFactory mgr = new LightblueFactory(dsc); } @BeforeClass @@ -61,7 +62,6 @@ public static void setupClass() throws Exception { @Before public void setup() { - super.setup(); // create metadata try { for (String resource : getMetadataResources()) { @@ -75,6 +75,11 @@ public void setup() { } } + @After + public void teardown() throws Exception { + mongo.reset(); + } + @AfterClass public static void teardownClass() throws Exception { parser = null; diff --git a/src/test/java/com/redhat/lightblue/hook/audit/AuditHookTest.java b/src/test/java/com/redhat/lightblue/hook/audit/AuditHookTest.java index e5f12b2..dbb87f7 100644 --- a/src/test/java/com/redhat/lightblue/hook/audit/AuditHookTest.java +++ b/src/test/java/com/redhat/lightblue/hook/audit/AuditHookTest.java @@ -84,7 +84,7 @@ public void getName() throws Exception { @Test public void updateWithId() throws Exception { // verify up front there is nothing in audit collection - DBCollection auditColl = db.createCollection("audit", null); + DBCollection auditColl = mongo.getDB().createCollection("audit", null); Assert.assertEquals(0, auditColl.find().count()); // parse audit and foo metadata diff --git a/src/test/java/com/redhat/lightblue/hook/audit/CountryAuditHookTest.java b/src/test/java/com/redhat/lightblue/hook/audit/CountryAuditHookTest.java index 70dd9ee..cf6bc56 100644 --- a/src/test/java/com/redhat/lightblue/hook/audit/CountryAuditHookTest.java +++ b/src/test/java/com/redhat/lightblue/hook/audit/CountryAuditHookTest.java @@ -169,7 +169,7 @@ public void missingAllIdentifyingFields() throws Exception { @Test public void noMissingIdentifyingFields() throws Exception { // verify up front there is nothing in audit collection - DBCollection auditColl = db.createCollection("audit", null); + DBCollection auditColl = mongo.getDB().createCollection("audit", null); Assert.assertEquals(0, auditColl.find().count()); String jsonSchemaString = FileUtil.readFile(COUNTRY_METADATA_FILENAME); @@ -210,7 +210,7 @@ public void noMissingIdentifyingFields() throws Exception { @Test public void differentPreAndPost() throws Exception { // verify up front there is nothing in audit collection - DBCollection auditColl = db.createCollection("audit", null); + DBCollection auditColl = mongo.getDB().createCollection("audit", null); Assert.assertEquals(0, auditColl.find().count()); String jsonSchemaString = FileUtil.readFile(COUNTRY_METADATA_FILENAME); @@ -259,7 +259,7 @@ public void differentPreAndPost() throws Exception { @Test public void nothingToAudit() throws Exception { // verify up front there is nothing in audit collection - DBCollection auditColl = db.createCollection("audit", null); + DBCollection auditColl = mongo.getDB().createCollection("audit", null); Assert.assertEquals(0, auditColl.find().count()); String jsonSchemaString = FileUtil.readFile(COUNTRY_METADATA_FILENAME);