use of org.apache.apex.malhar.lib.appdata.query.serde.DataResultSnapshotSerializer in project apex-malhar by apache.
the class DataResultSnapshotSerializerTest method simpleCountdownTest.
@Test
public void simpleCountdownTest() throws Exception {
List<GPOMutable> dataValues = createValues();
DataQuerySnapshot gQuery = new DataQuerySnapshot("1", new Fields(Sets.newHashSet("a", "b")));
DataResultSnapshot result = new DataResultSnapshot(gQuery, dataValues, 2);
DataResultSnapshotSerializer serializer = new DataResultSnapshotSerializer();
String resultJSON = serializer.serialize(result, new ResultFormatter());
JSONObject rjo = new JSONObject(resultJSON);
long countdown = rjo.getLong(Result.FIELD_COUNTDOWN);
Assert.assertEquals(2, countdown);
}
use of org.apache.apex.malhar.lib.appdata.query.serde.DataResultSnapshotSerializer in project apex-malhar by apache.
the class DataResultSnapshotSerializerTest method simpleResultSerializerTest.
@Test
public void simpleResultSerializerTest() throws Exception {
List<GPOMutable> dataValues = createValues();
DataQuerySnapshot gQuery = new DataQuerySnapshot("1", new Fields(Sets.newHashSet("a", "b")));
DataResultSnapshot result = new DataResultSnapshot(gQuery, dataValues);
DataResultSnapshotSerializer serializer = new DataResultSnapshotSerializer();
final String expectedJSONResult = "{\"id\":\"1\",\"type\":\"dataResult\",\"data\":[{\"b\":\"hello\",\"a\":\"1\"}," + "{\"b\":\"world\",\"a\":\"2\"}]}";
String resultJSON = serializer.serialize(result, new ResultFormatter());
JSONObject jo = new JSONObject(expectedJSONResult);
JSONArray data = jo.getJSONArray("data");
JSONObject jo1 = data.getJSONObject(0);
JSONObject jo2 = data.getJSONObject(1);
JSONObject rjo = new JSONObject(resultJSON);
JSONArray rdata = rjo.getJSONArray("data");
JSONObject rjo1 = rdata.getJSONObject(0);
JSONObject rjo2 = rdata.getJSONObject(1);
Assert.assertFalse(rjo.has(Result.FIELD_COUNTDOWN));
Assert.assertEquals("The json doesn't match.", jo1.get("a"), rjo1.get("a"));
Assert.assertEquals("The json doesn't match.", jo1.get("b"), rjo1.get("b"));
Assert.assertEquals("The json doesn't match.", jo2.get("a"), rjo2.get("a"));
Assert.assertEquals("The json doesn't match.", jo2.get("b"), rjo2.get("b"));
Assert.assertEquals("The type doesn't match.", DataResultSnapshot.TYPE, jo.get(DataResultSnapshot.FIELD_TYPE));
}
Aggregations