use of io.siddhi.core.event.stream.converter.SimpleStreamEventConverter in project siddhi by wso2.
the class EventTestCase method testSimpleStreamEventConverter.
@Test
public void testSimpleStreamEventConverter() {
Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addOutputData(symbol);
metaStreamEvent.addOutputData(price);
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT);
Event event = new Event(System.currentTimeMillis(), new Object[] { "WSO2", 200, 50 });
metaStreamEvent.addInputDefinition(streamDefinition);
StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent);
StreamEventFactory eventPool = new StreamEventFactory(metaStreamEvent);
StreamEvent newEvent = eventPool.newInstance();
converter.convertEvent(event, newEvent);
AssertJUnit.assertTrue(converter instanceof SimpleStreamEventConverter);
AssertJUnit.assertNull(newEvent.getBeforeWindowData());
AssertJUnit.assertNull(newEvent.getOnAfterWindowData());
AssertJUnit.assertEquals(2, newEvent.getOutputData().length);
AssertJUnit.assertEquals(200, newEvent.getOutputData()[1]);
AssertJUnit.assertEquals("WSO2", newEvent.getOutputData()[0]);
}
Aggregations