use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.
the class TransactionIT method restFormattedNodesShouldHaveSensibleUrisWhenUsingXForwardHeader.
@Test
public void restFormattedNodesShouldHaveSensibleUrisWhenUsingXForwardHeader() throws Throwable {
// given
final String hostname = "dummy.example.org";
final String scheme = "http";
// when
Response rs = http.withHeaders(XForwardUtil.X_FORWARD_HOST_HEADER_KEY, hostname).POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'CREATE (n:Foo:Bar) RETURN n', " + "'resultDataContents':['rest'] } ] }"));
// then
JsonNode restNode = rs.get("results").get(0).get("data").get(0).get("rest").get(0);
assertPath(restNode.get("labels"), "/node/\\d+/labels", hostname, scheme);
assertPath(restNode.get("outgoing_relationships"), "/node/\\d+/relationships/out", hostname, scheme);
assertPath(restNode.get("traverse"), "/node/\\d+/traverse/\\{returnType\\}", hostname, scheme);
assertPath(restNode.get("all_typed_relationships"), "/node/\\d+/relationships/all/\\{-list\\|&\\|types\\}", hostname, scheme);
assertPath(restNode.get("self"), "/node/\\d+", hostname, scheme);
assertPath(restNode.get("property"), "/node/\\d+/properties/\\{key\\}", hostname, scheme);
assertPath(restNode.get("properties"), "/node/\\d+/properties", hostname, scheme);
assertPath(restNode.get("outgoing_typed_relationships"), "/node/\\d+/relationships/out/\\{-list\\|&\\|types\\}", hostname, scheme);
assertPath(restNode.get("incoming_relationships"), "/node/\\d+/relationships/in", hostname, scheme);
assertPath(restNode.get("create_relationship"), "/node/\\d+/relationships", hostname, scheme);
assertPath(restNode.get("paged_traverse"), "/node/\\d+/paged/traverse/\\{returnType\\}\\{\\?pageSize," + "leaseTime\\}", hostname, scheme);
assertPath(restNode.get("all_relationships"), "/node/\\d+/relationships/all", hostname, scheme);
assertPath(restNode.get("incoming_typed_relationships"), "/node/\\d+/relationships/in/\\{-list\\|&\\|types\\}", hostname, scheme);
}
use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.
the class TransactionIT method begin_create_two_nodes_delete_one.
@Test
public void begin_create_two_nodes_delete_one() throws Exception {
/*
* This issue was reported from the community. It resulted in a refactoring of the interaction
* between TxManager and TransactionContexts.
*/
// GIVEN
long nodesInDatabaseBeforeTransaction = countNodes();
Response response = http.POST("/db/data/transaction/commit", rawPayload("{ \"statements\" : [{\"statement\" : \"CREATE (n0:DecibelEntity :AlbumGroup{DecibelID : " + "'34a2201b-f4a9-420f-87ae-00a9c691cc5c', Title : 'Dance With Me', " + "ArtistString : 'Ra Ra Riot', MainArtistAlias : 'Ra Ra Riot', " + "OriginalReleaseDate : '2013-01-08', IsCanon : 'False'}) return id(n0)\"}, " + "{\"statement\" : \"CREATE (n1:DecibelEntity :AlbumRelease{DecibelID : " + "'9ed529fa-7c19-11e2-be78-bcaec5bea3c3', Title : 'Dance With Me', " + "ArtistString : 'Ra Ra Riot', MainArtistAlias : 'Ra Ra Riot', LabelName : 'Barsuk " + "Records', " + "FormatNames : 'File', TrackCount : '3', MediaCount : '1', Duration : '460.000000', " + "ReleaseDate : '2013-01-08', ReleaseYear : '2013', ReleaseRegion : 'USA', " + "Cline : 'Barsuk Records', Pline : 'Barsuk Records', CYear : '2013', PYear : '2013', " + "ParentalAdvisory : 'False', IsLimitedEdition : 'False'}) return id(n1)\"}]}"));
assertEquals(200, response.status());
JsonNode everything = jsonNode(response.rawContent());
JsonNode result = everything.get("results").get(0);
long id = result.get("data").get(0).get("row").get(0).getLongValue();
// WHEN
http.POST("/db/data/cypher", rawPayload("{\"query\":\"match (n) where id(n) = " + id + " delete n\"}"));
// THEN
assertThat(countNodes(), equalTo(nodesInDatabaseBeforeTransaction + 1));
}
use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.
the class TransactionIT method begin_and_execute_periodic_commit_that_returns_data_and_commit.
@Test
public void begin_and_execute_periodic_commit_that_returns_data_and_commit() throws Exception {
int nodes = 11;
int batch = 2;
ServerTestUtils.withCSVFile(nodes, url -> {
long nodesInDatabaseBeforeTransaction = countNodes();
long txIdBefore = resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
Response response = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'USING PERIODIC COMMIT " + batch + " LOAD CSV FROM \\\"" + url + "\\\" AS line CREATE (n {id: 23}) RETURN n' } ] }"));
long txIdAfter = resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
assertThat(response.status(), equalTo(200));
assertThat(response, containsNoErrors());
JsonNode columns = response.get("results").get(0).get("columns");
assertThat(columns.toString(), equalTo("[\"n\"]"));
assertThat(countNodes(), equalTo(nodesInDatabaseBeforeTransaction + nodes));
assertThat(txIdAfter, equalTo(txIdBefore + ((nodes / batch) + 1)));
});
}
use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.
the class ReadOnlyIT method shouldReturnReadOnlyStatusWhenCreatingNodesWhichTransitivelyCreateTokens.
@Test
public void shouldReturnReadOnlyStatusWhenCreatingNodesWhichTransitivelyCreateTokens() throws Exception {
// Given
// When
HTTP.Response response = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'CREATE (node:Node)' } ] }"));
// Then
JsonNode error = response.get("errors").get(0);
String code = error.get("code").asText();
String message = error.get("message").asText();
assertEquals("Neo.ClientError.General.ForbiddenOnReadOnlyDatabase", code);
assertThat(message, containsString("This is a read only Neo4j instance"));
}
use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.
the class BatchOperations method readBody.
private String readBody(JsonParser jp) throws IOException {
JsonNode node = mapper.readTree(jp);
StringWriter out = new StringWriter();
JsonGenerator gen = jsonFactory.createJsonGenerator(out);
mapper.writeTree(gen, node);
gen.flush();
gen.close();
return out.toString();
}
Aggregations