Skip to content

Commit

Permalink
Merge pull request #19 from jewzaam/embedded-mongo
Browse files Browse the repository at this point in the history
Updated to use EmbeddedMongo from lightblue-mongo
  • Loading branch information
luan-cestari committed Jan 19, 2015
2 parents bef1a3d + 02fbee6 commit 320d996
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@
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
* resource(s) on classpath.
*
* @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
Expand All @@ -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
Expand All @@ -61,7 +62,6 @@ public static void setupClass() throws Exception {

@Before
public void setup() {
super.setup();
// create metadata
try {
for (String resource : getMetadataResources()) {
Expand All @@ -75,6 +75,11 @@ public void setup() {
}
}

@After
public void teardown() throws Exception {
mongo.reset();
}

@AfterClass
public static void teardownClass() throws Exception {
parser = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 320d996

Please sign in to comment.