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());
}
}
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());
}
}
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));
}
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) {
}
};
}
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) {
}
};
}
Aggregations