use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class ExecutionResultSerializerTest method shouldProduceResultStreamWithLegacyRestFormat.
@Test
public void shouldProduceResultStreamWithLegacyRestFormat() throws Exception {
// given
Node[] node = { node(0, properties(property("name", "node0"))), node(1, properties(property("name", "node1"))), node(2, properties(property("name", "node2"))) };
Relationship[] rel = { relationship(0, node[0], "KNOWS", node[1], property("name", "rel0")), relationship(1, node[2], "LOVES", node[1], property("name", "rel1")) };
Path path = GraphMock.path(node[0], link(rel[0], node[1]), link(rel[1], node[2]));
ByteArrayOutputStream output = new ByteArrayOutputStream();
ExecutionResultSerializer serializer = getSerializerWith(output, "http://base.uri/");
// when
serializer.statementResult(mockExecutionResult(map("node", node[0], "rel", rel[0], "path", path, "map", map("n1", node[1], "r1", rel[1]))), false, ResultDataContent.rest);
serializer.finish();
// then
String result = output.toString(UTF_8.name());
JsonNode json = jsonNode(result);
Map<String, Integer> columns = new HashMap<>();
int col = 0;
JsonNode results = json.get("results").get(0);
for (JsonNode column : results.get("columns")) {
columns.put(column.getTextValue(), col++);
}
JsonNode row = results.get("data").get(0).get("rest");
JsonNode jsonNode = row.get(columns.get("node"));
JsonNode jsonRel = row.get(columns.get("rel"));
JsonNode jsonPath = row.get(columns.get("path"));
JsonNode jsonMap = row.get(columns.get("map"));
assertEquals("http://base.uri/node/0", jsonNode.get("self").getTextValue());
assertEquals("http://base.uri/relationship/0", jsonRel.get("self").getTextValue());
assertEquals(2, jsonPath.get("length").getNumberValue());
assertEquals("http://base.uri/node/0", jsonPath.get("start").getTextValue());
assertEquals("http://base.uri/node/2", jsonPath.get("end").getTextValue());
assertEquals("http://base.uri/node/1", jsonMap.get("n1").get("self").getTextValue());
assertEquals("http://base.uri/relationship/1", jsonMap.get("r1").get("self").getTextValue());
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class ExecutionResultSerializerTest method mockPath.
private static Path mockPath(Map<String, Object> startNodeProperties, Map<String, Object> relationshipProperties, Map<String, Object> endNodeProperties) {
Node startNode = node(1, properties(startNodeProperties));
Node endNode = node(2, properties(endNodeProperties));
Relationship relationship = relationship(1, properties(relationshipProperties), startNode, "RELATED", endNode);
return path(startNode, Link.link(relationship, endNode));
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class DeletionTest method shouldDeleteRecords.
/**
* The problem would manifest even if the transaction was performed on the Master, it would then occur when the
* Slave pulls updates and tries to apply the transaction. The reason for the test to run transactions against the
* Slave is because it makes guarantees for when the master has to apply the transaction.
*/
@Test
public void shouldDeleteRecords() throws Throwable {
// given
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase master = cluster.getMaster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
Relationship rel;
try (Transaction tx = slave.beginTx()) {
rel = slave.createNode().createRelationshipTo(slave.createNode(), withName("FOO"));
tx.success();
}
try (Transaction transaction = master.beginTx()) {
assertNotNull(master.getRelationshipById(rel.getId()));
}
// when
try (Transaction tx = slave.beginTx()) {
rel.delete();
tx.success();
}
// then - there should have been no exceptions
slave.shutdown();
master.shutdown();
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class AbstractTestBase method removeAllNodes.
protected static void removeAllNodes(boolean removeReference) {
Transaction tx = graphdb.beginTx();
try {
Node reference = removeReference ? null : graphdb.getReferenceNode();
for (Node node : graphdb.getAllNodes()) {
for (Relationship rel : node.getRelationships()) {
rel.delete();
}
if (!node.equals(reference)) {
node.delete();
}
}
tx.success();
} finally {
tx.finish();
}
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestRelationship method testRelationshipCreateAndDelete.
@Test
public void testRelationshipCreateAndDelete() {
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship relationship = node1.createRelationshipTo(node2, MyRelTypes.TEST);
Relationship[] relArray1 = getRelationshipArray(node1.getRelationships());
Relationship[] relArray2 = getRelationshipArray(node2.getRelationships());
assertEquals(1, relArray1.length);
assertEquals(relationship, relArray1[0]);
assertEquals(1, relArray2.length);
assertEquals(relationship, relArray2[0]);
relArray1 = getRelationshipArray(node1.getRelationships(MyRelTypes.TEST));
assertEquals(1, relArray1.length);
assertEquals(relationship, relArray1[0]);
relArray2 = getRelationshipArray(node2.getRelationships(MyRelTypes.TEST));
assertEquals(1, relArray2.length);
assertEquals(relationship, relArray2[0]);
relArray1 = getRelationshipArray(node1.getRelationships(MyRelTypes.TEST, Direction.OUTGOING));
assertEquals(1, relArray1.length);
relArray2 = getRelationshipArray(node2.getRelationships(MyRelTypes.TEST, Direction.INCOMING));
assertEquals(1, relArray2.length);
relArray1 = getRelationshipArray(node1.getRelationships(MyRelTypes.TEST, Direction.INCOMING));
assertEquals(0, relArray1.length);
relArray2 = getRelationshipArray(node2.getRelationships(MyRelTypes.TEST, Direction.OUTGOING));
assertEquals(0, relArray2.length);
relationship.delete();
node2.delete();
node1.delete();
}
Aggregations