Search in sources :

Example 21 with ResponseEntity

use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.

the class TransactionDocIT method return_results_in_graph_format.

@Test
@Documented("Return results in graph format\n" + "\n" + "If you want to understand the graph structure of nodes and relationships returned by your query,\n" + "you can specify the \"graph\" results data format. For example, this is useful when you want to visualise the\n" + "graph structure. The format collates all the nodes and relationships from all columns of the result,\n" + "and also flattens collections of nodes and relationships, including paths.")
public void return_results_in_graph_format() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().noGraph().expectedStatus(200).payload(quotedJson("{'statements':[{'statement':" + "'CREATE ( bike:Bike { weight: 10 } ) " + "CREATE ( frontWheel:Wheel { spokes: 3 } ) " + "CREATE ( backWheel:Wheel { spokes: 32 } ) " + "CREATE p1 = (bike)-[:HAS { position: 1 } ]->(frontWheel) " + "CREATE p2 = (bike)-[:HAS { position: 2 } ]->(backWheel) " + "RETURN bike, p1, p2', " + "'resultDataContents': ['row','graph']}] }")).post(txCommitUri());
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Map<String, List<Object>> row = graphRow(result, 0);
    assertEquals(3, row.get("nodes").size());
    assertEquals(2, row.get("relationships").size());
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) ArrayList(java.util.ArrayList) List(java.util.List) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 22 with ResponseEntity

use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.

the class RetrieveNodeDocIT method shouldGet200WhenRetrievingNodeCompact.

@Documented("Get node -- compact.\n" + "\n" + "Specifying the subformat in the requests media type yields a more compact\n" + "JSON response without metadata and templates.")
@Test
public void shouldGet200WhenRetrievingNodeCompact() {
    String uri = nodeUri.toString();
    ResponseEntity entity = gen.get().expectedType(CompactJsonFormat.MEDIA_TYPE).expectedStatus(200).get(uri);
    assertTrue(entity.entity().contains("self"));
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 23 with ResponseEntity

use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.

the class IndexRelationshipDocIT method create_a_unique_relationship_or_return_fail___create.

@Documented("Create a unique relationship or return fail (create).\n" + "\n" + "Here, in case\n" + "of an already existing relationship, an error should be returned. In this\n" + "example, no existing relationship is found and a new relationship is created.")
@Test
public void create_a_unique_relationship_or_return_fail___create() throws Exception {
    final String index = indexes.newInstance(), key = "name", value = "Tobias";
    helper.createRelationshipIndex(index);
    ResponseEntity response = gen.get().noGraph().expectedStatus(201).payloadType(MediaType.APPLICATION_JSON_TYPE).payload("{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"start\": \"" + functionalTestHelper.nodeUri(helper.createNode()) + "\", \"end\": \"" + functionalTestHelper.nodeUri(helper.createNode()) + "\", \"type\":\"" + MyRelationshipTypes.KNOWS + "\"}").post(functionalTestHelper.relationshipIndexUri() + index + "?uniqueness=create_or_fail");
    MultivaluedMap<String, String> headers = response.response().getHeaders();
    Map<String, Object> result = JsonHelper.jsonToMap(response.entity());
    assertEquals(result.get("indexed"), headers.getFirst("Location"));
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Aggregations

ResponseEntity (org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity)23 Test (org.junit.Test)22 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 Documented (org.neo4j.annotations.documented.Documented)13 Documented (org.neo4j.kernel.impl.annotations.Documented)8 ArrayList (java.util.ArrayList)3 Node (org.neo4j.graphdb.Node)3 Transaction (org.neo4j.graphdb.Transaction)3 List (java.util.List)2 Map (java.util.Map)2 HTTP (org.neo4j.doc.server.HTTP)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1