コード例 #1
0
ファイル: TestNewInstanceExpr.cs プロジェクト: ikvm/nesper
        private void RunAssertionNewInstance(bool soda)
        {
            _epService.EPAdministrator.Configuration.AddImport(typeof(SupportBean));

            var epl = "select " +
                      "new SupportBean(\"A\",IntPrimitive) as c0, " +
                      "new SupportBean(\"B\",IntPrimitive+10), " +
                      "new SupportBean() as c2, " +
                      "new SupportBean(\"ABC\",0).get_TheString() as c3 " +
                      "from SupportBean";
            var stmt = SupportModelHelper.CreateByCompileOrParse(_epService, soda, epl);

            stmt.AddListener(_listener);
            var expectedAggType = new object[][] { new object[] { "c0", typeof(SupportBean) }, new object[] { "new SupportBean(\"B\",IntPrimitive+10)", typeof(SupportBean) } };

            EventTypeAssertionUtil.AssertEventTypeProperties(expectedAggType, stmt.EventType, EventTypeAssertionEnum.NAME, EventTypeAssertionEnum.TYPE);

            var fields = "TheString,IntPrimitive".Split(',');

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 10));
            var @event = _listener.AssertOneGetNewAndReset();

            EPAssertionUtil.AssertPropsPONO(@event.Get("c0"), fields, new object[] { "A", 10 });
            EPAssertionUtil.AssertPropsPONO(((IDictionary <string, object>)@event.Underlying).Get("new SupportBean(\"B\",IntPrimitive+10)"), fields, new object[] { "B", 20 });
            EPAssertionUtil.AssertPropsPONO(@event.Get("c2"), fields, new object[] { null, 0 });
            Assert.AreEqual("ABC", @event.Get("c3"));

            _epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #2
0
        public void TestPopulateBeanSimple()
        {
            // test select column names
            var stmtTextOne = "insert into SupportBean select " +
                              "'E1' as TheString, 1 as IntPrimitive, 2 as IntBoxed, 3L as LongPrimitive," +
                              "null as LongBoxed, true as BoolPrimitive, " +
                              "'x' as CharPrimitive, 0xA as BytePrimitive, " +
                              "8.0f as FloatPrimitive, 9.0d as DoublePrimitive, " +
                              "0x05 as ShortPrimitive, SupportEnum.ENUM_VALUE_2 as EnumValue " +
                              " from MyMap";
            var stmtOne = _epService.EPAdministrator.CreateEPL(stmtTextOne);

            var stmtTextTwo = "select * from SupportBean";
            var stmtTwo     = _epService.EPAdministrator.CreateEPL(stmtTextTwo);

            stmtTwo.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "MyMap");
            var received = (SupportBean)_listener.AssertOneGetNewAndReset().Underlying;

            Assert.AreEqual("E1", received.TheString);
            EPAssertionUtil.AssertPropsPONO(received,
                                            "IntPrimitive,IntBoxed,LongPrimitive,LongBoxed,BoolPrimitive,CharPrimitive,BytePrimitive,FloatPrimitive,DoublePrimitive,ShortPrimitive,EnumValue".Split(','),
                                            new Object[] { 1, 2, 3l, null, true, 'x', (byte)10, 8f, 9d, (short)5, SupportEnum.ENUM_VALUE_2 });

            // test insert-into column names
            stmtOne.Dispose();
            stmtTwo.Dispose();
            _listener.Reset();
            stmtTextOne = "insert into SupportBean(TheString, IntPrimitive, IntBoxed, LongPrimitive," +
                          "LongBoxed, BoolPrimitive, CharPrimitive, BytePrimitive, FloatPrimitive, DoublePrimitive, " +
                          "ShortPrimitive, EnumValue) select " +
                          "'E1', 1, 2, 3L," +
                          "null, true, " +
                          "'x', 0xA, " +
                          "8.0f, 9.0d, " +
                          "0x05 as ShortPrimitive, SupportEnum.ENUM_VALUE_2 " +
                          " from MyMap";
            stmtOne         = _epService.EPAdministrator.CreateEPL(stmtTextOne);
            stmtOne.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "MyMap");
            received = (SupportBean)_listener.AssertOneGetNewAndReset().Underlying;
            Assert.AreEqual("E1", received.TheString);
            EPAssertionUtil.AssertPropsPONO(received,
                                            "IntPrimitive,IntBoxed,LongPrimitive,LongBoxed,BoolPrimitive,CharPrimitive,BytePrimitive,FloatPrimitive,DoublePrimitive,ShortPrimitive,EnumValue".Split(','),
                                            new Object[] { 1, 2, 3l, null, true, 'x', (byte)10, 8f, 9d, (short)5, SupportEnum.ENUM_VALUE_2 });

            // test convert Integer boxed to Long boxed
            stmtOne.Dispose();
            _listener.Reset();
            stmtTextOne     = "insert into SupportBean(LongBoxed, DoubleBoxed) select IntBoxed, FloatBoxed from MyMap";
            stmtOne         = _epService.EPAdministrator.CreateEPL(stmtTextOne);
            stmtOne.Events += _listener.Update;

            IDictionary <String, Object> vals = new Dictionary <String, Object>();

            vals.Put("IntBoxed", 4);
            vals.Put("FloatBoxed", 0f);
            _epService.EPRuntime.SendEvent(vals, "MyMap");
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "LongBoxed,DoubleBoxed".Split(','), new Object[] { 4L, 0d });
            _epService.EPAdministrator.DestroyAllStatements();

            // test new-to-map conversion
            _epService.EPAdministrator.Configuration.AddEventType(typeof(MyEventWithMapFieldSetter));
            var stmt = _epService.EPAdministrator.CreateEPL("insert into MyEventWithMapFieldSetter(Id, TheMap) " +
                                                            "select 'test' as Id, new {somefield = TheString} as TheMap from SupportBean");

            stmt.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertPropsMap((IDictionary <String, Object>)_listener.AssertOneGetNew().Get("TheMap"), "somefield".Split(','), "E1");
        }