This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* changed classname to correspond to the BatchRestAPI class
- Loading branch information
Klemens Burchardi
committed
Sep 20, 2011
1 parent
97a4dcc
commit 9e093fd
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/test/java/org/neo4j/rest/graphdb/BatchRestAPITest.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,90 @@ | ||
package org.neo4j.rest.graphdb; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
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; | ||
import org.neo4j.helpers.collection.MapUtil; | ||
|
||
public class BatchRestAPITest extends RestTestBase { | ||
private RestAPI restAPI; | ||
|
||
|
||
@Before | ||
public void init(){ | ||
this.restAPI = ((RestGraphDatabase)getRestGraphDb()).getRestAPI(); | ||
} | ||
|
||
@Test | ||
public void testCreateNode(){ | ||
TwoNodes response =this.restAPI.executeBatch(new BatchCallback() { | ||
|
||
@Override | ||
public TwoNodes recordBatch(RestAPI batchRestApi) { | ||
TwoNodes tNodes; | ||
Node n1 = batchRestApi.createNode(MapUtil.map("name", "node1")); | ||
Node n2 = batchRestApi.createNode(MapUtil.map("name", "node2")); | ||
tNodes = new TwoNodes(n1, n2); | ||
return tNodes; | ||
} | ||
}); | ||
//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() { | ||
this.restAPI.executeBatch(new BatchCallback() { | ||
@Override | ||
public Void recordBatch(RestAPI batchRestApi) { | ||
|
||
Node n1 = batchRestApi.createNode(MapUtil.map("name", "newnode1")); | ||
Node n2 = batchRestApi.createNode(MapUtil.map("name", "newnode2")); | ||
Relationship rel = batchRestApi.createRelationship(n1, n2, Type.TEST, MapUtil.map("name", "rel") ); | ||
return null; | ||
} | ||
}); | ||
//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") ); | ||
} | ||
|
||
static class TwoNodes{ | ||
Node n1; | ||
Node n2; | ||
|
||
TwoNodes(Node node1, Node node2){ | ||
n1 = node1; | ||
n2 = node2; | ||
} | ||
|
||
public Node getN1() { | ||
return n1; | ||
} | ||
|
||
public Node getN2() { | ||
return n2; | ||
} | ||
} | ||
} |