Search in sources :

Example 1 with TestObjAllTypes

use of org.apache.apex.malhar.lib.util.TestObjAllTypes in project apex-malhar by apache.

the class AppDataSnapshotServerPojoTest method simpleTest.

@Test
public void simpleTest() throws Exception {
    String query = SchemaUtils.jarResourceFileToString("snapshotServerPojoQuery.json");
    String schema = SchemaUtils.jarResourceFileToString("snapshotServerPojoSchema.json");
    TestObjAllTypes objAllTypes = new TestObjAllTypes();
    Map<String, String> fieldToGetter = Maps.newHashMap();
    fieldToGetter.put("stringType", "getInnerObj().stringVal");
    fieldToGetter.put("charType", "getInnerObj().charVal");
    fieldToGetter.put("booleanType", "getInnerObj().boolVal");
    fieldToGetter.put("longType", "getInnerObj().longVal");
    fieldToGetter.put("integerType", "getInnerObj().intVal");
    fieldToGetter.put("shortType", "getInnerObj().shortVal");
    fieldToGetter.put("byteType", "getInnerObj().byteVal");
    fieldToGetter.put("floatType", "getInnerObj().floatVal");
    fieldToGetter.put("doubleType", "getInnerObj().doubleVal");
    AppDataSnapshotServerPOJO snapshotServer = new AppDataSnapshotServerPOJO();
    snapshotServer.setFieldToGetter(fieldToGetter);
    snapshotServer.setSnapshotSchemaJSON(schema);
    CollectorTestSink<String> resultSink = new CollectorTestSink<String>();
    TestUtils.setSink(snapshotServer.queryResult, resultSink);
    List<Object> inputList = Lists.newArrayList();
    inputList.add(objAllTypes);
    snapshotServer.setup(null);
    snapshotServer.beginWindow(0L);
    snapshotServer.input.put(inputList);
    snapshotServer.query.put(query);
    snapshotServer.endWindow();
    Assert.assertEquals(1, resultSink.collectedTuples.size());
    String result = resultSink.collectedTuples.get(0);
    JSONObject data = new JSONObject(result).getJSONArray(DataQuerySnapshot.FIELD_DATA).getJSONObject(0);
    Assert.assertEquals(objAllTypes.getInnerObj().stringVal, data.get("stringType"));
    Assert.assertEquals(Character.toString(objAllTypes.getInnerObj().charVal), data.get("charType"));
    Assert.assertEquals(Boolean.toString(objAllTypes.getInnerObj().boolVal), Boolean.toString((Boolean) data.get("booleanType")));
    Assert.assertEquals(Long.toString(objAllTypes.getInnerObj().longVal), data.get("longType"));
    Assert.assertEquals(Integer.toString(objAllTypes.getInnerObj().intVal), data.get("integerType"));
    Assert.assertEquals(Short.toString(objAllTypes.getInnerObj().shortVal), data.get("shortType"));
    Assert.assertEquals(Byte.toString(objAllTypes.getInnerObj().byteVal), data.get("byteType"));
    Assert.assertEquals(Float.toString(objAllTypes.getInnerObj().floatVal), data.get("floatType"));
    Assert.assertEquals(Double.toString(objAllTypes.getInnerObj().doubleVal), data.get("doubleType"));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONObject(org.codehaus.jettison.json.JSONObject) TestObjAllTypes(org.apache.apex.malhar.lib.util.TestObjAllTypes) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Aggregations

CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)1 TestObjAllTypes (org.apache.apex.malhar.lib.util.TestObjAllTypes)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 Test (org.junit.Test)1