Skip to content

Commit

Permalink
Merge pull request #22 from luan-cestari/Fix_builds_21
Browse files Browse the repository at this point in the history
Fix builds 21
  • Loading branch information
jewzaam committed Jan 9, 2015
2 parents 1d793e4 + 7d7639c commit 1f4a3b8
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 25 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<groupId>com.redhat.lightblue.hook</groupId>
<artifactId>audit</artifactId>
<packaging>jar</packaging>
<version>1.2.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<name>lightblue audit hook: ${project.groupId}|${project.artifactId}</name>
<description>Lightblue Audit Hook components</description>
<licenses>
Expand All @@ -37,22 +37,22 @@
<dependency>
<groupId>com.redhat.lightblue</groupId>
<artifactId>metadata</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.redhat.lightblue</groupId>
<artifactId>crud</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.redhat.lightblue.config</groupId>
<artifactId>core-config</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.redhat.lightblue.mongo</groupId>
<artifactId>mongo-config</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.redhat.lightblue.mongo</groupId>
Expand All @@ -62,7 +62,7 @@
<dependency>
<groupId>com.redhat.lightblue.mongo</groupId>
<artifactId>mongo-test</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
31 changes: 16 additions & 15 deletions src/test/java/com/redhat/lightblue/hook/audit/AbstractHookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
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.AbstractMongoTest;
import com.redhat.lightblue.util.JsonUtils;
import com.redhat.lightblue.util.test.FileUtil;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;

import java.io.IOException;
import java.net.URISyntaxException;

/**
* Abstract hook test assuming use of mongo backend and metadata for test as
* resource(s) on classpath.
Expand All @@ -40,7 +41,8 @@ public abstract class AbstractHookTest extends AbstractMongoTest {
protected static JSONMetadataParser parser;

@BeforeClass
public static void beforeClass() {
public static void beforeClass() throws Exception {
AbstractMongoTest.setupClass();
DataSourcesConfiguration dsc = new DataSourcesConfiguration();
dsc.add(DATASTORE_BACKEND, new MongoConfiguration());
LightblueFactory mgr = new LightblueFactory(dsc);
Expand All @@ -58,22 +60,21 @@ public static void setupClass() throws Exception {
}

@Before
public void setup() throws Exception {
public void setup() {
super.setup();
// create metadata
for (String resource : getMetadataResources()) {
String jsonString = FileUtil.readFile(resource);
EntityMetadata em = parser.parseEntityMetadata(JsonUtils.json(jsonString));
AuditHook.getFactory().getMetadata().createNewMetadata(em);
try {
for (String resource : getMetadataResources()) {
String jsonString = null;
jsonString = FileUtil.readFile(resource);
EntityMetadata em = parser.parseEntityMetadata(JsonUtils.json(jsonString));
AuditHook.getFactory().getMetadata().createNewMetadata(em);
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
}

@After
@Override
public void teardown() throws Exception {
super.teardown();
dropDatabase("mongo");
}

@AfterClass
public static void teardownClass() throws Exception {
parser = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.redhat.lightblue.hook.audit;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.redhat.lightblue.mongo.test.EmbeddedMongo;
import com.redhat.lightblue.util.test.AbstractJsonSchemaTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;


/**
* Created by lcestari on 1/9/15.
*/
public abstract class AbstractMongoTest extends AbstractJsonSchemaTest {
private static EmbeddedMongo mongo = EmbeddedMongo.getInstance();
protected static final String COLL_NAME = "data";
protected static DB db;
protected DBCollection coll;

protected final String key1 = "name";
protected final String key2 = "foo";

@BeforeClass
public static void setupClass() throws Exception {
db = mongo.getDB();
}

@Before
public void setup() {
coll = db.getCollection(COLL_NAME);

// setup data
int count = 0;
for (int i = 1; i < 5; i++) {
for (int x = 1; x < i + 1; x++) {
DBObject obj = new BasicDBObject(key1, "obj" + i);
obj.put(key2, "bar" + x);
coll.insert(obj);
count++;
}
}

Assert.assertEquals(count, coll.find().count());
}

@After
public void teardown() {
mongo.reset();
coll = null;
}
}
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 = mongo.getDB("mongo").createCollection("audit", null);
DBCollection auditColl = db.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 = mongo.getDB("mongo").createCollection("audit", null);
DBCollection auditColl = db.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 = mongo.getDB("mongo").createCollection("audit", null);
DBCollection auditColl = db.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 = mongo.getDB("mongo").createCollection("audit", null);
DBCollection auditColl = db.createCollection("audit", null);
Assert.assertEquals(0, auditColl.find().count());

String jsonSchemaString = FileUtil.readFile(COUNTRY_METADATA_FILENAME);
Expand Down

0 comments on commit 1f4a3b8

Please sign in to comment.