Search in sources :

Example 41 with Graph

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

the class CypherIT method array_property.

@Test
@Graph(value = { "I know you" }, autoIndexNodes = false)
public void array_property() throws Exception {
    setProperty("I", "array1", new int[] { 1, 2, 3 });
    setProperty("I", "array2", new String[] { "a", "b", "c" });
    String script = "MATCH (n) WHERE id(n) = %I% RETURN n.array1, n.array2";
    String response = cypherRestCall(script, Status.OK);
    assertThat(response, anyOf(containsString("[ 1, 2, 3 ]"), containsString("[1,2,3]")));
    assertThat(response, anyOf(containsString("[ \"a\", \"b\", \"c\" ]"), containsString("[\"a\",\"b\",\"c\"]")));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 42 with Graph

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

the class CypherIT method send_query_to_create_a_node_from_a_map.

@Test
@Title("Create a node with multiple properties")
@Documented("Create a node with a label and multiple properties using Cypher. See the request for the parameter " + "sent with the query.")
@Graph
public void send_query_to_create_a_node_from_a_map() throws Exception {
    data.get();
    String script = "CREATE (n:Person { props } ) RETURN n";
    String params = "\"props\" : { \"position\" : \"Developer\", \"name\" : \"Michael\", \"awesome\" : true, \"children\" : 3 }";
    String response = cypherRestCall(script, Status.OK, params);
    assertTrue(response.contains("name"));
    assertTrue(response.contains("Michael"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Example 43 with Graph

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

the class RelationshipIT method shouldReturn404WhenPropertyWhichDoesNotExistRemovedFromRelationship.

@Test
@Title("Remove non-existent property from a relationship")
@Documented("Attempting to remove a property that doesn't exist results in an error.")
@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) }) })
public void shouldReturn404WhenPropertyWhichDoesNotExistRemovedFromRelationship() {
    data.get();
    Relationship loves = getFirstRelationshipFromRomeoNode();
    gen().expectedStatus(Status.NOT_FOUND.getStatusCode()).delete(getPropertiesUri(loves) + "/non-existent").entity();
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Example 44 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 45 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)

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