Search in sources :

Example 51 with JsonNode

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);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 52 with JsonNode

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));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 53 with JsonNode

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)));
    });
}
Also used : Response(org.neo4j.test.server.HTTP.Response) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 54 with JsonNode

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"));
}
Also used : HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 55 with JsonNode

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();
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(org.codehaus.jackson.JsonGenerator) JsonNode(org.codehaus.jackson.JsonNode)

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