Search in sources :

Example 1 with XML

use of com.ibm.streams.operator.types.XML in project streamsx.topology by IBMStreams.

the class XMLTupleTest method testConstant.

@Test
public void testConstant() throws Exception {
    final Topology topology = newTopology();
    String sdata = "<book><title>Dracula</title><author>Bram Stoker</author></book>";
    byte[] data = sdata.getBytes(StandardCharsets.UTF_8);
    XML xml = ValueFactory.newXML(new ByteArrayInputStream(data));
    TStream<XML> source = topology.constants(Collections.singletonList(xml)).asType(XML.class);
    assertNotNull(source);
    assertEquals(XML.class, source.getTupleClass());
    TStream<String> out = convertXMLToString(source);
    completeAndValidate(out, 10, sdata);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XML(com.ibm.streams.operator.types.XML) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 2 with XML

use of com.ibm.streams.operator.types.XML in project streamsx.topology by IBMStreams.

the class PublishSubscribeTest method testPublishXML.

@Test
public void testPublishXML() throws Exception {
    TStream<String> source = source();
    source = source.transform(s -> "<a>" + s + "</a>");
    TStream<XML> xml = source.transform(v -> {
        try {
            return ValueFactory.newXML(new ByteArrayInputStream(v.getBytes(StandardCharsets.UTF_8)));
        } catch (IOException e) {
            return null;
        }
    }).asType(XML.class);
    xml.publish("testPublishXML");
    TStream<XML> subscribe = source.topology().subscribe("testPublishXML", XML.class);
    TStream<String> strings = subscribe.transform(v -> {
        byte[] data = new byte[100];
        InputStream in = v.getInputStream();
        int read;
        try {
            read = in.read(data);
        } catch (IOException e) {
            return null;
        }
        return new String(data, 0, read, StandardCharsets.UTF_8);
    });
    strings = strings.transform(s -> s.substring(3, s.length() - 4));
    checkSubscribedAsStrings(strings);
}
Also used : TStream(com.ibm.streamsx.topology.TStream) StringStreams(com.ibm.streamsx.topology.streams.StringStreams) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) ArrayList(java.util.ArrayList) XML(com.ibm.streams.operator.types.XML) ByteArrayInputStream(java.io.ByteArrayInputStream) SPLSchemas(com.ibm.streamsx.topology.spl.SPLSchemas) Type(com.ibm.streamsx.topology.context.StreamsContext.Type) Before(org.junit.Before) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) Assert.assertFalse(org.junit.Assert.assertFalse) JSONObject(com.ibm.json.java.JSONObject) Condition(com.ibm.streamsx.topology.tester.Condition) SPLStreams(com.ibm.streamsx.topology.spl.SPLStreams) Assume.assumeTrue(org.junit.Assume.assumeTrue) Blob(com.ibm.streams.operator.types.Blob) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ValueFactory(com.ibm.streams.operator.types.ValueFactory) TestTopology(com.ibm.streamsx.topology.test.TestTopology) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) XML(com.ibm.streams.operator.types.XML) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with XML

use of com.ibm.streams.operator.types.XML in project streamsx.topology by IBMStreams.

the class PublishSubscribeTest method testFilterOnXML.

@Test(expected = IllegalArgumentException.class)
public void testFilterOnXML() throws Exception {
    final Topology t = new Topology();
    TStream<XML> xmls = t.constants(Collections.<XML>emptyList()).asType(XML.class);
    ;
    xmls.publish("sometopic", true);
}
Also used : XML(com.ibm.streams.operator.types.XML) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Aggregations

XML (com.ibm.streams.operator.types.XML)3 Topology (com.ibm.streamsx.topology.Topology)3 TestTopology (com.ibm.streamsx.topology.test.TestTopology)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 JSONObject (com.ibm.json.java.JSONObject)1 Blob (com.ibm.streams.operator.types.Blob)1 ValueFactory (com.ibm.streams.operator.types.ValueFactory)1 TStream (com.ibm.streamsx.topology.TStream)1 Type (com.ibm.streamsx.topology.context.StreamsContext.Type)1 SPLSchemas (com.ibm.streamsx.topology.spl.SPLSchemas)1 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)1 SPLStreams (com.ibm.streamsx.topology.spl.SPLStreams)1 StringStreams (com.ibm.streamsx.topology.streams.StringStreams)1 Condition (com.ibm.streamsx.topology.tester.Condition)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Serializable (java.io.Serializable)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1