use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.
the class PagedTraverserIT method shouldAcceptJsonAndStreamingFlagAndProduceStreamedJson.
@Test
public void shouldAcceptJsonAndStreamingFlagAndProduceStreamedJson() {
// given
theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
// when
JaxRsResponse pagedTraverserResponse = createStreamingPagedTraverserWithTimeoutInMinutesAndPageSize(60, 1);
System.out.println(pagedTraverserResponse.getHeaders().getFirst("Content-Type"));
// then
assertNotNull(pagedTraverserResponse.getHeaders().getFirst("Content-Type"));
assertThat(pagedTraverserResponse.getHeaders().getFirst("Content-Type"), containsString("application/json; charset=UTF-8; stream=true"));
}
use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.
the class PagedTraverserIT method shouldBeAbleToTraverseAllThePagesWithDefaultPageSize.
@Documented("Paging through the results of a paged traverser.\n\n" + "Paged traversers holdstate on the server, and allow clients to page through\n" + "the results of a traversal. To progress to the next page of traversal results,\n" + "the client issues a HTTP GET request on the paged traversal URI which causes the\n" + "traversal to fill the next page (or partially fill it if insufficient\n" + "results are available).\n" + " \n" + "Note that if a traverser expires through inactivity it will cause a 404\n" + "response on the next +GET+ request. Traversers' leases are renewed on\n" + "every successful access for the same amount of time as originally\n" + "specified.\n" + " \n" + "When the paged traverser reaches the end of its results, the client can\n" + "expect a 404 response as the traverser is disposed by the server.")
@Test
public void shouldBeAbleToTraverseAllThePagesWithDefaultPageSize() {
theStartNode = createLinkedList(LONG_LIST_LENGTH, server.getDatabase());
URI traverserLocation = createPagedTraverser().getLocation();
int enoughPagesToExpireTheTraverser = 3;
for (int i = 0; i < enoughPagesToExpireTheTraverser; i++) {
gen.get().expectedType(MediaType.APPLICATION_JSON_TYPE).expectedStatus(200).payload(traverserDescription()).get(traverserLocation.toString());
}
JaxRsResponse response = new RestRequest(traverserLocation).get();
assertEquals(404, response.getStatus());
}
use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.
the class PagedTraverserIT method nodeRepresentationShouldHaveLinkToPagedTraverser.
@Test
public void nodeRepresentationShouldHaveLinkToPagedTraverser() throws Exception {
theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
JaxRsResponse response = RestRequest.req().get(functionalTestHelper.nodeUri(theStartNode.getId()));
Map<String, Object> jsonMap = JsonHelper.jsonToMap(response.getEntity());
assertNotNull(jsonMap.containsKey(PAGED_TRAVERSE_LINK_REL));
assertThat(String.valueOf(jsonMap.get(PAGED_TRAVERSE_LINK_REL)), containsString("/db/data/node/" + String.valueOf(theStartNode.getId()) + "/paged/traverse/{returnType}{?pageSize,leaseTime}"));
}
use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.
the class PagedTraverserIT method shouldExpireTraverserWithNonDefaultTimeout.
@Documented("Paged traverser timeout.\n\n" + "The default timeout for a paged traverser is 60\n" + "seconds, but depending on the application larger or smaller timeouts\n" + "might be appropriate. This can be set by adding a +leaseTime+ query\n" + "parameter with the number of seconds the paged traverser should last.")
@Test
public void shouldExpireTraverserWithNonDefaultTimeout() {
theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
URI traverserLocation = createPagedTraverserWithTimeoutInMinutes(10).getLocation();
clock.forward(11, TimeUnit.MINUTES);
JaxRsResponse response = new RestRequest(traverserLocation).get();
assertEquals(404, response.getStatus());
}
use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.
the class PagedTraverserIT method shouldRespondWith400OnScriptErrors.
@Test
public void shouldRespondWith400OnScriptErrors() {
GlobalJavascriptInitializer.initialize(GlobalJavascriptInitializer.Mode.SANDBOXED);
theStartNode = createLinkedList(1, server.getDatabase());
JaxRsResponse response = RestRequest.req().post(functionalTestHelper.nodeUri(theStartNode.getId()) + "/paged/traverse/node?pageSize=50", "{" + "\"prune_evaluator\":{\"language\":\"builtin\",\"name\":\"none\"}," + "\"return_filter\":{\"language\":\"javascript\",\"body\":\"position.getClass()" + ".getClassLoader();\"}," + "\"order\":\"depth_first\"," + "\"relationships\":{\"type\":\"NEXT\",\"direction\":\"out\"}" + "}");
assertEquals(400, response.getStatus());
}
Aggregations