Search in sources :

Example 11 with JaxRsResponse

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"));
}
Also used : JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 12 with JaxRsResponse

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());
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) URI(java.net.URI) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 13 with JaxRsResponse

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}"));
}
Also used : JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 14 with JaxRsResponse

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());
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) URI(java.net.URI) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 15 with JaxRsResponse

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());
}
Also used : JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Aggregations

JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)58 Test (org.junit.Test)52 RestRequest (org.neo4j.server.rest.RestRequest)29 Matchers.containsString (org.hamcrest.Matchers.containsString)19 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)13 PrettyJSON (org.neo4j.server.rest.PrettyJSON)8 URI (java.net.URI)7 Documented (org.neo4j.kernel.impl.annotations.Documented)6 Map (java.util.Map)4 Client (com.sun.jersey.api.client.Client)3 Title (org.neo4j.test.TestData.Title)3 File (java.io.File)2 FileUtils.readTextFile (org.neo4j.io.fs.FileUtils.readTextFile)2 NeoServer (org.neo4j.server.NeoServer)2 HashMap (java.util.HashMap)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1 CommunityServerBuilder (org.neo4j.server.helpers.CommunityServerBuilder)1 BadInputException (org.neo4j.server.rest.repr.BadInputException)1 NodeRepresentationTest (org.neo4j.server.rest.repr.NodeRepresentationTest)1 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)1