Search in sources :

Example 21 with JaxRsResponse

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

the class BatchOperationHeaderIT 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.server.rest.RestRequest) PrettyJSON(org.neo4j.server.rest.PrettyJSON) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Map(java.util.Map) Test(org.junit.Test)

Example 22 with JaxRsResponse

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

the class BoltIT method boltPortShouldComeFromConfigButHostShouldMatchHttpHostHeaderWhenConfigIsLocalhostOrEmptyEvenThoughThisIsMorallyHazardous.

@Test
public void boltPortShouldComeFromConfigButHostShouldMatchHttpHostHeaderWhenConfigIsLocalhostOrEmptyEvenThoughThisIsMorallyHazardous() throws Throwable {
    // Given
    String host = "neo4j.com";
    startServerWithBoltEnabled("localhost", 9999, "localhost", 7687);
    RestRequest request = new RestRequest(server.baseUri()).host(host);
    // When
    JaxRsResponse response = request.get();
    // Then
    Map<String, Object> map = JsonHelper.jsonToMap(response.getEntity());
    assertThat(String.valueOf(map.get("bolt")), containsString("bolt://" + host + ":9999"));
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 23 with JaxRsResponse

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

the class ServerConfigIT method shouldPickUpAddressFromConfig.

@Test
public void shouldPickUpAddressFromConfig() throws Exception {
    ListenSocketAddress nonDefaultAddress = new ListenSocketAddress("0.0.0.0", 4321);
    server = server().onAddress(nonDefaultAddress).usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
    server.start();
    assertEquals(nonDefaultAddress, server.getAddress());
    JaxRsResponse response = new RestRequest(server.baseUri()).get();
    assertThat(response.getStatus(), is(200));
    response.close();
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 24 with JaxRsResponse

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

the class ServerConfigIT method shouldHaveSandboxingEnabledByDefault.

@Test
public void shouldHaveSandboxingEnabledByDefault() throws Exception {
    // Given
    server = server().usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
    server.start();
    String node = POST(server.baseUri().toASCIIString() + "db/data/node").location();
    // When
    JaxRsResponse response = new RestRequest().post(node + "/traverse/node", "{\n" + "  \"order\" : \"breadth_first\",\n" + "  \"return_filter\" : {\n" + "    \"body\" : \"position.getClass().getClassLoader()\",\n" + "    \"language\" : \"javascript\"\n" + "  },\n" + "  \"prune_evaluator\" : {\n" + "    \"body\" : \"position.getClass().getClassLoader()\",\n" + "    \"language\" : \"javascript\"\n" + "  },\n" + "  \"uniqueness\" : \"node_global\",\n" + "  \"relationships\" : [ {\n" + "    \"direction\" : \"all\",\n" + "    \"type\" : \"knows\"\n" + "  }, {\n" + "    \"direction\" : \"all\",\n" + "    \"type\" : \"loves\"\n" + "  } ],\n" + "  \"max_depth\" : 3\n" + "}", MediaType.APPLICATION_JSON_TYPE);
    // Then
    assertEquals(400, response.getStatus());
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 25 with JaxRsResponse

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

the class ServerConfigIT 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.server.rest.RestRequest) 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