Skip to content

Commit

Permalink
Adds NeoHelpersTests
Browse files Browse the repository at this point in the history
  • Loading branch information
frecar committed May 22, 2015
1 parent 1f5f29d commit 4f7d4cb
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/obelix/ObelixCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void run() {
makeSureTheUserDoesNotExceedMaxRelationshipsLimit(
graphDb, getUserNode(graphDb, user), maxRelationships);
} catch (ObelixNodeNotFoundException e) {
e.printStackTrace();
LOGGER.error("make sure users does not exceed max limit rel", e);
}
tx.success();
}
Expand Down
81 changes: 81 additions & 0 deletions src/test/java/TestNeoHelpers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import events.NeoHelpers;
import junit.framework.TestCase;
import obelix.ObelixFeeder;
import org.json.JSONObject;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.test.TestGraphDatabaseFactory;
import queue.impl.InternalObelixQueue;
import queue.impl.ObelixQueueElement;
import queue.interfaces.ObelixQueue;

import java.util.List;

public class TestNeoHelpers extends TestCase {

GraphDatabaseService graphDb;
ObelixQueue obelixQueue;
ObelixQueue obelixCacheQueue;

public void tearDown() throws Exception {
graphDb.shutdown();
}

public void setUp() throws Exception {
super.setUp();
graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
obelixQueue = new InternalObelixQueue();
obelixCacheQueue = new InternalObelixQueue();
}

public void testGetAllNodesReturnsEmptyListWHenNothingIsInserted() {
List<String> allNodes = NeoHelpers.getAllNodes(graphDb, "User");
assertEquals(allNodes.size(), 0);
}

public void testGetAllNodesReturnsOneNodeIfOneInserted() {

JSONObject jsonObject = new JSONObject();
jsonObject.put("type", "events.pageviews");
jsonObject.put("user", "1");
jsonObject.put("item", "1");
jsonObject.put("timestamp", "1421027564617");
obelixQueue.push(new ObelixQueueElement(jsonObject));

ObelixFeeder obelixFeeder = new ObelixFeeder(graphDb, 10, obelixQueue, obelixCacheQueue, 1);
obelixFeeder.feed();

List<String> allUsers = NeoHelpers.getAllNodes(graphDb, "User");
assertEquals(allUsers.size(), 1);

List<String> allItems = NeoHelpers.getAllNodes(graphDb, "Item");
assertEquals(allItems.size(), 1);

}

public void testGetAllNodesReturnsTwoItemsAndOneUser() {

JSONObject jsonObject = new JSONObject();
jsonObject.put("type", "events.pageviews");
jsonObject.put("user", "1");
jsonObject.put("item", "1");
jsonObject.put("timestamp", "1421027564617");
obelixQueue.push(new ObelixQueueElement(jsonObject));

jsonObject = new JSONObject();
jsonObject.put("type", "events.pageviews");
jsonObject.put("user", "1");
jsonObject.put("item", "2");
jsonObject.put("timestamp", "1421027564617");
obelixQueue.push(new ObelixQueueElement(jsonObject));

ObelixFeeder obelixFeeder = new ObelixFeeder(graphDb, 10, obelixQueue, obelixCacheQueue, 1);
obelixFeeder.feed();

List<String> allUsers = NeoHelpers.getAllNodes(graphDb, "User");
assertEquals(allUsers.size(), 1);

List<String> allItems = NeoHelpers.getAllNodes(graphDb, "Item");
assertEquals(allItems.size(), 2);

}
}

0 comments on commit 4f7d4cb

Please sign in to comment.