forked from jexp/neo4j-java-rest-binding
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first version of the tests for the new rest batch api
- Loading branch information
Klemens Burchardi
committed
Sep 15, 2011
1 parent
e28edbb
commit 3eaa05f
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
src/test/java/org/neo4j/rest/graphdb/RestBatchAPITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.neo4j.rest.graphdb; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.neo4j.graphdb.Direction; | ||
import org.neo4j.graphdb.Node; | ||
import org.neo4j.graphdb.Relationship; | ||
|
||
public class RestBatchAPITest extends RestTestBase { | ||
private RestAPI restAPI; | ||
|
||
|
||
@Before | ||
public void init(){ | ||
this.restAPI = ((RestGraphDatabase)getRestGraphDb()).getRestAPI(); | ||
} | ||
|
||
@Test | ||
public void testCreateNode(){ | ||
RequestResult response =this.restAPI.executeBatch(new BatchCallback() { | ||
|
||
@Override | ||
public void recordBatch(RestAPI batchRestApi) { | ||
Map<String, Object> props = new HashMap<String, Object>(); | ||
props.put("name", "node1"); | ||
Node n1 = batchRestApi.createNode(props); | ||
Map<String, Object> props2 = new HashMap<String, Object>(); | ||
props2.put("name", "node2"); | ||
Node n2 = batchRestApi.createNode(props2); | ||
} | ||
}); | ||
//System.out.println(response.getEntity()); | ||
Assert.assertEquals( "node1", getRestGraphDb().getNodeById(1).getProperty("name") ); | ||
Assert.assertEquals( "node2", getRestGraphDb().getNodeById(2).getProperty("name") ); | ||
} | ||
|
||
@Test | ||
public void testCreateRelationship(){ | ||
RequestResult response =this.restAPI.executeBatch(new BatchCallback() { | ||
|
||
@Override | ||
public void recordBatch(RestAPI batchRestApi) { | ||
|
||
Map<String, Object> props = new HashMap<String, Object>(); | ||
props.put("name", "node1"); | ||
Node n1 = batchRestApi.createNode(props); | ||
Map<String, Object> props2 = new HashMap<String, Object>(); | ||
props2.put("name", "node2"); | ||
Node n2 = batchRestApi.createNode(props2); | ||
|
||
Map<String, Object> propsrel = new HashMap<String, Object>(); | ||
propsrel.put("name", "rel"); | ||
|
||
Relationship rel = batchRestApi.createRelationship(n1, n2, Type.TEST, propsrel ); | ||
|
||
} | ||
}); | ||
System.out.println(response.getEntity()); | ||
Node n1 = getRestGraphDb().getNodeById(3); | ||
Node n2 = getRestGraphDb().getNodeById(4); | ||
Relationship rel = n1.getSingleRelationship(Type.TEST, Direction.OUTGOING); | ||
|
||
Relationship foundRelationship = TestHelper.firstRelationshipBetween( n1.getRelationships( Type.TEST, Direction.OUTGOING ), n1, n2 ); | ||
Assert.assertNotNull( "found relationship", foundRelationship ); | ||
Assert.assertEquals( "same relationship", rel, foundRelationship ); | ||
Assert.assertThat( n1.getRelationships( Type.TEST, Direction.OUTGOING ), new IsRelationshipToNodeMatcher( n1, n2 ) ); | ||
Assert.assertThat( n1.getRelationships( Direction.OUTGOING ), new IsRelationshipToNodeMatcher( n1, n2 ) ); | ||
Assert.assertThat( n1.getRelationships( Direction.BOTH ), new IsRelationshipToNodeMatcher( n1, n2 ) ); | ||
Assert.assertThat( n1.getRelationships( Type.TEST ), new IsRelationshipToNodeMatcher( n1, n2 ) ); | ||
Assert.assertEquals( "rel", rel.getProperty("name") ); | ||
} | ||
|
||
|
||
} |