Search in sources :

Example 26 with JsonNode

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

the class JavaProceduresTest method shouldWorkWithInjectableFromKernelExtension.

@Test
public void shouldWorkWithInjectableFromKernelExtension() throws Throwable {
    // When
    try (ServerControls server = TestServerBuilders.newInProcessBuilder().withProcedure(MyProceduresUsingMyService.class).newServer()) {
        // Then
        HTTP.Response response = HTTP.POST(server.httpURI().resolve("db/data/transaction/commit").toString(), quotedJson("{ 'statements': [ { 'statement': 'CALL hello' } ] }"));
        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)

Example 27 with JsonNode

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

the class TransactionIT method shouldSerializeMapsCorrectlyInRowsFormat.

@Test
public void shouldSerializeMapsCorrectlyInRowsFormat() throws Exception {
    Response response = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'RETURN {one:{two:[true, {three: 42}]}}' } ] }"));
    // then
    assertThat(response.status(), equalTo(200));
    JsonNode data = response.get("results").get(0);
    JsonNode row = data.get("data").get(0).get("row");
    assertThat(row.size(), equalTo(1));
    JsonNode firstCell = row.get(0);
    assertThat(firstCell.get("one").get("two").size(), is(2));
    assertThat(firstCell.get("one").get("two").get(0).asBoolean(), is(true));
    assertThat(firstCell.get("one").get("two").get(1).get("three").asInt(), is(42));
    assertThat(response.get("errors").size(), equalTo(0));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 28 with JsonNode

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

the class TransactionMatchers method rowContainsDeletedEntities.

public static Matcher<? super HTTP.Response> rowContainsDeletedEntities(final int nodes, final int rels) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> meta = getJsonNodeWithName(response, "meta").iterator();
                int nodeCounter = 0;
                int relCounter = 0;
                for (int i = 0; i < nodes + rels; ++i) {
                    assertTrue(meta.hasNext());
                    JsonNode node = meta.next();
                    assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                    String type = node.get("type").getTextValue();
                    switch(type) {
                        case "node":
                            ++nodeCounter;
                            break;
                        case "relationship":
                            ++relCounter;
                            break;
                        default:
                            fail("Unexpected type: " + type);
                            break;
                    }
                }
                assertEquals(nodes, nodeCounter);
                assertEquals(rels, relCounter);
                while (meta.hasNext()) {
                    JsonNode node = meta.next();
                    assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.FALSE));
                }
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.neo4j.server.rest.domain.JsonParseException)

Example 29 with JsonNode

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

the class TransactionMatchers method graphContainsDeletedRelationships.

public static Matcher<? super HTTP.Response> graphContainsDeletedRelationships(final int amount) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> relationships = getJsonNodeWithName(response, "graph").get("relationships").iterator();
                for (int i = 0; i < amount; ++i) {
                    assertTrue(relationships.hasNext());
                    JsonNode node = relationships.next();
                    assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                }
                if (relationships.hasNext()) {
                    JsonNode node = relationships.next();
                    fail("Expected no more nodes, but got a node with id " + node.get("id"));
                }
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.neo4j.server.rest.domain.JsonParseException)

Example 30 with JsonNode

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

the class TransactionMatchers method hasErrors.

public static Matcher<? super HTTP.Response> hasErrors(final Status... expectedErrors) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> errors = response.get("errors").iterator();
                Iterator<Status> expected = iterator(expectedErrors);
                while (expected.hasNext()) {
                    assertTrue(errors.hasNext());
                    assertThat(errors.next().get("code").asText(), equalTo(expected.next().code().serialize()));
                }
                if (errors.hasNext()) {
                    JsonNode error = errors.next();
                    fail("Expected no more errors, but got " + error.get("code") + " - '" + error.get("message") + "'.");
                }
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.neo4j.server.rest.domain.JsonParseException)

Aggregations

JsonNode (org.codehaus.jackson.JsonNode)191 Test (org.junit.Test)51 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)47 IOException (java.io.IOException)39 HashMap (java.util.HashMap)20 ArrayList (java.util.ArrayList)19 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)14 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