Exemplo n.º 1
0
        public void TestExpressionSimpleDOMGetter()
        {
            ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "simpleEvent";
            // eventTypeMeta.setXPathPropertyExpr(false); <== the default
            _epService.EPAdministrator.Configuration.AddEventType("TestXMLSchemaType", eventTypeMeta);

            EPStatement stmtInsert = _epService.EPAdministrator.CreateEPL("insert into MyNestedStream select nested1 from TestXMLSchemaType");

            EPAssertionUtil.AssertEqualsAnyOrder(
                new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("nested1", typeof(string), typeof(char), false, false, true, false, false),
            }, stmtInsert.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType);

            EPStatement stmtSelectWildcard = _epService.EPAdministrator.CreateEPL("select * from TestXMLSchemaType");

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[0], stmtSelectWildcard.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtSelectWildcard.EventType);

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "test");
            EventBean stmtInsertWildcardBean = stmtInsert.First();
            EventBean stmtSelectWildcardBean = stmtSelectWildcard.First();

            Assert.IsNotNull(stmtInsertWildcardBean.Get("nested1"));
            SupportEventTypeAssertionUtil.AssertConsistency(stmtSelectWildcardBean);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.First());

            Assert.AreEqual(0, stmtSelectWildcardBean.EventType.PropertyNames.Length);
        }
Exemplo n.º 2
0
        public void TestExpressionSimpleXPathGetter()
        {
            ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "simpleEvent";
            string schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();

            eventTypeMeta.SchemaResource      = schemaUri;
            eventTypeMeta.IsXPathPropertyExpr = true;           // <== note this
            eventTypeMeta.AddNamespacePrefix("ss", "samples:schemas:simpleSchema");
            _epService.EPAdministrator.Configuration.AddEventType("TestXMLSchemaType", eventTypeMeta);

            // note class not a fragment
            EPStatement stmtInsert = _epService.EPAdministrator.CreateEPL("insert into MyNestedStream select nested1 from TestXMLSchemaType");

            EPAssertionUtil.AssertEqualsAnyOrder(
                new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("nested1", typeof(XmlNode), null, false, false, false, false, false),
            }, stmtInsert.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType);

            EventType type = ((EPServiceProviderSPI)_epService).EventAdapterService.GetEventTypeByName("TestXMLSchemaType");

            SupportEventTypeAssertionUtil.AssertConsistency(type);
            Assert.IsNull(type.GetFragmentType("nested1"));
            Assert.IsNull(type.GetFragmentType("nested1.nested2"));

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "ABC");
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.First());
        }
        public void TestObservationExamplePropertyExpression()
        {
            var typecfg = new ConfigurationEventTypeXMLDOM();

            typecfg.RootElementName = "Sensor";
            var schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();

            typecfg.SchemaResource = schemaUri;

            var configuration = SupportConfigFactory.GetConfiguration();

            configuration.EngineDefaults.ViewResources.IsIterableUnbound = true;
            configuration.AddEventType("SensorEvent", typecfg);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, this.GetType(), this.GetType().FullName);
            }

            var stmtExampleOneText = "select ID, Observation.Command, Observation.ID,\n" +
                                     "Observation.Tag[0].ID, Observation.Tag[1].ID\n" +
                                     "from SensorEvent";
            var stmtExampleOne = _epService.EPAdministrator.CreateEPL(stmtExampleOneText);

            var stmtExampleTwo_0 = _epService.EPAdministrator.CreateEPL("insert into ObservationStream\n" +
                                                                        "select ID, Observation from SensorEvent");
            var stmtExampleTwo_1 = _epService.EPAdministrator.CreateEPL("select Observation.Command, Observation.Tag[0].ID from ObservationStream");

            var stmtExampleThree_0 = _epService.EPAdministrator.CreateEPL("insert into TagListStream\n" +
                                                                          "select ID as sensorId, Observation.* from SensorEvent");
            var stmtExampleThree_1 = _epService.EPAdministrator.CreateEPL("select sensorId, Command, Tag[0].ID from TagListStream");

            var doc    = SupportXML.GetDocument(XML);
            var sender = _epService.EPRuntime.GetEventSender("SensorEvent");

            sender.SendEvent(doc);

            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleOne.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_0.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_1.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleThree_0.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleThree_1.First());

            EPAssertionUtil.AssertProps(stmtExampleTwo_1.First(), "Observation.Command,Observation.Tag[0].ID".SplitCsv(), new object[] { "READ_PALLET_TAGS_ONLY", "urn:epc:1:2.24.400" });
            EPAssertionUtil.AssertProps(stmtExampleThree_1.First(), "sensorId,Command,Tag[0].ID".SplitCsv(), new object[] { "urn:epc:1:4.16.36", "READ_PALLET_TAGS_ONLY", "urn:epc:1:2.24.400" });

            try {
                _epService.EPAdministrator.CreateEPL("select Observation.Tag.ID from SensorEvent");
                Assert.Fail();
            } catch (EPStatementException ex) {
                Assert.AreEqual("Error starting statement: Failed to validate select-clause expression 'Observation.Tag.ID': Failed to resolve property 'Observation.Tag.ID' to a stream or nested property in a stream [select Observation.Tag.ID from SensorEvent]", ex.Message);
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Exemplo n.º 4
0
        public void TestSchemaXMLWSchemaWithAll()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();
            ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "event-page-visit";
            String schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_WITH_ALL_URI).ToString();

            eventTypeMeta.SchemaResource = schemaUri;
            eventTypeMeta.AddNamespacePrefix("ss", "samples:schemas:simpleSchemaWithAll");
            eventTypeMeta.AddXPathProperty("url", "/ss:event-page-visit/ss:url", XPathResultType.String);
            config.AddEventType("PageVisitEvent", eventTypeMeta);

            _epService = EPServiceProviderManager.GetDefaultProvider(config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            _updateListener = new SupportUpdateListener();

            // url='page4'
            String      text = "select a.url as sesja from pattern [ every a=PageVisitEvent(url='page1') ]";
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(text);

            stmt.Events += _updateListener.Update;

            SupportXML.SendEvent(
                _epService.EPRuntime,
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<event-page-visit xmlns=\"samples:schemas:simpleSchemaWithAll\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"samples:schemas:simpleSchemaWithAll simpleSchemaWithAll.xsd\">\n" +
                "<url>page1</url>" +
                "</event-page-visit>");
            EventBean theEvent = _updateListener.LastNewData[0];

            Assert.AreEqual("page1", theEvent.Get("sesja"));
            _updateListener.Reset();

            SupportXML.SendEvent(
                _epService.EPRuntime,
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<event-page-visit xmlns=\"samples:schemas:simpleSchemaWithAll\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"samples:schemas:simpleSchemaWithAll simpleSchemaWithAll.xsd\">\n" +
                "<url>page2</url>" +
                "</event-page-visit>");
            Assert.IsFalse(_updateListener.IsInvoked);

            EventType type = _epService.EPAdministrator.CreateEPL("select * from PageVisitEvent").EventType;

            EPAssertionUtil.AssertEqualsAnyOrder(new[] {
                new EventPropertyDescriptor("sessionId", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("customerId", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("url", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("method", typeof(XmlNode), null, false, false, false, false, true),
            }, type.PropertyDescriptors);
        }
Exemplo n.º 5
0
        public void TestExpressionNodeArray()
        {
            var eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "simpleEvent";
            var schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();

            eventTypeMeta.SchemaResource = schemaUri;
            _epService.EPAdministrator.Configuration.AddEventType("TestXMLSchemaType", eventTypeMeta);

            // try array property insert
            var stmtInsert = _epService.EPAdministrator.CreateEPL("select nested3.nested4 as narr from TestXMLSchemaType#lastevent");

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("narr", typeof(XmlNode[]), typeof(XmlNode), false, false, true, false, true),
            }, stmtInsert.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType);

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "test");

            var result = stmtInsert.First();

            SupportEventTypeAssertionUtil.AssertConsistency(result);
            var fragments = (EventBean[])result.GetFragment("narr");

            Assert.AreEqual(3, fragments.Length);
            Assert.AreEqual("SAMPLE_V8", fragments[0].Get("prop5[1]"));
            Assert.AreEqual("SAMPLE_V11", fragments[2].Get("prop5[1]"));

            var fragmentItem = (EventBean)result.GetFragment("narr[2]");

            Assert.AreEqual("TestXMLSchemaType.nested3.nested4", fragmentItem.EventType.Name);
            Assert.AreEqual("SAMPLE_V10", fragmentItem.Get("prop5[0]"));

            // try array index property insert
            var stmtInsertItem = _epService.EPAdministrator.CreateEPL("select nested3.nested4[1] as narr from TestXMLSchemaType#lastevent");

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("narr", typeof(XmlNode), null, false, false, false, false, true),
            }, stmtInsertItem.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsertItem.EventType);

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "test");

            var resultItem = stmtInsertItem.First();

            Assert.AreEqual("b", resultItem.Get("narr.id"));
            SupportEventTypeAssertionUtil.AssertConsistency(resultItem);
            var fragmentsInsertItem = (EventBean)resultItem.GetFragment("narr");

            SupportEventTypeAssertionUtil.AssertConsistency(fragmentsInsertItem);
            Assert.AreEqual("b", fragmentsInsertItem.Get("id"));
            Assert.AreEqual("SAMPLE_V9", fragmentsInsertItem.Get("prop5[0]"));
        }
Exemplo n.º 6
0
        public void TestSchemaXPathGetter()
        {
            var configuration = SupportConfigFactory.GetConfiguration();
            var desc          = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName = "simpleEvent";
            string schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();

            desc.SchemaResource             = schemaUri;
            desc.IsXPathPropertyExpr        = true;
            desc.IsEventSenderValidatesRoot = false;
            desc.AddNamespacePrefix("ss", "samples:schemas:simpleSchema");
            desc.DefaultNamespace = "samples:schemas:simpleSchema";
            configuration.AddEventType("MyEvent", desc);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, this.GetType(), this.GetType().FullName);
            }

            var stmtText = "select type?,dyn[1]?,nested.nes2?,map('a')? from MyEvent";
            var stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(_listener);

            EPAssertionUtil.AssertEqualsAnyOrder(
                new EventPropertyDescriptor[]
            {
                new EventPropertyDescriptor("type?", typeof(XmlNode), null, false, false, false, false, false),
                new EventPropertyDescriptor("dyn[1]?", typeof(XmlNode), null, false, false, false, false, false),
                new EventPropertyDescriptor("nested.nes2?", typeof(XmlNode), null, false, false, false, false, false),
                new EventPropertyDescriptor("map('a')?", typeof(XmlNode), null, false, false, false, false, false),
            }, stmt.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmt.EventType);

            var sender = _epService.EPRuntime.GetEventSender("MyEvent");
            var root   = SupportXML.SendEvent(sender, SCHEMA_XML);

            var theEvent = _listener.AssertOneGetNewAndReset();

            Assert.AreSame(root.DocumentElement.ChildNodes.Item(0), theEvent.Get("type?"));
            Assert.AreSame(root.DocumentElement.ChildNodes.Item(2), theEvent.Get("dyn[1]?"));
            Assert.AreSame(root.DocumentElement.ChildNodes.Item(3).ChildNodes.Item(0), theEvent.Get("nested.nes2?"));
            Assert.AreSame(root.DocumentElement.ChildNodes.Item(4), theEvent.Get("map('a')?"));
            SupportEventTypeAssertionUtil.AssertConsistency(theEvent);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Exemplo n.º 7
0
        public void TestExpressionPrimitiveArray()
        {
            var eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "simpleEvent";
            eventTypeMeta.SchemaResource  = _schemaURI;
            _epService.EPAdministrator.Configuration.AddEventType("ABCType", eventTypeMeta);

            eventTypeMeta = new ConfigurationEventTypeXMLDOM();
            eventTypeMeta.RootElementName            = "//nested2";
            eventTypeMeta.SchemaResource             = _schemaURI;
            eventTypeMeta.IsEventSenderValidatesRoot = false;
            _epService.EPAdministrator.Configuration.AddEventType("TestNested2", eventTypeMeta);

            // try array property in select
            var stmtInsert = _epService.EPAdministrator.CreateEPL("select * from TestNested2#lastevent");

            stmtInsert.AddListener(_listener);
            EPAssertionUtil.AssertEqualsAnyOrder(
                new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("prop3", typeof(int?[]), typeof(int?), false, false, true, false, false),
            }, stmtInsert.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType);

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "test");
            Assert.IsFalse(_listener.IsInvoked);

            var sender = _epService.EPRuntime.GetEventSender("TestNested2");

            sender.SendEvent(SupportXML.GetDocument("<nested2><prop3>2</prop3><prop3></prop3><prop3>4</prop3></nested2>"));
            var theEvent = stmtInsert.First();

            EPAssertionUtil.AssertEqualsExactOrder((int?[])theEvent.Get("prop3"), new int?[] { 2, null, 4 });
            SupportEventTypeAssertionUtil.AssertConsistency(theEvent);

            // try array property nested
            var stmtSelect = _epService.EPAdministrator.CreateEPL("select nested3.* from ABCType#lastevent");

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "test");
            var stmtSelectResult = stmtSelect.First();

            SupportEventTypeAssertionUtil.AssertConsistency(stmtSelectResult);
            Assert.AreEqual(typeof(string[]), stmtSelectResult.EventType.GetPropertyType("nested4[2].prop5"));
            Assert.AreEqual("SAMPLE_V8", stmtSelectResult.Get("nested4[0].prop5[1]"));
            EPAssertionUtil.AssertEqualsExactOrder((string[])stmtSelectResult.Get("nested4[2].prop5"), new object[] { "SAMPLE_V10", "SAMPLE_V11" });

            var fragmentNested4 = (EventBean)stmtSelectResult.GetFragment("nested4[2]");

            EPAssertionUtil.AssertEqualsExactOrder((string[])fragmentNested4.Get("prop5"), new object[] { "SAMPLE_V10", "SAMPLE_V11" });
            Assert.AreEqual("SAMPLE_V11", fragmentNested4.Get("prop5[1]"));
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentNested4);
        }
Exemplo n.º 8
0
        public void TestNoSchemaDOMGetter()
        {
            var configuration = SupportConfigFactory.GetConfiguration();
            var desc          = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName = "simpleEvent";
            configuration.AddEventType("MyEvent", desc);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            var stmtText = "select type?,dyn[1]?,nested.nes2?,map('a')? from MyEvent";
            var stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.Events += _listener.Update;

            EPAssertionUtil.AssertEqualsAnyOrder(
                new[]
            {
                new EventPropertyDescriptor("type?", typeof(XmlNode), null, false,
                                            false, false, false, false),
                new EventPropertyDescriptor("dyn[1]?", typeof(XmlNode), null,
                                            false, false, false, false, false),
                new EventPropertyDescriptor("nested.nes2?", typeof(XmlNode), null,
                                            false, false, false, false, false),
                new EventPropertyDescriptor("map('a')?", typeof(XmlNode), null,
                                            false, false, false, false, false),
            }, stmt.EventType.PropertyDescriptors);
            EventTypeAssertionUtil.AssertConsistency(stmt.EventType);

            XmlDocument root     = SupportXML.SendEvent(_epService.EPRuntime, NOSCHEMA_XML);
            EventBean   theEvent = _listener.AssertOneGetNewAndReset();

            Assert.AreSame(root.DocumentElement.ChildNodes.Item(0), theEvent.Get("type?"));
            Assert.AreSame(root.DocumentElement.ChildNodes.Item(2), theEvent.Get("dyn[1]?"));
            Assert.AreSame(root.DocumentElement.ChildNodes.Item(3).ChildNodes.Item(0), theEvent.Get("nested.nes2?"));
            Assert.AreSame(root.DocumentElement.ChildNodes.Item(4), theEvent.Get("map('a')?"));
            EventTypeAssertionUtil.AssertConsistency(theEvent);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Exemplo n.º 9
0
        public void TestXPathArray()
        {
            String xml = "<Event IsTriggering=\"True\">\n" +
                         "<Field Name=\"A\" Value=\"987654321\"/>\n" +
                         "<Field Name=\"B\" Value=\"2196958725202\"/>\n" +
                         "<Field Name=\"C\" Value=\"1232363702\"/>\n" +
                         "<Participants>\n" +
                         "<Participant>\n" +
                         "<Field Name=\"A\" Value=\"9876543210\"/>\n" +
                         "<Field Name=\"B\" Value=\"966607340\"/>\n" +
                         "<Field Name=\"D\" Value=\"353263010930650\"/>\n" +
                         "</Participant>\n" +
                         "</Participants>\n" +
                         "</Event>";

            ConfigurationEventTypeXMLDOM desc = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName = "Event";
            desc.AddXPathProperty("A", "//Field[@Name='A']/@Value", XPathResultType.NodeSet, "String[]");

            _epService = EPServiceProviderManager.GetDefaultProvider(SupportConfigFactory.GetConfiguration());
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            _epService.EPAdministrator.Configuration.AddEventType("Event", desc);

            EPStatement stmt = _epService.EPAdministrator.CreateEPL("select * from Event");

            _updateListener = new SupportUpdateListener();
            stmt.Events    += _updateListener.Update;

            XmlDocument doc = SupportXML.GetDocument(xml);

            _epService.EPRuntime.SendEvent(doc);

            EventBean theEvent = _updateListener.AssertOneGetNewAndReset();
            Object    value    = theEvent.Get("A");

            EPAssertionUtil.AssertProps(theEvent, "A".Split(','), new Object[] { new Object[] { "987654321", "9876543210" } });

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Exemplo n.º 10
0
        public void TestStaticConfig()
        {
            var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                      "<esper-configuration>\t\n" +
                      "\t<event-type name=\"MyMapEvent\">\n" +
                      "\t\t<map>\n" +
                      "\t  \t\t<map-property name=\"myStringArray\" class=\"string[]\"/>\n" +
                      "\t  \t</map>\n" +
                      "\t</event-type>\n" +
                      "\t\n" +
                      "\t<event-type name=\"MyObjectArrayEvent\">\n" +
                      "\t\t<objectarray>\n" +
                      "\t  \t\t<objectarray-property name=\"myStringArray\" class=\"string[]\"/>\n" +
                      "\t  \t</objectarray>\n" +
                      "\t</event-type>\n" +
                      "</esper-configuration>\n";

            var config = new Configuration();

            config.Configure(SupportXML.GetDocument(xml));

            // add a map-type and then clear the map to test copy of type definition for preventing accidental overwrite
            var typeMyEventIsCopyDef = new Dictionary <string, object>();

            typeMyEventIsCopyDef.Put("prop1", typeof(string));
            config.AddEventType("MyEventIsCopyDef", typeMyEventIsCopyDef);
            typeMyEventIsCopyDef.Clear();

            // obtain engine
            var epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();

            // ensure cleared type is available (type information was copied to prevent accidental overwrite)
            epService.EPAdministrator.CreateEPL("select prop1 from MyEventIsCopyDef");

            // assert array types
            foreach (var name in new string[] { "MyObjectArrayEvent", "MyMapEvent" })
            {
                EPAssertionUtil.AssertEqualsAnyOrder(
                    new EventPropertyDescriptor[]
                {
                    new EventPropertyDescriptor("myStringArray", typeof(string[]), typeof(string), false, false, true, false, false),
                },
                    epService.EPAdministrator.Configuration.GetEventType(name).PropertyDescriptors);
            }
        }
Exemplo n.º 11
0
        public void TestIt()
        {
            // Bean
            RunAssertionSuccess(typeof(SupportBean).FullName, new SupportBean());
            RunAssertionInvalid(typeof(SupportBean).FullName, new SupportBean_G("G1"),
                                "Event object of type " + typeof(SupportBean_G).FullName + " does not equal, extend or implement the type " + typeof(SupportBean).FullName + " of event type 'SupportBean'");
            RunAssertionSuccess("Marker", new SupportMarkerImplA("Q2"), new SupportBean_G("Q3"));

            // Map
            RunAssertionSuccess(SupportEventInfra.MAP_TYPENAME, new Dictionary <string, object>());
            RunAssertionInvalid(SupportEventInfra.MAP_TYPENAME, new SupportBean(),
                                "Unexpected event object of type " + typeof(SupportBean).FullName + ", expected " + Name.Of <IDictionary <string, object> >());

            // Object-Array
            RunAssertionSuccess(SupportEventInfra.OA_TYPENAME, new object[] { });
            RunAssertionInvalid(SupportEventInfra.OA_TYPENAME, new SupportBean(),
                                "Unexpected event object of type " + typeof(SupportBean).FullName + ", expected Object[]");

            // XML
            RunAssertionSuccess(SupportEventInfra.XML_TYPENAME, SupportXML.GetDocument("<myevent/>").DocumentElement);
            RunAssertionInvalid(SupportEventInfra.XML_TYPENAME, new SupportBean(),
                                "Unexpected event object type '" + typeof(SupportBean).FullName + "' encountered, please supply a XmlDocument or XmlElement node");
            RunAssertionInvalid(SupportEventInfra.XML_TYPENAME, SupportXML.GetDocument("<xxxx/>"),
                                "Unexpected root element name 'xxxx' encountered, expected a root element name of 'myevent'");

            // Avro
            RunAssertionSuccess(SupportEventInfra.AVRO_TYPENAME, new GenericRecord(GetAvroSchema()));
            RunAssertionInvalid(SupportEventInfra.AVRO_TYPENAME, new SupportBean(),
                                "Unexpected event object type '" + typeof(SupportBean).FullName + "' encountered, please supply a GenericRecord");

            // No such type
            try {
                _epService.EPRuntime.GetEventSender("ABC");
                Assert.Fail();
            } catch (EventTypeException ex) {
                Assert.AreEqual("Event type named 'ABC' could not be found", ex.Message);
            }

            // Internal implicit wrapper type
            _epService.EPAdministrator.CreateEPL("insert into ABC select *, theString as value from SupportBean");
            try {
                _epService.EPRuntime.GetEventSender("ABC");
                Assert.Fail("Event type named 'ABC' could not be found");
            } catch (EventTypeException ex) {
                Assert.AreEqual("An event sender for event type named 'ABC' could not be created as the type is internal", ex.Message);
            }
        }
        public void SetUp()
        {
            var configuration = SupportConfigFactory.GetConfiguration();
            var avroSchema    = SchemaBuilder.Record(SupportEventInfra.AVRO_TYPENAME,
                                                     TypeBuilder.Field("intPrimitive", TypeBuilder.Int()));

            //SchemaBuilder.Record(SupportEventInfra.AVRO_TYPENAME).Fields()
            //             .Name("intPrimitive").Type().IntType().NoDefault().EndRecord();

            string avroSchemaText = avroSchema.ToString().Replace("\"", "&quot;");

            string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                         "<esper-configuration>\t\n" +
                         "\t<event-type name=\"MyStaticBean\" class=\"" + typeof(SupportBean).FullName + "\"/>\n" +
                         "\t<event-type name=\"" + SupportEventInfra.MAP_TYPENAME + "\">\n" +
                         "\t\t<map>\n" +
                         "\t  \t\t<map-property name=\"intPrimitive\" class=\"int\"/>\n" +
                         "\t  \t</map>\n" +
                         "\t</event-type>\n" +
                         "\t\n" +
                         "\t<event-type name=\"" + SupportEventInfra.OA_TYPENAME + "\">\n" +
                         "\t\t<objectarray>\n" +
                         "\t  \t\t<objectarray-property name=\"intPrimitive\" class=\"int\"/>\n" +
                         "\t  \t</objectarray>\n" +
                         "\t</event-type>\n" +
                         "\t<event-type name=\"" + SupportEventInfra.XML_TYPENAME + "\">\n" +
                         "\t\t<xml-dom root-element-name=\"myevent\">\n" +
                         "\t\t\t<xpath-property property-name=\"intPrimitive\" xpath=\"@intPrimitive\" type=\"number\"/>\n" +
                         "\t\t</xml-dom>\n" +
                         "\t</event-type>\n" +
                         "\t<event-type name=\"" + SupportEventInfra.AVRO_TYPENAME + "\">\n" +
                         "\t\t<avro schema-text=\"" + avroSchemaText + "\"/>\n" +
                         "\t</event-type>\n" +
                         "</esper-configuration>\n";

            configuration.Configure(SupportXML.GetDocument(xml));

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, this.GetType(), this.GetType().FullName);
            }
        }
Exemplo n.º 13
0
        public void TestSchemaXMLWSchemaWithRestriction()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();
            ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "order";

            var schemaStream = ResourceManager.GetResourceAsStream(CLASSLOADER_SCHEMA_WITH_RESTRICTION_URI);

            Assert.NotNull(schemaStream);

            var schemaReader = new StreamReader(schemaStream);
            var schemaText   = schemaReader.ReadToEnd();

            schemaReader.Close();
            schemaStream.Close();

            eventTypeMeta.SchemaText = schemaText;
            config.AddEventType("OrderEvent", eventTypeMeta);

            _epService = EPServiceProviderManager.GetProvider("TestSchemaXML", config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            _updateListener = new SupportUpdateListener();

            String      text = "select order_amount from OrderEvent";
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(text);

            stmt.Events += _updateListener.Update;

            SupportXML.SendEvent(_epService.EPRuntime,
                                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                                 "<order>\n" +
                                 "<order_amount>202.1</order_amount>" +
                                 "</order>");
            EventBean theEvent = _updateListener.LastNewData[0];

            Assert.AreEqual(typeof(double), theEvent.Get("order_amount").GetType());
            Assert.AreEqual(202.1d, theEvent.Get("order_amount"));
            _updateListener.Reset();
        }
Exemplo n.º 14
0
        public void TestXPathExpression()
        {
            var ctx = new XPathNamespaceContext();

            ctx.AddNamespace("n0", "samples:schemas:simpleSchema");

            var node = SupportXML.GetDocument().DocumentElement;

            var pathExprOne = XPathExpression.Compile(
                "/n0:simpleEvent/n0:nested1",
                ctx);

            var nav      = node.CreateNavigator();
            var iterator = (XPathNodeIterator)nav.Evaluate(pathExprOne);

            Assert.AreEqual(iterator.Count, 1);
            Assert.IsTrue(iterator.MoveNext());
            var result = ((IHasXmlNode)iterator.Current).GetNode();

            Assert.IsNotNull(result);

            //Console.WriteLine("Result:\n" + SchemaUtil.Serialize(result));

            var pathExprTwo = XPathExpression.Compile("/n0:simpleEvent/n0:nested1/n0:prop1", ctx);

            iterator = (XPathNodeIterator)nav.Evaluate(pathExprTwo);
            Assert.AreEqual(iterator.Count, 1);
            Assert.IsTrue(iterator.MoveNext());
            var resultTwo = (string)iterator.Current.TypedValue;
            //Console.WriteLine("Result 2: <" + resultTwo + ">");

            var pathExprThree = XPathExpression.Compile("/n0:simpleEvent/n0:nested3", ctx);

            iterator = (XPathNodeIterator)nav.Evaluate(pathExprThree);
            Assert.AreEqual(iterator.Count, 1);
            Assert.IsTrue(iterator.MoveNext());
            var resultThree = (string)iterator.Current.TypedValue;
            //Console.WriteLine("Result 3: <" + resultThress + ">");
        }
        public void TestObservationExampleXPathExpr()
        {
            var schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();

            var sensorcfg = new ConfigurationEventTypeXMLDOM();

            sensorcfg.RootElementName = "Sensor";
            sensorcfg.AddXPathProperty("countTags", "count(/ss:Sensor/ss:Observation/ss:Tag)", XPathResultType.Number);
            sensorcfg.AddXPathProperty("countTagsInt", "count(/ss:Sensor/ss:Observation/ss:Tag)", XPathResultType.Number, "int");
            sensorcfg.AddNamespacePrefix("ss", "SensorSchema");
            sensorcfg.AddXPathProperty("idarray", "//ss:Tag/ss:ID", XPathResultType.NodeSet, "String[]");
            sensorcfg.AddXPathPropertyFragment("tagArray", "//ss:Tag", XPathResultType.NodeSet, "TagEvent");
            sensorcfg.AddXPathPropertyFragment("tagOne", "//ss:Tag[position() = 1]", XPathResultType.Any, "TagEvent");
            sensorcfg.SchemaResource = schemaUri;

            var configuration = SupportConfigFactory.GetConfiguration();

            configuration.EngineDefaults.ViewResources.IsIterableUnbound = true;
            configuration.AddEventType("SensorEvent", sensorcfg);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, this.GetType(), this.GetType().FullName);
            }

            var tagcfg = new ConfigurationEventTypeXMLDOM();

            tagcfg.RootElementName = "//Tag";
            tagcfg.SchemaResource  = schemaUri;
            _epService.EPAdministrator.Configuration.AddEventType("TagEvent", tagcfg);

            var stmtExampleOne   = _epService.EPAdministrator.CreateEPL("select countTags, countTagsInt, idarray, tagArray, tagOne from SensorEvent");
            var stmtExampleTwo_0 = _epService.EPAdministrator.CreateEPL("insert into TagOneStream select tagOne.* from SensorEvent");
            var stmtExampleTwo_1 = _epService.EPAdministrator.CreateEPL("select ID from TagOneStream");
            var stmtExampleTwo_2 = _epService.EPAdministrator.CreateEPL("insert into TagArrayStream select tagArray as mytags from SensorEvent");
            var stmtExampleTwo_3 = _epService.EPAdministrator.CreateEPL("select mytags[1].ID from TagArrayStream");

            var doc = SupportXML.GetDocument(XML);

            _epService.EPRuntime.SendEvent(doc);

            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleOne.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_0.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_1.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_2.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_3.First());

            var resultArray = stmtExampleOne.First().Get("idarray");

            EPAssertionUtil.AssertEqualsExactOrder((object[])resultArray, new string[] { "urn:epc:1:2.24.400", "urn:epc:1:2.24.401" });
            EPAssertionUtil.AssertProps(stmtExampleOne.First(), "countTags,countTagsInt".SplitCsv(), new object[] { 2d, 2 });
            Assert.AreEqual("urn:epc:1:2.24.400", stmtExampleTwo_1.First().Get("ID"));
            Assert.AreEqual("urn:epc:1:2.24.401", stmtExampleTwo_3.First().Get("mytags[1].ID"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Exemplo n.º 16
0
        public void TestXPathConfigured()
        {
            var rootMeta = new ConfigurationEventTypeXMLDOM();

            rootMeta.RootElementName = "simpleEvent";
            rootMeta.SchemaResource  = _schemaURI;
            rootMeta.AddNamespacePrefix("ss", "samples:schemas:simpleSchema");
            rootMeta.AddXPathPropertyFragment("nested1simple", "/ss:simpleEvent/ss:nested1", XPathResultType.Any, "MyNestedEvent");
            rootMeta.AddXPathPropertyFragment("nested4array", "//ss:nested4", XPathResultType.NodeSet, "MyNestedArrayEvent");
            rootMeta.IsAutoFragment = false;
            _epService.EPAdministrator.Configuration.AddEventType("MyXMLEvent", rootMeta);

            var metaNested = new ConfigurationEventTypeXMLDOM();

            metaNested.RootElementName = "//nested1";
            metaNested.SchemaResource  = _schemaURI;
            metaNested.IsAutoFragment  = false;
            _epService.EPAdministrator.Configuration.AddEventType("MyNestedEvent", metaNested);

            var metaNestedArray = new ConfigurationEventTypeXMLDOM();

            metaNestedArray.RootElementName = "//nested4";
            metaNestedArray.SchemaResource  = _schemaURI;
            _epService.EPAdministrator.Configuration.AddEventType("MyNestedArrayEvent", metaNestedArray);

            var stmtInsert   = _epService.EPAdministrator.CreateEPL("insert into Nested3Stream select nested1simple, nested4array from MyXMLEvent#lastevent");
            var stmtWildcard = _epService.EPAdministrator.CreateEPL("select * from MyXMLEvent#lastevent");

            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtWildcard.EventType);
            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("nested1simple", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("nested4array", typeof(XmlNode[]), typeof(XmlNode), false, false, true, false, true),
            }, stmtInsert.EventType.PropertyDescriptors);

            var fragmentTypeNested1 = stmtInsert.EventType.GetFragmentType("nested1simple");

            Assert.IsFalse(fragmentTypeNested1.IsIndexed);
            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("prop1", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("prop2", typeof(bool?), null, false, false, false, false, false),
                new EventPropertyDescriptor("attr1", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("nested2", typeof(XmlNode), null, false, false, false, false, false),
            }, fragmentTypeNested1.FragmentType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentTypeNested1.FragmentType);

            var fragmentTypeNested4 = stmtInsert.EventType.GetFragmentType("nested4array");

            Assert.IsTrue(fragmentTypeNested4.IsIndexed);
            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("prop5", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop6", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop7", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop8", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("id", typeof(string), typeof(char), false, false, true, false, false),
            }, fragmentTypeNested4.FragmentType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentTypeNested4.FragmentType);

            var fragmentTypeNested4Item = stmtInsert.EventType.GetFragmentType("nested4array[0]");

            Assert.IsFalse(fragmentTypeNested4Item.IsIndexed);
            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("prop5", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop6", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop7", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop8", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("id", typeof(string), typeof(char), false, false, true, false, false),
            }, fragmentTypeNested4Item.FragmentType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentTypeNested4Item.FragmentType);

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "ABC");

            var received = stmtInsert.First();

            EPAssertionUtil.AssertProps(received, "nested1simple.prop1,nested1simple.prop2,nested1simple.attr1,nested1simple.nested2.prop3[1]".SplitCsv(), new object[] { "SAMPLE_V1", true, "SAMPLE_ATTR1", 4 });
            EPAssertionUtil.AssertProps(received, "nested4array[0].id,nested4array[0].prop5[1],nested4array[1].id".SplitCsv(), new object[] { "a", "SAMPLE_V8", "b" });

            // assert event and fragments alone
            var wildcardStmtEvent = stmtWildcard.First();

            SupportEventTypeAssertionUtil.AssertConsistency(wildcardStmtEvent);

            var eventType = wildcardStmtEvent.EventType.GetFragmentType("nested1simple");

            Assert.IsFalse(eventType.IsIndexed);
            Assert.IsFalse(eventType.IsNative);
            Assert.AreEqual("MyNestedEvent", eventType.FragmentType.Name);
            Assert.IsTrue(wildcardStmtEvent.Get("nested1simple") is XmlNode);
            Assert.AreEqual("SAMPLE_V1", ((EventBean)wildcardStmtEvent.GetFragment("nested1simple")).Get("prop1"));

            eventType = wildcardStmtEvent.EventType.GetFragmentType("nested4array");
            Assert.IsTrue(eventType.IsIndexed);
            Assert.IsFalse(eventType.IsNative);
            Assert.AreEqual("MyNestedArrayEvent", eventType.FragmentType.Name);
            var eventsArray = (EventBean[])wildcardStmtEvent.GetFragment("nested4array");

            Assert.AreEqual(3, eventsArray.Length);
            Assert.AreEqual("SAMPLE_V8", eventsArray[0].Get("prop5[1]"));
            Assert.AreEqual("SAMPLE_V9", eventsArray[1].Get("prop5[0]"));
            Assert.AreEqual(typeof(XmlNodeList), wildcardStmtEvent.EventType.GetPropertyType("nested4array"));
            Assert.IsTrue(wildcardStmtEvent.Get("nested4array") is XmlNodeList);

            var nested4arrayItem = (EventBean)wildcardStmtEvent.GetFragment("nested4array[1]");

            Assert.AreEqual("b", nested4arrayItem.Get("id"));
        }
Exemplo n.º 17
0
        public void TestXML()
        {
            var configuration = SupportConfigFactory.GetConfiguration();
            var typeMeta      = new ConfigurationEventTypeXMLDOM();

            typeMeta.RootElementName = "a";
            typeMeta.AddXPathProperty("element1", "/a/b/c", XPathResultType.String);
            configuration.AddEventType("AEvent", typeMeta);

            var listener  = new SupportUpdateListener();
            var epService = EPServiceProviderManager.GetDefaultProvider(configuration);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, this.GetType(), this.GetType().FullName);
            }

            var stmtText = "select b.c as type, element1 from AEvent";
            var stmt     = epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(listener);

            var doc    = SupportXML.GetDocument("<a><b><c>text</c></b></a>");
            var sender = epService.EPRuntime.GetEventSender("AEvent");

            sender.SendEvent(doc);

            var theEvent = listener.AssertOneGetNewAndReset();

            Assert.AreEqual("text", theEvent.Get("type"));
            Assert.AreEqual("text", theEvent.Get("element1"));

            // send wrong event
            try {
                sender.SendEvent(SupportXML.GetDocument("<xxxx><b><c>text</c></b></xxxx>"));
                Assert.Fail();
            } catch (EPException ex) {
                Assert.AreEqual("Unexpected root element name 'xxxx' encountered, expected a root element name of 'a'", ex.Message);
            }

            try {
                sender.SendEvent(new SupportBean());
                Assert.Fail();
            } catch (EPException ex) {
                Assert.AreEqual("Unexpected event object type '" + Name.Of <SupportBean>() + "' encountered, please supply a XmlDocument or XmlElement node", ex.Message);
            }

            // test adding a second type for the same root element
            configuration            = SupportConfigFactory.GetConfiguration();
            typeMeta                 = new ConfigurationEventTypeXMLDOM();
            typeMeta.RootElementName = "a";
            typeMeta.AddXPathProperty("element2", "//c", XPathResultType.String);
            typeMeta.IsEventSenderValidatesRoot = false;
            epService.EPAdministrator.Configuration.AddEventType("BEvent", typeMeta);

            stmtText = "select element2 from BEvent#lastevent";
            var stmtTwo = epService.EPAdministrator.CreateEPL(stmtText);

            // test sender that doesn't care about the root element
            var senderTwo = epService.EPRuntime.GetEventSender("BEvent");

            senderTwo.SendEvent(SupportXML.GetDocument("<xxxx><b><c>text</c></b></xxxx>"));    // allowed, not checking

            theEvent = stmtTwo.First();
            Assert.AreEqual("text", theEvent.Get("element2"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Exemplo n.º 18
0
        public void TestExpressionSimpleDOMGetter()
        {
            var eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "simpleEvent";
            var schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();

            eventTypeMeta.SchemaResource = schemaUri;
            // eventTypeMeta.setXPathPropertyExpr(false); <== the default
            _epService.EPAdministrator.Configuration.AddEventType("TestXMLSchemaType", eventTypeMeta);

            var stmtInsert = _epService.EPAdministrator.CreateEPL("insert into MyNestedStream select nested1 from TestXMLSchemaType#lastevent");

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("nested1", typeof(XmlNode), null, false, false, false, false, true),
            }, stmtInsert.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType);

            var stmtSelect = _epService.EPAdministrator.CreateEPL("select nested1.attr1 as attr1, nested1.prop1 as prop1, nested1.prop2 as prop2, nested1.nested2.prop3 as prop3, nested1.nested2.prop3[0] as prop3_0, nested1.nested2 as nested2 from MyNestedStream#lastevent");

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("prop1", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("prop2", typeof(bool?), null, false, false, false, false, false),
                new EventPropertyDescriptor("attr1", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("prop3", typeof(int?[]), typeof(int?), false, false, true, false, false),
                new EventPropertyDescriptor("prop3_0", typeof(int?), null, false, false, false, false, false),
                new EventPropertyDescriptor("nested2", typeof(XmlNode), null, false, false, false, false, true),
            }, stmtSelect.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtSelect.EventType);

            var stmtSelectWildcard = _epService.EPAdministrator.CreateEPL("select * from MyNestedStream");

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("nested1", typeof(XmlNode), null, false, false, false, false, true),
            }, stmtSelectWildcard.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtSelectWildcard.EventType);

            var stmtInsertWildcard = _epService.EPAdministrator.CreateEPL("insert into MyNestedStreamTwo select nested1.* from TestXMLSchemaType#lastevent");

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("prop1", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("prop2", typeof(bool?), null, false, false, false, false, false),
                new EventPropertyDescriptor("attr1", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("nested2", typeof(XmlNode), null, false, false, false, false, true),
            }, stmtInsertWildcard.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsertWildcard.EventType);

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "test");
            var stmtInsertWildcardBean = stmtInsertWildcard.First();

            EPAssertionUtil.AssertProps(stmtInsertWildcardBean, "prop1,prop2,attr1".SplitCsv(),
                                        new object[] { "SAMPLE_V1", true, "SAMPLE_ATTR1" });

            SupportEventTypeAssertionUtil.AssertConsistency(stmtSelect.First());
            var stmtInsertBean = stmtInsert.First();

            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsertWildcard.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.First());

            var fragmentNested1 = (EventBean)stmtInsertBean.GetFragment("nested1");

            Assert.AreEqual(5, fragmentNested1.Get("nested2.prop3[2]"));
            Assert.AreEqual("TestXMLSchemaType.nested1", fragmentNested1.EventType.Name);

            var fragmentNested2 = (EventBean)stmtInsertWildcardBean.GetFragment("nested2");

            Assert.AreEqual(4, fragmentNested2.Get("prop3[1]"));
            Assert.AreEqual("TestXMLSchemaType.nested1.nested2", fragmentNested2.EventType.Name);
        }
Exemplo n.º 19
0
        public void TestSchemaXMLQuery_DOMGetterBacked()
        {
            _epService = EPServiceProviderManager.GetProvider("TestSchemaXML", GetConfig(false));
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            _updateListener = new SupportUpdateListener();

            String      stmtSelectWild = "select * from TestXMLSchemaType";
            EPStatement wildStmt       = _epService.EPAdministrator.CreateEPL(stmtSelectWild);
            EventType   type           = wildStmt.EventType;

            EventTypeAssertionUtil.AssertConsistency(type);

            EPAssertionUtil.AssertEqualsAnyOrder(new[] {
                new EventPropertyDescriptor("nested1", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("prop4", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("nested3", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("customProp", typeof(double?), null, false, false, false, false, false),
            }, type.PropertyDescriptors);

            String stmt =
                "select nested1 as NodeProp," +
                "prop4 as Nested1Prop," +
                "nested1.prop2 as Nested2Prop," +
                "nested3.nested4('a').prop5[1] as ComplexProp," +
                "nested1.nested2.prop3[2] as IndexedProp," +
                "customProp as CustomProp," +
                "prop4.attr2 as AttrOneProp," +
                "nested3.nested4[2].id as AttrTwoProp" +
                " from TestXMLSchemaType.win:length(100)";

            EPStatement selectStmt = _epService.EPAdministrator.CreateEPL(stmt);

            selectStmt.Events += _updateListener.Update;
            type = selectStmt.EventType;
            EventTypeAssertionUtil.AssertConsistency(type);
            EPAssertionUtil.AssertEqualsAnyOrder(new[] {
                new EventPropertyDescriptor("NodeProp", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("Nested1Prop", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("Nested2Prop", typeof(bool?), null, false, false, false, false, false),
                new EventPropertyDescriptor("ComplexProp", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("IndexedProp", typeof(int?), null, false, false, false, false, false),
                new EventPropertyDescriptor("CustomProp", typeof(double?), null, false, false, false, false, false),
                new EventPropertyDescriptor("AttrOneProp", typeof(bool?), null, false, false, false, false, false),
                new EventPropertyDescriptor("AttrTwoProp", typeof(string), typeof(char), false, false, true, false, false),
            }, type.PropertyDescriptors);

            XmlDocument eventDoc = SupportXML.SendDefaultEvent(_epService.EPRuntime, "test");

            Assert.NotNull(_updateListener.LastNewData);
            EventBean theEvent = _updateListener.LastNewData[0];

            Assert.AreSame(eventDoc.DocumentElement.ChildNodes[0], theEvent.Get("NodeProp"));
            Assert.AreEqual("SAMPLE_V6", theEvent.Get("Nested1Prop"));
            Assert.AreEqual(true, theEvent.Get("Nested2Prop"));
            Assert.AreEqual("SAMPLE_V8", theEvent.Get("ComplexProp"));
            Assert.AreEqual(5, theEvent.Get("IndexedProp"));
            Assert.AreEqual(3.0, theEvent.Get("CustomProp"));
            Assert.AreEqual(true, theEvent.Get("AttrOneProp"));
            Assert.AreEqual("c", theEvent.Get("AttrTwoProp"));
        }