Search in sources :

Example 51 with Graph

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

the class RelationshipDocIT method shouldReturn404WhenPropertyWhichDoesNotExistRemovedFromRelationshipStreaming.

@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) }) })
public void shouldReturn404WhenPropertyWhichDoesNotExistRemovedFromRelationshipStreaming() {
    data.get();
    Relationship loves = getFirstRelationshipFromRomeoNode();
    gen().withHeader(StreamingFormat.STREAM_HEADER, "true").expectedStatus(Status.NOT_FOUND.getStatusCode()).delete(getPropertiesUri(loves) + "/non-existent").entity();
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 52 with Graph

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

the class RelationshipDocIT 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().description(startGraph("Delete relationship1"));
    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 53 with Graph

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

the class RelationshipDocIT method shouldReturn204WhenPropertyIsRemovedFromRelationship.

@Test
@Title("Remove property from a relationship")
@Documented("See the example request below.")
@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 shouldReturn204WhenPropertyIsRemovedFromRelationship() {
    data.get();
    Relationship loves = getFirstRelationshipFromRomeoNode();
    gen().description(startGraph("Remove property from a relationship1"));
    gen().expectedStatus(Status.NO_CONTENT.getStatusCode()).delete(getPropertiesUri(loves) + "/cost").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 54 with Graph

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

the class DepthTwoDocIT method shouldReturnAllPathsAtDepthTwoOnPost.

@Documented("Get paths at depth two.")
@Test
@Graph({ "I know you", "you know him" })
public void shouldReturnAllPathsAtDepthTwoOnPost() throws JsonParseException {
    Node node = data.get().get("I");
    String uri = (String) getNodeLevelPluginMetadata(DepthTwo.class, node.getId()).get(PATHS_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((Integer) map.get("length"), equalTo(2));
}
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 55 with Graph

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

the class ShortestPathDocIT method shouldReturnAllShortestPathsOnPost.

@Documented("Get shortest path.")
@Test
@Graph({ "A knows B", "B knew C", "A knows D", "D knows E", "E knows C" })
public void shouldReturnAllShortestPathsOnPost() throws JsonParseException {
    Node source = data.get().get("C");
    String sourceUri = functionalTestHelper.nodeUri(source.getId());
    Node target = data.get().get("A");
    String targetUri = functionalTestHelper.nodeUri(target.getId());
    String uri = (String) getNodeLevelPluginMetadata(ShortestPath.class, source.getId()).get(SHORTEST_PATHS);
    String body = "{\"target\":\"" + targetUri + "\"}";
    String result = performPost(uri, body);
    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("start").toString(), containsString(sourceUri));
    assertThat(map.get("end").toString(), containsString(targetUri));
    assertThat((Integer) map.get("length"), equalTo(2));
}
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)

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