public void testConfiguredViaPropsAndXML() { Configuration configuration = SupportConfigFactory.getConfiguration(); configuration .getEngineDefaults() .getEventMeta() .setDefaultEventRepresentation(Configuration.EventRepresentation.OBJECTARRAY); configuration.addEventType( "MyOAType", "bean,theString,map".split(","), new Object[] {SupportBean.class.getName(), "string", "java.util.Map"}); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration); epService.initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.startTest(epService, this.getClass(), getName()); } EventType eventType = epService.getEPAdministrator().getConfiguration().getEventType("MyOAType"); assertEquals(Object[].class, eventType.getUnderlyingType()); assertEquals(String.class, eventType.getPropertyType("theString")); assertEquals(Map.class, eventType.getPropertyType("map")); assertEquals(SupportBean.class, eventType.getPropertyType("bean")); EPStatement stmt = epService .getEPAdministrator() .createEPL("select bean, theString, map('key'), bean.theString from MyOAType"); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); assertEquals(Object[].class, stmt.getEventType().getUnderlyingType()); SupportBean bean = new SupportBean("E1", 1); epService .getEPRuntime() .sendEvent( new Object[] {bean, "abc", Collections.singletonMap("key", "value")}, "MyOAType"); EPAssertionUtil.assertProps( listener.assertOneGetNew(), "bean,theString,map('key'),bean.theString".split(","), new Object[] {bean, "abc", "value", "E1"}); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.endTest(); } }
public void testNestedPojo() { Pair<String[], Object[]> pair = getTestDefTwo(); EPServiceProvider epService = getEngineInitialized("NestedObjectArr", pair.getFirst(), pair.getSecond()); String statementText = "select " + "simple, object, nodefmap, map, " + "object.id as a1, nodefmap.key1? as a2, nodefmap.key2? as a3, nodefmap.key3?.key4 as a4, " + "map.objectOne as b1, map.simpleOne as b2, map.nodefmapOne.key2? as b3, map.mapOne.simpleTwo? as b4, " + "map.objectOne.indexed[1] as c1, map.objectOne.nested.nestedValue as c2," + "map.mapOne.simpleTwo as d1, map.mapOne.objectTwo as d2, map.mapOne.nodefmapTwo as d3, " + "map.mapOne.mapTwo as e1, map.mapOne.mapTwo.simpleThree as e2, map.mapOne.mapTwo.objectThree as e3, " + "map.mapOne.objectTwo.array[1].mapped('1ma').value as f1, map.mapOne.mapTwo.objectThree.id as f2" + " from NestedObjectArr"; EPStatement statement = epService.getEPAdministrator().createEPL(statementText); SupportUpdateListener listener = new SupportUpdateListener(); statement.addListener(listener); Object[] testdata = getTestDataTwo(); epService.getEPRuntime().sendEvent(testdata, "NestedObjectArr"); // test all properties exist EventBean received = listener.assertOneGetNewAndReset(); EPAssertionUtil.assertProps( received, "simple,object,nodefmap,map".split(","), new Object[] {"abc", new SupportBean_A("A1"), testdata[2], testdata[3]}); EPAssertionUtil.assertProps( received, "a1,a2,a3,a4".split(","), new Object[] {"A1", "val1", null, null}); EPAssertionUtil.assertProps( received, "b1,b2,b3,b4".split(","), new Object[] {getNestedKey(testdata, 3, "objectOne"), 10, "val2", 300}); EPAssertionUtil.assertProps(received, "c1,c2".split(","), new Object[] {2, "nestedValue"}); EPAssertionUtil.assertProps( received, "d1,d2,d3".split(","), new Object[] { 300, getNestedKey(testdata, 3, "mapOne", "objectTwo"), getNestedKey(testdata, 3, "mapOne", "nodefmapTwo") }); EPAssertionUtil.assertProps( received, "e1,e2,e3".split(","), new Object[] { getNestedKey(testdata, 3, "mapOne", "mapTwo"), 4000L, new SupportBean_B("B1") }); EPAssertionUtil.assertProps(received, "f1,f2".split(","), new Object[] {"1ma0", "B1"}); // assert type info EPStatement stmt = epService.getEPAdministrator().createEPL(("select * from NestedObjectArr")); EventType eventType = stmt.getEventType(); String[] propertiesReceived = eventType.getPropertyNames(); String[] propertiesExpected = new String[] {"simple", "object", "nodefmap", "map"}; EPAssertionUtil.assertEqualsAnyOrder(propertiesReceived, propertiesExpected); assertEquals(String.class, eventType.getPropertyType("simple")); assertEquals(Map.class, eventType.getPropertyType("map")); assertEquals(Map.class, eventType.getPropertyType("nodefmap")); assertEquals(SupportBean_A.class, eventType.getPropertyType("object")); assertNull(eventType.getPropertyType("map.mapOne.simpleOne")); // nested POJO with generic return type listener.reset(); epService .getEPAdministrator() .getConfiguration() .addEventType("MyNested", new String[] {"bean"}, new Object[] {MyNested.class}); EPStatement stmtTwo = epService .getEPAdministrator() .createEPL("select * from MyNested(bean.insides.anyOf(i=>id = 'A'))"); stmtTwo.addListener(listener); epService .getEPRuntime() .sendEvent( new Object[] {new MyNested(Arrays.asList(new MyInside[] {new MyInside("A")}))}, "MyNested"); assertTrue(listener.isInvoked()); }