Search in sources :

Example 91 with Graph

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

the class DepthTwoDocIT method shouldReturnAllNodesAtDepthTwoOnPost.

@Documented("Get nodes at depth two.")
@Test
@Graph({ "I know you", "you know him" })
public void shouldReturnAllNodesAtDepthTwoOnPost() throws JsonParseException {
    Node node = data.get().get("I");
    String uri = (String) getNodeLevelPluginMetadata(DepthTwo.class, node.getId()).get(NODES_ON_DEPTH_TWO);
    String result = performPost(uri);
    List<Map<String, Object>> list = JsonHelper.jsonToList(result);
    assertThat(list, notNullValue());
    assertThat(list.size(), equalTo(1));
    Map<String, Object> map = list.get(0);
    assertThat(map.get("data").toString(), containsString("him"));
}
Also used : Node(org.neo4j.graphdb.Node) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 92 with Graph

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

the class DepthTwoDocIT method shouldReturnAllRelationshipsAtDepthTwoOnPost.

@Documented("Get relationships at depth two.")
@Test
@Graph({ "I know you", "you know him" })
public void shouldReturnAllRelationshipsAtDepthTwoOnPost() throws JsonParseException {
    Node node = data.get().get("I");
    String uri = (String) getNodeLevelPluginMetadata(DepthTwo.class, node.getId()).get(RELATIONSHIPS_ON_DEPTH_TWO);
    String result = performPost(uri);
    List<Map<String, Object>> list = JsonHelper.jsonToList(result);
    assertThat(list, notNullValue());
    assertThat(list.size(), equalTo(1));
    Map<String, Object> map = list.get(0);
    assertThat(map.get("type").toString(), containsString("know"));
}
Also used : Node(org.neo4j.graphdb.Node) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) Graph(org.neo4j.test.GraphDescription.Graph) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 93 with Graph

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

the class RelationshipDocIT method get_Relationship_by_ID.

@Test
@Graph("I know you")
public void get_Relationship_by_ID() throws JsonParseException {
    Node node = data.get().get("I");
    Relationship relationship;
    try (Transaction transaction = node.getGraphDatabase().beginTx()) {
        relationship = node.getSingleRelationship(RelationshipType.withName("know"), Direction.OUTGOING);
    }
    String response = gen().expectedStatus(com.sun.jersey.api.client.ClientResponse.Status.OK.getStatusCode()).get(getRelationshipUri(relationship)).entity();
    assertTrue(JsonHelper.jsonToMap(response).containsKey("start"));
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 94 with Graph

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

the class RelationshipDocIT method shouldReturn204WhenPropertiesAreRemovedFromRelationship.

@Test
@Title("Remove properties from a relationship")
@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 shouldReturn204WhenPropertiesAreRemovedFromRelationship() {
    Relationship loves = getFirstRelationshipFromRomeoNode();
    gen().description(startGraph("remove properties from a relationship")).expectedStatus(Status.NO_CONTENT.getStatusCode()).delete(functionalTestHelper.relationshipPropertiesUri(loves.getId())).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 95 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() {
    Map<String, Node> graph = data.get();
    Set<Node> unique = new HashSet<>();
    Node n = graph.get("a");
    while (unique.add(n)) {
        try (Transaction tx = graphdb.beginTx()) {
            n = tx.getNodeById(n.getId()).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.jupiter.api.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