Search in sources :

Example 56 with JSONObject

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);
}
Also used : Random(java.util.Random) JSONObject(com.ibm.json.java.JSONObject) Topology(com.ibm.streamsx.topology.Topology) Test(org.junit.Test)

Aggregations

JSONObject (com.ibm.json.java.JSONObject)56 JSONArray (com.ibm.json.java.JSONArray)19 Topology (com.ibm.streamsx.topology.Topology)18 Test (org.junit.Test)18 TestTopology (com.ibm.streamsx.topology.test.TestTopology)14 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)6 Tester (com.ibm.streamsx.topology.tester.Tester)5 JsonObject (com.google.gson.JsonObject)4 HashMap (java.util.HashMap)4 Random (java.util.Random)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 OrderedJSONObject (com.ibm.json.java.OrderedJSONObject)2 StreamConnection (com.ibm.streams.flow.declare.StreamConnection)2 StreamSchema (com.ibm.streams.operator.StreamSchema)2 BOperatorInvocation (com.ibm.streamsx.topology.builder.BOperatorInvocation)2 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Attribute (com.ibm.streams.operator.Attribute)1