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