Search in sources :

Example 46 with JaxRsResponse

use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.

the class PagedTraverserIT method shouldBeAbleToTraverseAllThePagesWithNonDefaultPageSize.

@Documented("Paged traverser page size.\n\n" + "The default page size is 50 items, but\n" + "depending on the application larger or smaller pages sizes might be\n" + "appropriate. This can be set by adding a +pageSize+ query parameter.")
@Test
public void shouldBeAbleToTraverseAllThePagesWithNonDefaultPageSize() {
    theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
    URI traverserLocation = createPagedTraverserWithPageSize(1).getLocation();
    int enoughPagesToExpireTheTraverser = 12;
    for (int i = 0; i < enoughPagesToExpireTheTraverser; i++) {
        JaxRsResponse response = new RestRequest(traverserLocation).get();
        assertEquals(200, response.getStatus());
    }
    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 47 with JaxRsResponse

use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.

the class PagedTraverserIT method shouldHaveTransportEncodingChunkedOnResponseHeader.

@Test
public void shouldHaveTransportEncodingChunkedOnResponseHeader() {
    // given
    theStartNode = createLinkedList(VERY_LONG_LIST_LENGTH, server.getDatabase());
    // when
    JaxRsResponse response = createStreamingPagedTraverserWithTimeoutInMinutesAndPageSize(60, 1000);
    // then
    assertEquals(201, response.getStatus());
    assertEquals("application/json; charset=UTF-8; stream=true", response.getHeaders().getFirst("Content-Type"));
    assertThat(response.getHeaders().getFirst("Transfer-Encoding"), containsString("chunked"));
}
Also used : JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 48 with JaxRsResponse

use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.

the class PagedTraverserIT method shouldExpireTheTraverserAfterDefaultTimeoutAndGetA404Response.

@Test
public void shouldExpireTheTraverserAfterDefaultTimeoutAndGetA404Response() {
    theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
    JaxRsResponse postResponse = createPagedTraverser();
    assertEquals(201, postResponse.getStatus());
    final int TEN_MINUTES = 10;
    clock.forward(TEN_MINUTES, TimeUnit.MINUTES);
    JaxRsResponse getResponse = new RestRequest(postResponse.getLocation()).get();
    assertEquals(404, getResponse.getStatus());
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 49 with JaxRsResponse

use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.

the class PagedTraverserIT method shouldTraverseAllPagesWithANonDefaultTimeoutAndNonDefaultPageSize.

@Test
public void shouldTraverseAllPagesWithANonDefaultTimeoutAndNonDefaultPageSize() {
    theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
    URI traverserLocation = createPagedTraverserWithTimeoutInMinutesAndPageSize(10, 2).getLocation();
    int enoughPagesToExpireTheTraverser = 6;
    for (int i = 0; i < enoughPagesToExpireTheTraverser; i++) {
        JaxRsResponse response = new RestRequest(traverserLocation).get();
        assertEquals(200, response.getStatus());
    }
    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) Test(org.junit.Test)

Example 50 with JaxRsResponse

use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.

the class PagedTraverserIT method should201WithAcceptJsonHeader.

@Test
public void should201WithAcceptJsonHeader() {
    // given
    theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
    String uri = functionalTestHelper.nodeUri(theStartNode.getId()) + "/paged/traverse/node";
    // when
    JaxRsResponse response = RestRequest.req().accept(MediaType.APPLICATION_JSON_TYPE).post(uri, traverserDescription());
    // then
    assertEquals(201, response.getStatus());
    assertNotNull(response.getHeaders().getFirst("Content-Type"));
    assertThat(response.getType().toString(), containsString(MediaType.APPLICATION_JSON));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) 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