Search in sources :

Example 21 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class IndexNodeIT method get_or_create_node_with_array_properties.

@Test
public void get_or_create_node_with_array_properties() throws Exception {
    final String index = indexes.newInstance(), key = "name", value = "Tobias";
    helper.createNodeIndex(index);
    ResponseEntity response = gen().expectedStatus(201).payloadType(MediaType.APPLICATION_JSON_TYPE).payload("{\"key\": \"" + key + "\", \"value\": \"" + value + "\", \"properties\": {\"" + key + "\": \"" + value + "\", \"array\": [1,2,3]}}").post(functionalTestHelper.nodeIndexUri() + index + "?unique");
    MultivaluedMap<String, String> headers = response.response().getHeaders();
    Map<String, Object> result = JsonHelper.jsonToMap(response.entity());
    String location = headers.getFirst("Location");
    assertEquals(result.get("indexed"), location);
    Map<String, Object> data = assertCast(Map.class, result.get("data"));
    assertEquals(value, data.get(key));
    assertEquals(Arrays.asList(1, 2, 3), data.get("array"));
    Node node;
    try (Transaction tx = graphdb().beginTx()) {
        node = graphdb().index().forNodes(index).get(key, value).getSingle();
    }
    assertThat(node, inTx(graphdb(), hasProperty(key).withValue(value)));
    assertThat(node, inTx(graphdb(), hasProperty("array").withValue(new int[] { 1, 2, 3 })));
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 22 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class GetOnRootIT method streaming.

@Documented("All responses from the REST API can be transmitted as JSON streams, resulting in\n" + "better performance and lower memory overhead on the server side. To use\n" + "streaming, supply the header `X-Stream: true` with each request.")
@Test
public void streaming() throws Exception {
    data.get();
    ResponseEntity responseEntity = gen().withHeader(StreamingFormat.STREAM_HEADER, "true").expectedType(APPLICATION_JSON_TYPE).expectedStatus(200).get(getDataUri());
    JaxRsResponse response = responseEntity.response();
    // this gets the full media type, including things like
    // ; stream=true at the end
    String foundMediaType = response.getType().toString();
    String expectedMediaType = StreamingFormat.MEDIA_TYPE.toString();
    assertEquals(expectedMediaType, foundMediaType);
    String body = responseEntity.entity();
    Map<String, Object> map = JsonHelper.jsonToMap(body);
    assertEquals(getDataUri() + "node", map.get("node"));
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 23 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class RetrieveNodeIT 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.server.rest.RESTRequestGenerator.ResponseEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 24 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class PagedTraverserIT method shouldPostATraverserWithDefaultOptionsAndReceiveTheFirstPageOfResults.

@Documented("Creating a paged traverser.\n\n" + "Paged traversers are created by ++POST++-ing a\n" + "traversal description to the link identified by the +paged_traverser+ key\n" + "in a node representation. When creating a paged traverser, the same\n" + "options apply as for a regular traverser, meaning that +node+, +path+,\n" + "or +fullpath+, can be targeted.")
@Test
public void shouldPostATraverserWithDefaultOptionsAndReceiveTheFirstPageOfResults() throws Exception {
    theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
    ResponseEntity entity = gen.get().expectedType(MediaType.valueOf("application/json; charset=UTF-8")).expectedHeader("Location").expectedStatus(201).payload(traverserDescription()).payloadType(MediaType.APPLICATION_JSON_TYPE).post(functionalTestHelper.nodeUri(theStartNode.getId()) + "/paged/traverse/node");
    assertEquals(201, entity.response().getStatus());
    assertThat(entity.response().getLocation().toString(), containsString("/db/data/node/" + theStartNode.getId() + "/paged/traverse/node/"));
    assertEquals("application/json; charset=UTF-8", entity.response().getType().toString());
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 25 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class TransactionTest 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().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(getDataUri() + "transaction/commit");
    // 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.server.rest.RESTRequestGenerator.ResponseEntity) ArrayList(java.util.ArrayList) List(java.util.List) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Aggregations

ResponseEntity (org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity)36 Test (org.junit.Test)22 Documented (org.neo4j.kernel.impl.annotations.Documented)20 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 Test (org.junit.jupiter.api.Test)12 Documented (org.neo4j.annotations.documented.Documented)12 ArrayList (java.util.ArrayList)6 List (java.util.List)5 HTTP (org.neo4j.test.server.HTTP)4 Node (org.neo4j.graphdb.Node)3 Transaction (org.neo4j.graphdb.Transaction)3 Map (java.util.Map)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1