Search in sources :

Example 41 with JsonNode

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

the class JavaProceduresTest method shouldLaunchWithDeclaredProcedures.

@Test
public void shouldLaunchWithDeclaredProcedures() throws Exception {
    // When
    try (ServerControls server = TestServerBuilders.newInProcessBuilder().withProcedure(MyProcedures.class).newServer()) {
        // Then
        HTTP.Response response = HTTP.POST(server.httpURI().resolve("db/data/transaction/commit").toString(), quotedJson("{ 'statements': [ { 'statement': 'CALL org.neo4j.harness.myProc' } ] }"));
        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 42 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 43 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 44 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 45 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)

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