Search in sources :

Example 86 with JsonNode

use of org.codehaus.jackson.JsonNode in project apex-malhar by apache.

the class CouchDBOutputOperatorTest method testCouchDBOutputOperator.

@Test
public void testCouchDBOutputOperator() throws MalformedURLException {
    String testDocumentId = "TestDocument";
    Map<Object, Object> tuple = Maps.newHashMap();
    tuple.put("_id", testDocumentId);
    tuple.put("name", "TD");
    tuple.put("type", "test");
    MapBasedCouchDbOutputOperator dbOutputOper = new MapBasedCouchDbOutputOperator();
    CouchDbStore store = new CouchDbStore();
    store.setDbName(CouchDBTestHelper.TEST_DB);
    dbOutputOper.setStore(store);
    dbOutputOper.setup(mockOperatorContext(1));
    dbOutputOper.beginWindow(0);
    dbOutputOper.input.process(tuple);
    dbOutputOper.endWindow();
    tuple.put("output-type", "map");
    dbOutputOper.beginWindow(1);
    dbOutputOper.input.process(tuple);
    dbOutputOper.endWindow();
    // Test if the document was persisted
    JsonNode docNode = CouchDBTestHelper.fetchDocument(testDocumentId);
    Assert.assertNotNull("Document saved", docNode);
    Assert.assertEquals("name of document", "TD", docNode.get("name").getTextValue());
    Assert.assertEquals("type of document", "test", docNode.get("type").getTextValue());
    Assert.assertEquals("output-type", "map", docNode.get("output-type").getTextValue());
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 87 with JsonNode

use of org.codehaus.jackson.JsonNode in project apex-malhar by apache.

the class CouchDBOutputOperatorTest method testCouchDBPOJOOutputOperator.

@Test
public void testCouchDBPOJOOutputOperator() {
    String testDocumentId = "test2";
    TestPOJO tuple = new TestPOJO();
    tuple.setId(testDocumentId);
    tuple.setName("TD2");
    tuple.setType("test2");
    tuple.setCh('x');
    tuple.setFl(2.0f);
    tuple.setOutput_type("pojo");
    Address address = new Address();
    address.setCity("chandigarh");
    address.setHousenumber(123);
    tuple.setAddress(address);
    CouchDBPOJOOutputOperator dbOutputOper = new CouchDBPOJOOutputOperator();
    CouchDbStore store = new CouchDbStore();
    store.setDbName(CouchDBTestHelper.TEST_DB);
    dbOutputOper.setStore(store);
    String expression = "getId()";
    dbOutputOper.setExpressionForDocId(expression);
    dbOutputOper.setup(mockOperatorContext(1));
    dbOutputOper.beginWindow(0);
    dbOutputOper.input.process(tuple);
    dbOutputOper.endWindow();
    // Test if the document was persisted
    JsonNode docNode = CouchDBTestHelper.fetchDocument(testDocumentId);
    Assert.assertNotNull("Document saved ", docNode);
    Assert.assertEquals("name of document ", "TD2", docNode.get("name").getTextValue());
    Assert.assertEquals("type of document ", "test2", docNode.get("type").getTextValue());
    Assert.assertEquals("character ", "x", docNode.get("ch").getTextValue());
    Assert.assertEquals("float value ", 2.0, docNode.get("fl").getDoubleValue());
    Assert.assertEquals("output-type", "pojo", docNode.get("output_type").getTextValue());
    Assert.assertEquals("Housenumber is ", 123, docNode.get("address").get("housenumber").getIntValue());
    Assert.assertEquals("City is ", "chandigarh", docNode.get("address").get("city").getTextValue());
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 88 with JsonNode

use of org.codehaus.jackson.JsonNode in project hive by apache.

the class TestJsonRPFormatter method testJsonEmptyRPFormatter.

@Test
public void testJsonEmptyRPFormatter() throws Exception {
    WMFullResourcePlan fullRp = createRP("test_rp_1", null, null);
    formatter.showFullResourcePlan(out, fullRp);
    out.flush();
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode jsonTree = objectMapper.readTree(bos.toByteArray());
    assertNotNull(jsonTree);
    assertTrue(jsonTree.isObject());
    assertEquals("test_rp_1", jsonTree.get("name").asText());
    assertTrue(jsonTree.get("parallelism").isNull());
    assertTrue(jsonTree.get("defaultPool").isNull());
    assertTrue(jsonTree.get("pools").isArray());
    assertEquals(0, jsonTree.get("pools").size());
}
Also used : WMFullResourcePlan(org.apache.hadoop.hive.metastore.api.WMFullResourcePlan) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 89 with JsonNode

use of org.codehaus.jackson.JsonNode in project hive by apache.

the class TestJsonRPFormatter method testJsonRPFormatter.

@Test
public void testJsonRPFormatter() throws Exception {
    WMFullResourcePlan fullRp = createRP("test_rp_2", 10, "def");
    addPool(fullRp, "pool1", 0.3, 3, "fair");
    addTrigger(fullRp, "trigger1", "KILL", "BYTES > 2", "pool1");
    addPool(fullRp, "pool2", 0.7, 7, "fcfs");
    addMapping(fullRp, "user", "foo", "pool2");
    addMapping(fullRp, "user", "bar", "pool2");
    formatter.showFullResourcePlan(out, fullRp);
    out.flush();
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode jsonTree = objectMapper.readTree(bos.toByteArray());
    assertNotNull(jsonTree);
    assertTrue(jsonTree.isObject());
    assertEquals("test_rp_2", jsonTree.get("name").asText());
    assertEquals(10, jsonTree.get("parallelism").asInt());
    assertEquals("def", jsonTree.get("defaultPool").asText());
    assertTrue(jsonTree.get("pools").isArray());
    assertEquals(2, jsonTree.get("pools").size());
    JsonNode pool2 = jsonTree.get("pools").get(0);
    assertEquals("pool2", pool2.get("name").asText());
    assertEquals("fcfs", pool2.get("schedulingPolicy").asText());
    assertEquals(7, pool2.get("parallelism").asInt());
    assertEquals(0.7, pool2.get("allocFraction").asDouble(), 0.00001);
    assertTrue(pool2.get("triggers").isArray());
    assertEquals(0, pool2.get("triggers").size());
    assertTrue(pool2.get("mappings").isArray());
    JsonNode type0 = pool2.get("mappings").get(0);
    assertEquals("user", type0.get("type").asText());
    assertTrue(type0.get("values").isArray());
    assertEquals(2, type0.get("values").size());
    HashSet<String> vals = new HashSet<>();
    for (int i = 0; i < type0.get("values").size(); ++i) {
        vals.add(type0.get("values").get(i).asText());
    }
    assertTrue(vals.contains("foo"));
    assertTrue(vals.contains("bar"));
    JsonNode pool1 = jsonTree.get("pools").get(1);
    assertEquals("pool1", pool1.get("name").asText());
    assertEquals("fair", pool1.get("schedulingPolicy").asText());
    assertEquals(3, pool1.get("parallelism").asInt());
    assertEquals(0.3, pool1.get("allocFraction").asDouble(), 0.00001);
    assertTrue(pool1.get("triggers").isArray());
    assertEquals(1, pool1.get("triggers").size());
    JsonNode trigger1 = pool1.get("triggers").get(0);
    assertEquals("trigger1", trigger1.get("name").asText());
    assertEquals("KILL", trigger1.get("action").asText());
    assertEquals("BYTES > 2", trigger1.get("trigger").asText());
}
Also used : WMFullResourcePlan(org.apache.hadoop.hive.metastore.api.WMFullResourcePlan) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 90 with JsonNode

use of org.codehaus.jackson.JsonNode in project perun by CESNET.

the class JsonDeserializer method readArrayOfInts.

@Override
public int[] readArrayOfInts(String name) throws RpcException {
    JsonNode node;
    if (name == null) {
        // The object is not under root, but directly in the response
        node = root;
    } else {
        node = root.get(name);
    }
    if (node.isNull()) {
        return null;
    }
    if (!node.isArray()) {
        throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as int[] - not an array");
    }
    int[] array = new int[node.size()];
    for (int i = 0; i < node.size(); ++i) {
        JsonNode value = node.get(i);
        if (!value.isInt()) {
            throw new RpcException(RpcException.Type.CANNOT_DESERIALIZE_VALUE, node.toString() + " as int");
        }
        array[i] = node.get(i).getIntValue();
    }
    return array;
}
Also used : RpcException(cz.metacentrum.perun.core.api.exceptions.RpcException) 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