Search in sources :

Example 21 with JsonNode

use of org.codehaus.jackson.JsonNode in project pinot by linkedin.

the class TenantTest method testDeserializeFromJson.

@Test
public void testDeserializeFromJson() throws JSONException, IOException {
    JSONObject json = new JSONObject();
    json.put("tenantRole", "SERVER");
    json.put("tenantName", "newTenant");
    json.put("numberOfInstances", 10);
    json.put("offlineInstances", 5);
    json.put("realtimeInstances", 5);
    json.put("keyIDontKnow", "blahblahblah");
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(json.toString());
    Tenant tenant = mapper.readValue(jsonNode, Tenant.class);
    Assert.assertEquals(5, tenant.getOfflineInstances());
    Assert.assertEquals(10, tenant.getNumberOfInstances());
    Assert.assertEquals("newTenant", tenant.getTenantName());
    Assert.assertEquals(TenantRole.SERVER, tenant.getTenantRole());
}
Also used : JSONObject(org.json.JSONObject) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Example 22 with JsonNode

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

the class JavaAggregationFunctionsTest method shouldLaunchWithDeclaredFunctions.

@Test
public void shouldLaunchWithDeclaredFunctions() throws Exception {
    // When
    try (ServerControls server = TestServerBuilders.newInProcessBuilder().withAggregationFunction(MyFunctions.class).newServer()) {
        // Then
        HTTP.Response response = HTTP.POST(server.httpURI().resolve("db/data/transaction/commit").toString(), quotedJson("{ 'statements': [ { 'statement': 'RETURN org.neo4j.harness.myFunc() AS someNumber' } ] " + "}"));
        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 23 with JsonNode

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

the class JavaFunctionsTest method shouldLaunchWithDeclaredFunctions.

@Test
public void shouldLaunchWithDeclaredFunctions() throws Exception {
    // When
    try (ServerControls server = TestServerBuilders.newInProcessBuilder().withFunction(MyFunctions.class).newServer()) {
        // Then
        HTTP.Response response = HTTP.POST(server.httpURI().resolve("db/data/transaction/commit").toString(), quotedJson("{ 'statements': [ { 'statement': 'RETURN org.neo4j.harness.myFunc() AS someNumber' } ] " + "}"));
        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 24 with JsonNode

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

the class JavaFunctionsTest method shouldWorkWithInjectableFromKernelExtension.

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

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