use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class PublishSubscribeJsonPythonTest method testPublishJsonFilter.
/**
* Json Subscribe feeding a filter
*/
@Test
public void testPublishJsonFilter() throws Exception {
Random r = new Random();
final Topology t = new Topology();
includePythonApp(t, "json_filter_json.py", "json_filter_json::json_filter_json");
JSONObject j1 = new JSONObject();
j1.put("a", 23523L);
j1.put("b", "Hello:" + r.nextInt(200));
JSONObject j2 = new JSONObject();
j2.put("a", 7L);
j2.put("b", "Goodbye:" + r.nextInt(200));
JSONObject j3 = new JSONObject();
j3.put("a", 101L);
j3.put("b", "So long:" + r.nextInt(200));
String s2 = "R" + j2.get("a") + "X" + j2.get("b");
TStream<JSONObject> source = t.constants(Arrays.asList(j1, j2, j3));
source = addStartupDelay(source).asType(JSONObject.class);
source.publish("pytest/json/filter");
TStream<JSONObject> subscribe = t.subscribe("pytest/json/filter/result", JSONObject.class);
TStream<String> asString = subscribe.transform(j -> "R" + j.get("a") + "X" + j.get("b"));
completeAndValidate(asString, 30, s2);
}
Aggregations