Search in sources :

Example 71 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.

the class TraverserIT method shouldAllowTypeOrderedTraversals.

@Test
@Graph({ "Root knows Mattias", "Root knows Johan", "Johan knows Emil", "Emil knows Peter", "Root eats Cork", "Cork hates Root", "Root likes Banana", "Banana is_a Fruit" })
public void shouldAllowTypeOrderedTraversals() throws JsonParseException {
    Node start = getNode("Root");
    String description = createJsonFrom(map("expander", "order_by_type", "relationships", new Map[] { map("type", "eats"), map("type", "knows"), map("type", "likes") }, "prune_evaluator", map("language", "builtin", "name", "none"), "return_filter", map("language", "javascript", "body", "position.length()<2;")));
    @SuppressWarnings("unchecked") List<Map<String, Object>> nodes = (List<Map<String, Object>>) readJson(gen().expectedStatus(200).payload(description).post(getTraverseUriNodes(start)).entity());
    assertThat(nodes.size(), is(5));
    assertThat(getName(nodes.get(0)), is("Root"));
    assertThat(getName(nodes.get(1)), is("Cork"));
    // We don't really care about the ordering between Johan and Mattias, we just assert that they
    // both are there, in between Root/Cork and Banana
    Set<String> knowsNodes = new HashSet<>(Arrays.asList("Johan", "Mattias"));
    assertTrue(knowsNodes.remove(getName(nodes.get(2))));
    assertTrue(knowsNodes.remove(getName(nodes.get(3))));
    assertThat(getName(nodes.get(4)), is("Banana"));
}
Also used : Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashSet(java.util.HashSet) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 72 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.

the class SetNodePropertiesIT method set_node_properties_in_Unicode.

@Graph("jim knows joe")
@Test
public void set_node_properties_in_Unicode() throws JsonParseException {
    Node jim = data.get().get("jim");
    gen.get().payload(JsonHelper.createJsonFrom(MapUtil.map("name", "例子"))).expectedStatus(204).put(getPropertiesUri(jim));
    assertThat(jim, inTx(graphdb(), hasProperty("name").withValue("例子")));
}
Also used : Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 73 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.

the class RelationshipIT method removeRelationship.

@Test
@Graph(nodes = { @NODE(name = "Romeo", setNameProperty = true), @NODE(name = "Juliet", setNameProperty = true) }, relationships = { @REL(start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP(key = "cost", value = "high", type = GraphDescription.PropType.STRING) }) })
@Title("Delete relationship")
public void removeRelationship() {
    data.get();
    Relationship loves = getFirstRelationshipFromRomeoNode();
    gen().expectedStatus(Status.NO_CONTENT.getStatusCode()).delete(getRelationshipUri(loves)).entity();
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Example 74 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.

the class StreamingBatchOperationIT method execute_multiple_operations_in_batch_streaming.

/**
     * By specifying an extended header attribute in the HTTP request,
     * the server will stream the results back as soon as they are processed on the server side
     * instead of constructing a full response when all entities are processed.
     */
@SuppressWarnings("unchecked")
@Test
@Graph("Joe knows John")
public void execute_multiple_operations_in_batch_streaming() throws Exception {
    long idJoe = data.get().get("Joe").getId();
    String jsonString = new PrettyJSON().array().object().key("method").value("PUT").key("to").value("/node/" + idJoe + "/properties").key("body").object().key("age").value(1).endObject().key("id").value(0).endObject().object().key("method").value("GET").key("to").value("/node/" + idJoe).key("id").value(1).endObject().object().key("method").value("POST").key("to").value("/node").key("body").object().key("age").value(1).endObject().key("id").value(2).endObject().object().key("method").value("POST").key("to").value("/node").key("body").object().key("age").value(1).endObject().key("id").value(3).endObject().endArray().toString();
    String entity = gen.get().expectedType(APPLICATION_JSON_TYPE).withHeader(StreamingFormat.STREAM_HEADER, "true").payload(jsonString).expectedStatus(200).post(batchUri()).entity();
    List<Map<String, Object>> results = JsonHelper.jsonToList(entity);
    assertEquals(4, results.size());
    Map<String, Object> putResult = results.get(0);
    Map<String, Object> getResult = results.get(1);
    Map<String, Object> firstPostResult = results.get(2);
    Map<String, Object> secondPostResult = results.get(3);
    // Ids should be ok
    assertEquals(0, putResult.get("id"));
    assertEquals(2, firstPostResult.get("id"));
    assertEquals(3, secondPostResult.get("id"));
    // Should contain "from"
    assertEquals("/node/" + idJoe + "/properties", putResult.get("from"));
    assertEquals("/node/" + idJoe, getResult.get("from"));
    assertEquals("/node", firstPostResult.get("from"));
    assertEquals("/node", secondPostResult.get("from"));
    // Post should contain location
    assertTrue(((String) firstPostResult.get("location")).length() > 0);
    assertTrue(((String) secondPostResult.get("location")).length() > 0);
    // Should have created by the first PUT request
    Map<String, Object> body = (Map<String, Object>) getResult.get("body");
    assertEquals(1, ((Map<String, Object>) body.get("data")).get("age"));
}
Also used : PrettyJSON(org.neo4j.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 75 with Graph

use of org.neo4j.test.GraphDescription.Graph in project neo4j by neo4j.

the class StreamingBatchOperationIT 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(), Neo4jMatchers.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().expectedType(APPLICATION_JSON_TYPE).withHeader(StreamingFormat.STREAM_HEADER, "true").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 : Node(org.neo4j.graphdb.Node) PrettyJSON(org.neo4j.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Aggregations

Graph (org.neo4j.test.GraphDescription.Graph)96 Test (org.junit.Test)92 Documented (org.neo4j.kernel.impl.annotations.Documented)48 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)37 Title (org.neo4j.test.TestData.Title)36 Node (org.neo4j.graphdb.Node)35 Relationship (org.neo4j.graphdb.Relationship)21 Transaction (org.neo4j.graphdb.Transaction)21 Map (java.util.Map)19 ArrayList (java.util.ArrayList)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)4 HashSet (java.util.HashSet)3 Test (org.junit.jupiter.api.Test)3 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)3 Collection (java.util.Collection)2 List (java.util.List)2 JsonNode (org.codehaus.jackson.JsonNode)2 PrettyJSON (org.neo4j.doc.server.rest.PrettyJSON)2 PrettyJSON (org.neo4j.server.rest.PrettyJSON)2