Search in sources :

Example 11 with RestRequest

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

the class PagedTraverserDocIT method shouldBeAbleToTraverseAllThePagesWithDefaultPageSize.

@Documented("Paging through the results of a paged traverser.\n\n" + "Paged traversers hold state on the server, and allow clients to page through the results of a traversal.\n" + "To progress to the next page of traversal results, the client issues a HTTP `GET` request on the paged traversal URI which causes the traversal to fill the next page (or partially fill it if insufficient results are available).\n \n" + "Note that if a traverser expires through inactivity it will cause a 404 response on the next `GET` request.\n" + "Traversers' leases are renewed on every successful access for the same amount of time as originally specified.\n\n" + "When the paged traverser reaches the end of its results, the client can 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.doc.server.rest.RestRequest) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) URI(java.net.URI) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 12 with RestRequest

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

the class NeoServerJAXRSDocIT method shouldMakeJAXRSClassesAvailableViaHTTP.

@Test
public void shouldMakeJAXRSClassesAvailableViaHTTP() throws Exception {
    CommunityWebContainerBuilder builder = CommunityWebContainerBuilder.builder();
    webContainer = WebContainerHelper.createContainer(builder, folder, true);
    FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper(webContainer);
    JaxRsResponse response = new RestRequest().get(functionalTestHelper.baseUri().toASCIIString());
    assertEquals(200, response.getStatus());
}
Also used : CommunityWebContainerBuilder(org.neo4j.doc.server.helpers.CommunityWebContainerBuilder) RestRequest(org.neo4j.doc.server.rest.RestRequest) FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 13 with RestRequest

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

the class BatchOperationHeaderDocIT method shouldPassHeaders.

@Test
public void shouldPassHeaders() throws Exception {
    String jsonData = new PrettyJSON().array().object().key("method").value("GET").key("to").value("../.." + DUMMY_WEB_SERVICE_MOUNT_POINT + "/needs-auth-header").key("body").object().endObject().endObject().endArray().toString();
    JaxRsResponse response = new RestRequest(null, "user", "pass").post("http://localhost:7474/db/data/batch", jsonData);
    assertEquals(200, response.getStatus());
    final List<Map<String, Object>> responseData = jsonToList(response.getEntity());
    Map<String, Object> res = (Map<String, Object>) responseData.get(0).get("body");
    /*
         * {
         *   Accept=[application/json],
         *   Content-Type=[application/json],
         *   Authorization=[Basic dXNlcjpwYXNz],
         *   User-Agent=[Java/1.6.0_27] <-- ignore that, it changes often
         *   Host=[localhost:7474],
         *   Connection=[keep-alive],
         *   Content-Length=[86]
         * }
         */
    assertEquals("Basic dXNlcjpwYXNz", res.get("Authorization"));
    assertEquals("application/json", res.get("Accept"));
    assertEquals("application/json", res.get("Content-Type"));
    assertEquals("localhost:7474", res.get("Host"));
    assertEquals("keep-alive", res.get("Connection"));
}
Also used : RestRequest(org.neo4j.doc.server.rest.RestRequest) PrettyJSON(org.neo4j.doc.server.rest.PrettyJSON) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Map(java.util.Map) Test(org.junit.Test)

Example 14 with RestRequest

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

the class ServerConfigDocIT method shouldNotGenerateWADLWhenExplicitlyDisabledInConfig.

@Test
public void shouldNotGenerateWADLWhenExplicitlyDisabledInConfig() throws IOException {
    server = server().withProperty(ServerSettings.wadl_enabled.name(), "false").usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
    server.start();
    JaxRsResponse response = new RestRequest().get("http://localhost:7474/application.wadl", MediaType.WILDCARD_TYPE);
    assertEquals(404, response.getStatus());
}
Also used : RestRequest(org.neo4j.doc.server.rest.RestRequest) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 15 with RestRequest

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

the class ServerConfigDocIT method shouldGenerateWADLWhenExplicitlyEnabledInConfig.

@Test
public void shouldGenerateWADLWhenExplicitlyEnabledInConfig() throws IOException {
    server = server().withProperty(ServerSettings.wadl_enabled.name(), "true").usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
    server.start();
    JaxRsResponse response = new RestRequest().get("http://localhost:7474/application.wadl", MediaType.WILDCARD_TYPE);
    assertEquals(200, response.getStatus());
    assertEquals("application/vnd.sun.wadl+xml", response.getHeaders().get("Content-Type").iterator().next());
    assertThat(response.getEntity(), containsString("<application xmlns=\"http://wadl.dev.java" + ".net/2009/02\">"));
}
Also used : RestRequest(org.neo4j.doc.server.rest.RestRequest) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 RestRequest (org.neo4j.doc.server.rest.RestRequest)19 JaxRsResponse (org.neo4j.doc.server.rest.JaxRsResponse)17 URI (java.net.URI)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 FunctionalTestHelper (org.neo4j.doc.server.helpers.FunctionalTestHelper)3 Documented (org.neo4j.kernel.impl.annotations.Documented)3 File (java.io.File)2 FileUtils.readTextFile (org.neo4j.io.fs.FileUtils.readTextFile)2 NeoServer (org.neo4j.server.NeoServer)2 Client (com.sun.jersey.api.client.Client)1 Map (java.util.Map)1 CommunityWebContainerBuilder (org.neo4j.doc.server.helpers.CommunityWebContainerBuilder)1 PrettyJSON (org.neo4j.doc.server.rest.PrettyJSON)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1