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);
}
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);
}
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);
}
Aggregations