use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.
the class TestGraphDescription method canCreateGraphFromMultipleStrings.
@Test
@Graph({ "a TO b", "b TO c", "c TO a" })
public void canCreateGraphFromMultipleStrings() throws Exception {
Map<String, Node> graph = data.get();
Set<Node> unique = new HashSet<Node>();
Node n = graph.get("a");
while (unique.add(n)) {
try (Transaction ignored = graphdb.beginTx()) {
n = n.getSingleRelationship(RelationshipType.withName("TO"), Direction.OUTGOING).getEndNode();
}
}
assertEquals(graph.size(), unique.size());
}
use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.
the class TestGraphDescription method verifyIKnowYou.
@Graph(value = { "I know you" }, nodes = { @NODE(name = "I", properties = { @PROP(key = "name", value = "me") }) })
private void verifyIKnowYou(String type, String myName) {
try (Transaction ignored = graphdb.beginTx()) {
Map<String, Node> graph = data.get();
assertEquals("Wrong graph size.", 2, graph.size());
Node I = graph.get("I");
assertNotNull("The node 'I' was not defined", I);
Node you = graph.get("you");
assertNotNull("The node 'you' was not defined", you);
assertEquals("'I' has wrong 'name'.", myName, I.getProperty("name"));
assertEquals("'you' has wrong 'name'.", "you", you.getProperty("name"));
Iterator<Relationship> rels = I.getRelationships().iterator();
assertTrue("'I' has too few relationships", rels.hasNext());
Relationship rel = rels.next();
assertEquals("'I' is not related to 'you'", you, rel.getOtherNode(I));
assertEquals("Wrong relationship type.", type, rel.getType().name());
assertFalse("'I' has too many relationships", rels.hasNext());
rels = you.getRelationships().iterator();
assertTrue("'you' has too few relationships", rels.hasNext());
rel = rels.next();
assertEquals("'you' is not related to 'i'", I, rel.getOtherNode(you));
assertEquals("Wrong relationship type.", type, rel.getType().name());
assertFalse("'you' has too many relationships", rels.hasNext());
assertEquals("wrong direction", I, rel.getStartNode());
}
}
use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.
the class TestGraphDescription method canCreateMoreInvolvedGraphWithPropertiesAndAutoIndex.
@Test
@Graph(nodes = { @NODE(name = "I", properties = { @PROP(key = "name", value = "me"), @PROP(key = "bool", value = "true", type = GraphDescription.PropType.BOOLEAN) }), @NODE(name = "you", setNameProperty = true) }, relationships = { @REL(start = "I", end = "you", type = "knows", properties = { @PROP(key = "name", value = "relProp"), @PROP(key = "valid", value = "true", type = GraphDescription.PropType.BOOLEAN) }) }, autoIndexRelationships = true)
public void canCreateMoreInvolvedGraphWithPropertiesAndAutoIndex() throws Exception {
data.get();
verifyIKnowYou("knows", "me");
try (Transaction ignored = graphdb.beginTx()) {
assertEquals(true, data.get().get("I").getProperty("bool"));
assertFalse("node autoindex enabled.", graphdb().index().getNodeAutoIndexer().isEnabled());
assertTrue("can't look up rel.", graphdb().index().getRelationshipAutoIndexer().getAutoIndex().get("name", "relProp").hasNext());
assertTrue("relationship autoindex enabled.", graphdb().index().getRelationshipAutoIndexer().isEnabled());
}
}
use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.
the class AutoIndexIT method autoindexed_relationships_cannot_be_removed_manually.
/**
* It is not allowed to remove entries manually from automatic indexes.
*/
@Test
@Graph(nodes = { @NODE(name = "I"), @NODE(name = "you") }, relationships = { @REL(start = "I", end = "you", type = "know", properties = { @PROP(key = "since", value = "today") }) }, autoIndexRelationships = true)
public void autoindexed_relationships_cannot_be_removed_manually() {
try (Transaction tx = graphdb().beginTx()) {
data.get();
tx.success();
}
try (Transaction tx = graphdb().beginTx()) {
long id = data.get().get("I").getRelationships().iterator().next().getId();
String indexName = graphdb().index().getRelationshipAutoIndexer().getAutoIndex().getName();
gen.get().expectedStatus(405).delete(getDataUri() + "index/relationship/" + indexName + "/since/today/" + id).entity();
gen.get().expectedStatus(405).delete(getDataUri() + "index/relationship/" + indexName + "/since/" + id).entity();
gen.get().expectedStatus(405).delete(getDataUri() + "index/relationship/" + indexName + "/" + id).entity();
}
}
use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.
the class BatchOperationIT method shouldHandleEscapedStrings.
@Test
@Graph("Peter likes Jazz")
public void shouldHandleEscapedStrings() throws ClientHandlerException, UniformInterfaceException, JSONException, JsonParseException {
String string = "Jazz";
Node gnode = getNode(string);
assertThat(gnode, inTx(graphdb(), hasProperty("name").withValue(string)));
String name = "string\\ and \"test\"";
String jsonString = new PrettyJSON().array().object().key("method").value("PUT").key("to").value("/node/" + gnode.getId() + "/properties").key("body").object().key("name").value(name).endObject().endObject().endArray().toString();
gen.get().expectedStatus(200).payload(jsonString).post(batchUri()).entity();
jsonString = new PrettyJSON().array().object().key("method").value("GET").key("to").value("/node/" + gnode.getId() + "/properties/name").endObject().endArray().toString();
String entity = gen.get().expectedStatus(200).payload(jsonString).post(batchUri()).entity();
List<Map<String, Object>> results = JsonHelper.jsonToList(entity);
assertEquals(results.get(0).get("body"), name);
}
Aggregations