Search in sources :

Example 1 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 2 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 3 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)

Example 4 with JaxRsResponse

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

the class ServerConfigIT method shouldNotGenerateWADLWhenNotExplicitlyEnabledInConfig.

@Test
public void shouldNotGenerateWADLWhenNotExplicitlyEnabledInConfig() throws IOException {
    server = server().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.server.rest.RestRequest) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 5 with JaxRsResponse

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

the class HTTPLoggingIT method givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess.

@Test
public void givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess() throws Exception {
    // given
    String directoryPrefix = testName.getMethodName();
    File logDirectory = testDirectory.directory(directoryPrefix + "-logdir");
    final String query = "?explicitlyEnabled=" + randomString();
    NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning().persistent().withProperty(ServerSettings.http_logging_enabled.name(), Settings.TRUE).withProperty(GraphDatabaseSettings.logs_directory.name(), logDirectory.getAbsolutePath()).usingDataDir(testDirectory.directory(directoryPrefix + "-dbdir").getAbsolutePath()).build();
    try {
        server.start();
        FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper(server);
        // when
        JaxRsResponse response = new RestRequest().get(functionalTestHelper.managementUri() + query);
        assertThat(response.getStatus(), is(HttpStatus.SC_OK));
        response.close();
        // then
        File httpLog = new File(logDirectory, "http.log");
        assertEventually("request appears in log", fileContentSupplier(httpLog), containsString(query), 5, TimeUnit.SECONDS);
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) RestRequest(org.neo4j.server.rest.RestRequest) FunctionalTestHelper(org.neo4j.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) FileUtils.readTextFile(org.neo4j.io.fs.FileUtils.readTextFile) File(java.io.File) 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