Search in sources :

Example 36 with JsonNode

use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.

the class ExceptionRepresentationTest method shouldRenderErrorsWithNeo4jStatusCode.

@Test
public void shouldRenderErrorsWithNeo4jStatusCode() throws Exception {
    // Given
    ExceptionRepresentation rep = new ExceptionRepresentation(new KernelException(UnknownError, "Hello") {
    });
    // When
    JsonNode out = serialize(rep);
    // Then
    assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError"));
    assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello"));
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) KernelException(org.neo4j.kernel.api.exceptions.KernelException) Test(org.junit.Test)

Example 37 with JsonNode

use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.

the class ExceptionRepresentationTest method shoudExcludeLegacyFormatIfAsked.

@Test
public void shoudExcludeLegacyFormatIfAsked() throws Exception {
    // Given
    ExceptionRepresentation rep = new ExceptionRepresentation(new KernelException(UnknownError, "Hello") {
    }, /*legacy*/
    false);
    // When
    JsonNode out = serialize(rep);
    // Then
    assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError"));
    assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello"));
    assertThat(out.has("message"), equalTo(false));
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) KernelException(org.neo4j.kernel.api.exceptions.KernelException) Test(org.junit.Test)

Example 38 with JsonNode

use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.

the class JavaAggregationFunctionsTest method shouldLaunchWithDeclaredFunctions.

@Test
public void shouldLaunchWithDeclaredFunctions() throws Exception {
    // When
    try (ServerControls server = TestServerBuilders.newInProcessBuilder().withAggregationFunction(MyFunctions.class).newServer()) {
        // Then
        HTTP.Response response = HTTP.POST(server.httpURI().resolve("db/data/transaction/commit").toString(), quotedJson("{ 'statements': [ { 'statement': 'RETURN org.neo4j.harness.myFunc() AS someNumber' } ] " + "}"));
        JsonNode result = response.get("results").get(0);
        assertEquals("someNumber", result.get("columns").get(0).asText());
        assertEquals(1337, result.get("data").get(0).get("row").get(0).asInt());
        assertEquals("[]", response.get("errors").toString());
    }
}
Also used : HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 39 with JsonNode

use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.

the class JavaFunctionsTest method shouldLaunchWithDeclaredFunctions.

@Test
public void shouldLaunchWithDeclaredFunctions() throws Exception {
    // When
    try (ServerControls server = TestServerBuilders.newInProcessBuilder().withFunction(MyFunctions.class).newServer()) {
        // Then
        HTTP.Response response = HTTP.POST(server.httpURI().resolve("db/data/transaction/commit").toString(), quotedJson("{ 'statements': [ { 'statement': 'RETURN org.neo4j.harness.myFunc() AS someNumber' } ] " + "}"));
        JsonNode result = response.get("results").get(0);
        assertEquals("someNumber", result.get("columns").get(0).asText());
        assertEquals(1337, result.get("data").get(0).get("row").get(0).asInt());
        assertEquals("[]", response.get("errors").toString());
    }
}
Also used : HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 40 with JsonNode

use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.

the class JavaFunctionsTest method shouldWorkWithInjectableFromKernelExtension.

@Test
public void shouldWorkWithInjectableFromKernelExtension() throws Throwable {
    // When
    try (ServerControls server = TestServerBuilders.newInProcessBuilder().withFunction(MyFunctionsUsingMyService.class).newServer()) {
        // Then
        HTTP.Response response = HTTP.POST(server.httpURI().resolve("db/data/transaction/commit").toString(), quotedJson("{ 'statements': [ { 'statement': 'RETURN my.hello() AS result' } ] }"));
        assertEquals("[]", response.get("errors").toString());
        JsonNode result = response.get("results").get(0);
        assertEquals("result", result.get("columns").get(0).asText());
        assertEquals("world", result.get("data").get(0).get("row").get(0).asText());
    }
}
Also used : HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Aggregations

JsonNode (org.codehaus.jackson.JsonNode)200 Test (org.junit.Test)55 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)50 IOException (java.io.IOException)40 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 HTTP (org.neo4j.test.server.HTTP)18 Resource (com.netflix.simianarmy.Resource)17 AWSResource (com.netflix.simianarmy.aws.AWSResource)17 ObjectNode (org.codehaus.jackson.node.ObjectNode)15 Response (org.neo4j.test.server.HTTP.Response)12 Map (java.util.Map)9 ArrayNode (org.codehaus.jackson.node.ArrayNode)9 RpcException (cz.metacentrum.perun.core.api.exceptions.RpcException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)7 Date (java.util.Date)6 List (java.util.List)6 Description (org.hamcrest.Description)6 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)6