Search in sources :

Example 36 with JaxRsResponse

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

the class StreamingBatchOperationDocIT method shouldRollbackAllWhenGivenIncorrectRequest.

@Test
public void shouldRollbackAllWhenGivenIncorrectRequest() throws JsonParseException, ClientHandlerException, UniformInterfaceException, JSONException {
    String jsonString = new PrettyJSON().array().object().key("method").value("POST").key("to").value("/node").key("body").object().key("age").value("1").endObject().endObject().object().key("method").value("POST").key("to").value("/node").key("body").array().value("a_list").value("this_makes_no_sense").endArray().endObject().endArray().toString();
    long originalNodeCount = countNodes();
    JaxRsResponse response = RestRequest.req().accept(APPLICATION_JSON_TYPE).header(StreamingFormat.STREAM_HEADER, "true").post(batchUri(), jsonString);
    assertEquals(200, response.getStatus());
    // Message of the ClassCastException differs in Oracle JDK [typeX cannot be cast to typeY]
    // and IBM JDK [typeX incompatible with typeY]. That is why we check parts of the message and exception class.
    Map<String, String> body = (Map) singleResult(response, 1).get("body");
    assertEquals(BadInputException.class.getSimpleName(), body.get("exception"));
    assertThat(body.get("message"), containsString("java.util.ArrayList"));
    assertThat(body.get("message"), containsString("java.util.Map"));
    assertEquals(400, singleResult(response, 1).get("status"));
    assertEquals(originalNodeCount, countNodes());
}
Also used : BadInputException(org.neo4j.server.rest.repr.BadInputException) PrettyJSON(org.neo4j.doc.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Map(java.util.Map) Test(org.junit.Test)

Example 37 with JaxRsResponse

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

the class HTTPLoggingDocIT 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(), "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.doc.server.rest.RestRequest) FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) FileUtils.readTextFile(org.neo4j.io.fs.FileUtils.readTextFile) File(java.io.File) Test(org.junit.Test)

Example 38 with JaxRsResponse

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

the class HTTPLoggingDocIT method givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesses.

@Test
public void givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesses() throws Exception {
    // given
    String directoryPrefix = testName.getMethodName();
    File logDirectory = testDirectory.directory(directoryPrefix + "-logdir");
    FileUtils.forceMkdir(logDirectory);
    final File confDir = testDirectory.directory(directoryPrefix + "-confdir");
    FileUtils.forceMkdir(confDir);
    NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withProperty(ServerSettings.http_logging_enabled.name(), "false").withProperty(GraphDatabaseSettings.logs_directory.name(), logDirectory.toString()).usingDataDir(testDirectory.directory(directoryPrefix + "-dbdir").getAbsolutePath()).build();
    try {
        server.start();
        FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper(server);
        // when
        String query = "?implicitlyDisabled" + randomString();
        JaxRsResponse response = new RestRequest().get(functionalTestHelper.managementUri() + query);
        assertThat(response.getStatus(), is(200));
        response.close();
        // then
        File httpLog = new File(logDirectory, "http.log");
        assertThat(httpLog.exists(), is(false));
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) RestRequest(org.neo4j.doc.server.rest.RestRequest) FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) FileUtils.readTextFile(org.neo4j.io.fs.FileUtils.readTextFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)38 JaxRsResponse (org.neo4j.doc.server.rest.JaxRsResponse)38 RestRequest (org.neo4j.doc.server.rest.RestRequest)17 Matchers.containsString (org.hamcrest.Matchers.containsString)16 FunctionalTestHelper (org.neo4j.doc.server.helpers.FunctionalTestHelper)9 PrettyJSON (org.neo4j.doc.server.rest.PrettyJSON)8 Documented (org.neo4j.kernel.impl.annotations.Documented)6 URI (java.net.URI)4 Map (java.util.Map)4 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 Client (com.sun.jersey.api.client.Client)1 CommunityWebContainerBuilder (org.neo4j.doc.server.helpers.CommunityWebContainerBuilder)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1 BadInputException (org.neo4j.server.rest.repr.BadInputException)1