Permalink
Browse files

Added test for unclosed graph.

  • Loading branch information...
1 parent 77421d7 commit c11ac8a642dd8eb17422bed5cf14d3a01b4dd027 @dmontag committed Feb 14, 2011
@@ -3,4 +3,5 @@ agents.SimpleIndexingGraph
agents.UnclosedIndexingGraph
agents.FulltextIndexingGraph
agents.ExhaustiveGraph
-agents.UnfinishedTransactionGraph
+agents.UnfinishedTransactionGraph
+agents.UnclosedGraph
@@ -0,0 +1,47 @@
+package agents;
+
+import org.neo4j.compatibility.StoreAgent;
+import org.neo4j.graphdb.Direction;
+import org.neo4j.graphdb.DynamicRelationshipType;
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.RelationshipType;
+import org.neo4j.graphdb.Transaction;
+import org.neo4j.helpers.collection.IteratorUtil;
+import org.neo4j.kernel.EmbeddedGraphDatabase;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import static org.junit.Assert.assertEquals;
+
+public class UnclosedGraph implements StoreAgent
+{
+ private static final RelationshipType REL_TYPE = DynamicRelationshipType.withName( "REL" );
+
+ public void generate( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Transaction tx = graphDb.beginTx();
+ try
+ {
+ Node n = graphDb.createNode();
+ n.createRelationshipTo( graphDb.createNode(), REL_TYPE );
+ tx.success();
+ }
+ finally
+ {
+ tx.finish();
+ }
+ }
+
+ public void verify( String dbPath )
+ {
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase( dbPath );
+ Node n = graphDb.getNodeById( 1 );
+ Node n2 = n.getSingleRelationship( REL_TYPE, Direction.OUTGOING ).getEndNode();
+ assertEquals( new HashSet<Node>( Arrays.asList( graphDb.getReferenceNode(), n, n2 ) ),
+ IteratorUtil.addToCollection( graphDb.getAllNodes(), new HashSet<Node>() ) );
+ graphDb.shutdown();
+ }
+}

0 comments on commit c11ac8a

Please sign in to comment.