Search in sources :

Example 31 with Graph

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());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) HashSet(java.util.HashSet) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 32 with Graph

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());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph)

Example 33 with Graph

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());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 34 with Graph

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();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 35 with Graph

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);
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node) Map(java.util.Map) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Aggregations

Graph (org.neo4j.test.GraphDescription.Graph)48 Test (org.junit.Test)47 Documented (org.neo4j.kernel.impl.annotations.Documented)21 Title (org.neo4j.test.TestData.Title)18 Node (org.neo4j.graphdb.Node)17 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)16 Transaction (org.neo4j.graphdb.Transaction)13 Relationship (org.neo4j.graphdb.Relationship)11 Map (java.util.Map)7 ArrayList (java.util.ArrayList)3 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)3 HashSet (java.util.HashSet)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 PrettyJSON (org.neo4j.server.rest.PrettyJSON)2 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)2 Collection (java.util.Collection)1 List (java.util.List)1 JsonNode (org.codehaus.jackson.JsonNode)1 PathExpander (org.neo4j.graphdb.PathExpander)1