public void TestEventXML()
        {
            Configuration configuration       = SupportConfigFactory.GetConfiguration();
            ConfigurationEventTypeXMLDOM desc = new ConfigurationEventTypeXMLDOM();

            desc.AddXPathProperty("event.type", "/event/@type", XPathResultType.String);
            desc.AddXPathProperty("event.uid", "/event/@uid", XPathResultType.String);
            desc.RootElementName = "event";
            configuration.AddEventType("MyEvent", desc);

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

            _updateListener = new SupportUpdateListener();

            String      stmt     = "select event.type as type, event.uid as uid from MyEvent";
            EPStatement joinView = _epService.EPAdministrator.CreateEPL(stmt);

            joinView.Events += _updateListener.Update;

            SendXMLEvent("<event type=\"a-f-G\" uid=\"terminal.55\" time=\"2007-04-19T13:05:20.22Z\" version=\"2.0\"></event>");
            EventBean theEvent = _updateListener.AssertOneGetNewAndReset();

            Assert.AreEqual("a-f-G", theEvent.Get("type"));
            Assert.AreEqual("terminal.55", theEvent.Get("uid"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestVariableAndDotMethodResolution()
        {
            // test for ESPER-341
            Configuration configuration = SupportConfigFactory.GetConfiguration();

            configuration.AddVariable("var", typeof(int), 0);

            ConfigurationEventTypeXMLDOM xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();

            xmlDOMEventTypeDesc.RootElementName = "myevent";
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrNum", "/myevent/@attrnum", XPathResultType.String, "long");
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrNumTwo", "/myevent/@attrnumtwo", XPathResultType.String, "long");
            configuration.AddEventType("TestXMLNoSchemaType", xmlDOMEventTypeDesc);

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

            _updateListener = new SupportUpdateListener();

            String stmtTextOne = "select var, xpathAttrNum.After(xpathAttrNumTwo) from TestXMLNoSchemaType.win:length(100)";

            _epService.EPAdministrator.CreateEPL(stmtTextOne);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestElementNode()
        {
            // test for Esper-129
            Configuration configuration = SupportConfigFactory.GetConfiguration();
            var           desc          = new ConfigurationEventTypeXMLDOM();

            desc.AddXPathProperty("event.type", "//event/@type", XPathResultType.String);
            desc.AddXPathProperty("event.uid", "//event/@uid", XPathResultType.String);
            desc.RootElementName = "batch-event";
            configuration.AddEventType("MyEvent", desc);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            _updateListener = new SupportUpdateListener();

            const string stmt     = "select event.type as type, event.uid as uid from MyEvent";
            EPStatement  joinView = _epService.EPAdministrator.CreateEPL(stmt);

            joinView.Events += _updateListener.Update;

            const string xml = "<batch-event>" +
                               "<event type=\"a-f-G\" uid=\"terminal.55\" time=\"2007-04-19T13:05:20.22Z\" version=\"2.0\"/>" +
                               "</batch-event>";

            var doc        = XDocument.Parse(xml);
            var topElement = doc.Root;

            _epService.EPRuntime.SendEvent(topElement);
            EventBean theEvent = _updateListener.AssertOneGetNewAndReset();

            Assert.AreEqual("a-f-G", theEvent.Get("type"));
            Assert.AreEqual("terminal.55", theEvent.Get("uid"));
        }
Exemple #4
0
        public void TestSchemaReplace()
        {
            ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();

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

            eventTypeMeta.SchemaResource = schemaUri;
            eventTypeMeta.AddNamespacePrefix("ss", "samples:schemas:simpleSchema");
            eventTypeMeta.AddXPathProperty("customProp", "count(/ss:simpleEvent/ss:nested3/ss:nested4)", XPathResultType.Number);

            Configuration configuration = SupportConfigFactory.GetConfiguration();

            configuration.AddEventType("TestXMLSchemaType", eventTypeMeta);

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

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

            // Update type and replace
            schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_VERSION2_URI).ToString();
            eventTypeMeta.SchemaResource = schemaUri;
            eventTypeMeta.AddXPathProperty("countProp", "count(/ss:simpleEvent/ss:nested3/ss:nested4)", XPathResultType.Number);
            _epService.EPAdministrator.Configuration.ReplaceXMLEventType("TestXMLSchemaType", eventTypeMeta);

            wildStmt = _epService.EPAdministrator.CreateEPL(stmtSelectWild);
            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("prop5", 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),
                new EventPropertyDescriptor("countProp", typeof(double?), null, false, false, false, false, false),
            }, type.PropertyDescriptors);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public override void Configure(Configuration configuration)
        {
            var desc = new ConfigurationEventTypeXMLDOM();

            desc.AddXPathProperty("event.type", "/event/@type", XPathResultType.String);
            desc.AddXPathProperty("event.uid", "/event/@uid", XPathResultType.String);
            desc.RootElementName = "event";
            configuration.AddEventType("MyEvent", desc);
        }
        public override void Configure(Configuration configuration)
        {
            configuration.AddVariable("var", typeof(int), 0);

            var xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();

            xmlDOMEventTypeDesc.RootElementName = "myevent";
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrNum", "/myevent/@attrnum", XPathResultType.String, "long");
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrNumTwo", "/myevent/@attrnumtwo", XPathResultType.String, "long");
            configuration.AddEventType("TestXMLNoSchemaType", xmlDOMEventTypeDesc);
        }
        public override void Configure(Configuration configuration)
        {
            var desc = new ConfigurationEventTypeXMLDOM();

            desc.AddXPathProperty("symbol_a", "//m0:symbol", XPathResultType.String);
            desc.AddXPathProperty("symbol_b", "//*[local-name(.) = 'getQuote' and namespace-uri(.) = 'http://services.samples/xsd']", XPathResultType.String);
            desc.AddXPathProperty("symbol_c", "/m0:getQuote/m0:request/m0:symbol", XPathResultType.String);
            desc.RootElementName      = "getQuote";
            desc.DefaultNamespace     = "http://services.samples/xsd";
            desc.RootElementNamespace = "http://services.samples/xsd";
            desc.AddNamespacePrefix("m0", "http://services.samples/xsd");
            desc.IsXPathResolvePropertiesAbsolute = true;
            desc.IsXPathPropertyExpr = true;
            configuration.AddEventType("StockQuote", desc);
        }
Exemple #8
0
        internal static ConfigurationEventTypeXMLDOM GetConfigTestType(string additionalXPathProperty, bool isUseXPathPropertyExpression)
        {
            var eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "simpleEvent";
            eventTypeMeta.SchemaResource  = SupportContainer.Instance.ResourceManager().ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();
            eventTypeMeta.AddNamespacePrefix("ss", "samples:schemas:simpleSchema");
            eventTypeMeta.AddXPathProperty("customProp", "count(/ss:simpleEvent/ss:nested3/ss:nested4)", XPathResultType.Number);
            eventTypeMeta.IsXPathPropertyExpr = isUseXPathPropertyExpression;
            if (additionalXPathProperty != null)
            {
                eventTypeMeta.AddXPathProperty(additionalXPathProperty, "count(/ss:simpleEvent/ss:nested3/ss:nested4)", XPathResultType.Number);
            }
            return(eventTypeMeta);
        }
        public void TestNestedXMLXPathGetter()
        {
            Configuration configuration       = SupportConfigFactory.GetConfiguration();
            var           xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();

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

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            _updateListener = new SupportUpdateListener();

            String      stmt     = "select b.c as type, element1, result1 from AEvent";
            EPStatement joinView = _epService.EPAdministrator.CreateEPL(stmt);

            joinView.Events += _updateListener.Update;

            SendXMLEvent("<a><b><c></c></b></a>");
            EventBean theEvent = _updateListener.AssertOneGetNewAndReset();

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

            SendXMLEvent("<a><b></b></a>");
            theEvent = _updateListener.AssertOneGetNewAndReset();
            Assert.AreEqual(null, theEvent.Get("type"));
            Assert.AreEqual(null, theEvent.Get("element1"));

            SendXMLEvent("<a><b><c>text</c></b></a>");
            theEvent = _updateListener.AssertOneGetNewAndReset();
            Assert.AreEqual("text", theEvent.Get("type"));
            Assert.AreEqual("text", theEvent.Get("element1"));
        }
Exemple #10
0
        public void SetUp()
        {
            _container = SupportContainer.Reset();

            var schemaUrl  = _container.ResourceManager().ResolveResourceURL("regression/simpleSchema.xsd");
            var configNoNS = new ConfigurationEventTypeXMLDOM();

            configNoNS.IsXPathPropertyExpr = true;
            configNoNS.SchemaResource      = schemaUrl.ToString();
            configNoNS.RootElementName     = "simpleEvent";
            configNoNS.AddXPathProperty("customProp", "count(/ss:simpleEvent/ss:nested3/ss:nested4)", XPathResultType.Number);
            configNoNS.AddNamespacePrefix("ss", "samples:schemas:simpleSchema");
            var model = XSDSchemaMapper.LoadAndMap(
                schemaUrl.ToString(), null, SupportEngineImportServiceFactory.Make(_container),
                _container.ResourceManager());
            var eventTypeNoNS = new SchemaXMLEventType(
                null, 1, configNoNS, model, _container.Resolve <EventAdapterService>(), _container.LockManager());

            var noNSDoc = new XmlDocument();

            using (var stream = _container.ResourceManager().GetResourceAsStream("regression/simpleWithSchema.xml"))
            {
                noNSDoc.Load(stream);
            }

            _eventSchemaOne = new XMLEventBean(noNSDoc.DocumentElement, eventTypeNoNS);
        }
        public override void Run(EPServiceProvider epService)
        {
            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>";

            var desc = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName = "Event";
            desc.AddXPathProperty("A", "//Field[@Name='A']/@Value", XPathResultType.NodeSet, "string[]");
            epService.EPAdministrator.Configuration.AddEventType("Event", desc);

            EPStatement stmt           = epService.EPAdministrator.CreateEPL("select * from Event");
            var         updateListener = new SupportUpdateListener();

            stmt.Events += updateListener.Update;

            XmlDocument doc = SupportXML.GetDocument(xml);

            epService.EPRuntime.SendEvent(doc);

            EventBean theEvent = updateListener.AssertOneGetNewAndReset();

            EPAssertionUtil.AssertProps(theEvent, "A".Split(','), new object[] { new object[] { "987654321", "9876543210" } });
        }
Exemple #12
0
        private static ConfigurationEventTypeXMLDOM GetXMLDOMConfig()
        {
            var config = new ConfigurationEventTypeXMLDOM();

            config.RootElementName = "simpleEvent";
            config.AddXPathProperty("nested1", "/simpleEvent/nested1", XPathResultType.String);
            return(config);
        }
        public override void Configure(Configuration configuration)
        {
            _schemaUri = SupportContainer.Instance.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;
            configuration.EngineDefaults.ViewResources.IsIterableUnbound = true;
            configuration.AddEventType("SensorEvent", sensorcfg);
        }
        public override void Configure(Configuration configuration)
        {
            var xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();

            xmlDOMEventTypeDesc.RootElementName = "a";
            xmlDOMEventTypeDesc.AddXPathProperty("element1", "/a/b/c", XPathResultType.String);
            configuration.AddEventType("AEvent", xmlDOMEventTypeDesc);
        }
Exemple #15
0
        public override void Configure(Configuration configuration)
        {
            var typeMeta = new ConfigurationEventTypeXMLDOM();

            typeMeta.RootElementName = "a";
            typeMeta.AddXPathProperty("element1", "/a/b/c", XPathResultType.String);
            configuration.AddEventType("AEvent", typeMeta);
        }
Exemple #16
0
        public void TestElementNode()
        {
            // test for Esper-129
            var configuration = SupportConfigFactory.GetConfiguration();
            var desc          = new ConfigurationEventTypeXMLDOM();

            desc.AddXPathProperty("event.type", "//event/@type", XPathResultType.String);
            desc.AddXPathProperty("event.uid", "//event/@uid", XPathResultType.String);
            desc.RootElementName = "batch-event";
            configuration.AddEventType("MyEvent", desc);

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

            var stmt     = "select event.type as type, event.uid as uid from MyEvent";
            var joinView = _epService.EPAdministrator.CreateEPL(stmt);

            joinView.AddListener(_updateListener);

            var xml = "<batch-event>" +
                      "<event type=\"a-f-G\" uid=\"terminal.55\" time=\"2007-04-19T13:05:20.22Z\" version=\"2.0\"/>" +
                      "</batch-event>";
            var doc = new XmlDocument();

            doc.LoadXml(xml);

            var topElement = doc.DocumentElement;

            _epService.EPRuntime.SendEvent(topElement);
            var theEvent = _updateListener.AssertOneGetNewAndReset();

            Assert.AreEqual("a-f-G", theEvent.Get("type"));
            Assert.AreEqual("terminal.55", theEvent.Get("uid"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        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);
        }
Exemple #18
0
        public override void Configure(Configuration configuration)
        {
            _eventTypeMeta = new ConfigurationEventTypeXMLDOM();
            _eventTypeMeta.RootElementName = "simpleEvent";

            _eventTypeMeta.SchemaResource = SupportContainer.Instance.ResourceManager().ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();
            _eventTypeMeta.AddNamespacePrefix("ss", "samples:schemas:simpleSchema");
            _eventTypeMeta.AddXPathProperty("customProp", "count(/ss:simpleEvent/ss:nested3/ss:nested4)", XPathResultType.Number);
            configuration.AddEventType("TestXMLSchemaType", _eventTypeMeta);
        }
Exemple #19
0
        public override void Configure(Configuration configuration)
        {
            var eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "event-page-visit";
            string schemaUri = SupportContainer.Instance.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);
            configuration.AddEventType("PageVisitEvent", eventTypeMeta);
        }
Exemple #20
0
        public override void Run(EPServiceProvider epService)
        {
            var         listener = new SupportUpdateListener();
            string      stmtText = "select b.c as type, element1 from AEvent";
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(stmtText);

            stmt.Events += listener.Update;

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

            sender.SendEvent(doc);

            EventBean theEvent = listener.AssertOneGetNewAndReset();

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

            // send wrong event
            try {
                sender.SendEvent(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 '" + typeof(SupportBean).FullName + "' encountered, please supply a XmlDocument or XmlElement node", ex.Message);
            }

            // test adding a second type for the same root element
            var 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";
            EPStatement stmtTwo = epService.EPAdministrator.CreateEPL(stmtText);

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

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

            theEvent = stmtTwo.First();
            Assert.AreEqual("text", theEvent.Get("element2"));
        }
Exemple #21
0
        public void SetUp()
        {
            var simpleDoc = XDocument.Parse(Xml);

            var config = new ConfigurationEventTypeXMLDOM();

            config.RootElementName = "simpleEvent";
            config.AddXPathProperty("customProp", "count(/simpleEvent/nested3/nested4)", XPathResultType.Number);

            var eventType = new SimpleXElementType(null, 1, config, SupportEventAdapterService.Service);

            _event = new XEventBean(simpleDoc.Root, eventType);
        }
        public void TestNamespaceXPathAbsolute()
        {
            Configuration configuration = SupportConfigFactory.GetConfiguration();
            var           desc          = new ConfigurationEventTypeXMLDOM();

            desc.AddXPathProperty("symbol_a", "//m0:symbol", XPathResultType.String);
            desc.AddXPathProperty("symbol_b", "//*[local-name(.) = 'getQuote' and namespace-uri(.) = 'http://services.samples/xsd']", XPathResultType.String);
            desc.AddXPathProperty("symbol_c", "/m0:getQuote/m0:request/m0:symbol", XPathResultType.String);
            desc.RootElementName      = "getQuote";
            desc.DefaultNamespace     = "http://services.samples/xsd";
            desc.RootElementNamespace = "http://services.samples/xsd";
            desc.AddNamespacePrefix("m0", "http://services.samples/xsd");
            desc.IsXPathResolvePropertiesAbsolute = true;
            desc.IsXPathPropertyExpr = true;
            configuration.AddEventType("StockQuote", desc);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            _updateListener = new SupportUpdateListener();

            const string stmt     = "select symbol_a, symbol_b, symbol_c, request.symbol as symbol_d, symbol as symbol_e from StockQuote";
            EPStatement  joinView = _epService.EPAdministrator.CreateEPL(stmt);

            joinView.Events += _updateListener.Update;

            const string xml = "<m0:getQuote xmlns:m0=\"http://services.samples/xsd\"><m0:request><m0:symbol>IBM</m0:symbol></m0:request></m0:getQuote>";
            //String xml = "<getQuote><request><symbol>IBM</symbol></request></getQuote>";
            var doc = XDocument.Parse(xml);

            _epService.EPRuntime.SendEvent(doc.Root);
            EventBean theEvent = _updateListener.AssertOneGetNewAndReset();

            Assert.AreEqual("IBM", theEvent.Get("symbol_a"));
            Assert.AreEqual("IBM", theEvent.Get("symbol_b"));
            Assert.AreEqual("IBM", theEvent.Get("symbol_c"));
            Assert.AreEqual("IBM", theEvent.Get("symbol_d"));
            Assert.AreEqual(null, theEvent.Get("symbol_e")); // should be empty string as we are doing absolute XPath
        }
        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();
            }
        }
Exemple #24
0
        public void SetUp()
        {
            _container = SupportContainer.Reset();

            var simpleDoc = new XmlDocument();

            simpleDoc.LoadXml(Xml);

            var config = new ConfigurationEventTypeXMLDOM();

            config.RootElementName = "simpleEvent";
            config.AddXPathProperty("customProp", "count(/simpleEvent/nested3/nested4)", XPathResultType.Number);

            var eventType = new SimpleXMLEventType(null, 1, config, _container.Resolve <EventAdapterService>(), _container.LockManager());

            _theEvent = new XMLEventBean(simpleDoc.DocumentElement, eventType);
        }
        public override void Configure(Configuration configuration)
        {
            var xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();

            xmlDOMEventTypeDesc.RootElementName = "myevent";
            xmlDOMEventTypeDesc.AddXPathProperty("xpathElement1", "/myevent/element1", XPathResultType.String);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathCountE21", "count(/myevent/element2/element21)", XPathResultType.Number);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrString", "/myevent/element3/@attrString", XPathResultType.String);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrNum", "/myevent/element3/@attrNum", XPathResultType.Number);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrBool", "/myevent/element3/@attrBool", XPathResultType.Boolean);
            xmlDOMEventTypeDesc.AddXPathProperty("stringCastLong", "/myevent/element3/@attrNum", XPathResultType.String, "long");
            xmlDOMEventTypeDesc.AddXPathProperty("stringCastDouble", "/myevent/element3/@attrNum", XPathResultType.String, "double");
            xmlDOMEventTypeDesc.AddXPathProperty("numCastInt", "/myevent/element3/@attrNum", XPathResultType.Number, "int");
            xmlDOMEventTypeDesc.XPathFunctionResolver = typeof(SupportXPathFunctionResolver).FullName;
            xmlDOMEventTypeDesc.XPathVariableResolver = typeof(SupportXPathVariableResolver).FullName;
            configuration.AddEventType("TestXMLNoSchemaType", xmlDOMEventTypeDesc);

            xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();
            xmlDOMEventTypeDesc.RootElementName = "my.event2";
            configuration.AddEventType("TestXMLWithDots", xmlDOMEventTypeDesc);
        }
Exemple #26
0
        public void TestNestedXMLDOMGetter()
        {
            var configuration       = SupportConfigFactory.GetConfiguration();
            var xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();

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

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

            var stmt     = "select b.c as type, element1, result1 from AEvent";
            var joinView = _epService.EPAdministrator.CreateEPL(stmt);

            joinView.AddListener(_updateListener);

            SendXMLEvent("<a><b><c></c></b></a>");
            var theEvent = _updateListener.AssertOneGetNewAndReset();

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

            SendXMLEvent("<a><b></b></a>");
            theEvent = _updateListener.AssertOneGetNewAndReset();
            Assert.AreEqual(null, theEvent.Get("type"));
            Assert.AreEqual(null, theEvent.Get("element1"));

            SendXMLEvent("<a><b><c>text</c></b></a>");
            theEvent = _updateListener.AssertOneGetNewAndReset();
            Assert.AreEqual("text", theEvent.Get("type"));
            Assert.AreEqual("text", theEvent.Get("element1"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Exemple #27
0
        public override void Run(EPServiceProvider epService)
        {
            if (SupportConfigFactory.SkipTest(typeof(ExecEventXMLSchemaEventReplace)))
            {
                return;
            }

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

            SupportEventTypeAssertionUtil.AssertConsistency(type);

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                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);

            // update type and replace
            _eventTypeMeta.SchemaResource = SupportContainer.Instance.ResourceManager().ResolveResourceURL(CLASSLOADER_SCHEMA_VERSION2_URI).ToString();
            _eventTypeMeta.AddXPathProperty("countProp", "count(/ss:simpleEvent/ss:nested3/ss:nested4)", XPathResultType.Number);
            epService.EPAdministrator.Configuration.ReplaceXMLEventType("TestXMLSchemaType", _eventTypeMeta);

            wildStmt = epService.EPAdministrator.CreateEPL(stmtSelectWild);
            type     = wildStmt.EventType;
            SupportEventTypeAssertionUtil.AssertConsistency(type);

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                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("prop5", 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),
                new EventPropertyDescriptor("countProp", typeof(double?), null, false, false, false, false, false),
            }, type.PropertyDescriptors);
        }
        public void TestSimpleXMLXPathProperties()
        {
            Configuration configuration = SupportConfigFactory.GetConfiguration();

            ConfigurationEventTypeXMLDOM xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();

            xmlDOMEventTypeDesc.RootElementName = "myevent";
            xmlDOMEventTypeDesc.AddXPathProperty("xpathElement1", "/myevent/element1", XPathResultType.String);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathCountE21", "count(/myevent/element2/element21)", XPathResultType.Number);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrString", "/myevent/element3/@attrString", XPathResultType.String);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrNum", "/myevent/element3/@attrNum", XPathResultType.Number);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrBool", "/myevent/element3/@attrBool", XPathResultType.Boolean);
            xmlDOMEventTypeDesc.AddXPathProperty("stringCastLong", "/myevent/element3/@attrNum", XPathResultType.String, "long");
            xmlDOMEventTypeDesc.AddXPathProperty("stringCastDouble", "/myevent/element3/@attrNum", XPathResultType.String, "double");
            xmlDOMEventTypeDesc.AddXPathProperty("numCastInt", "/myevent/element3/@attrNum", XPathResultType.Number, "int");
            xmlDOMEventTypeDesc.XPathFunctionResolver = typeof(SupportXPathFunctionResolver).FullName;
            xmlDOMEventTypeDesc.XPathVariableResolver = typeof(SupportXPathVariableResolver).FullName;
            configuration.AddEventType("TestXMLNoSchemaType", xmlDOMEventTypeDesc);

            xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();
            xmlDOMEventTypeDesc.RootElementName = "my.event2";
            configuration.AddEventType("TestXMLWithDots", xmlDOMEventTypeDesc);

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

            _updateListener = new SupportUpdateListener();

            // assert type metadata
            EventTypeSPI type = (EventTypeSPI)((EPServiceProviderSPI)_epService).EventAdapterService.GetEventTypeByName("TestXMLNoSchemaType");

            Assert.AreEqual(ApplicationType.XML, type.Metadata.OptionalApplicationType);
            Assert.AreEqual(null, type.Metadata.OptionalSecondaryNames);
            Assert.AreEqual("TestXMLNoSchemaType", type.Metadata.PrimaryName);
            Assert.AreEqual("TestXMLNoSchemaType", type.Metadata.PublicName);
            Assert.AreEqual("TestXMLNoSchemaType", type.Name);
            Assert.AreEqual(TypeClass.APPLICATION, type.Metadata.TypeClass);
            Assert.AreEqual(true, type.Metadata.IsApplicationConfigured);
            Assert.AreEqual(true, type.Metadata.IsApplicationPreConfigured);
            Assert.AreEqual(true, type.Metadata.IsApplicationPreConfiguredStatic);

            EPAssertionUtil.AssertEqualsAnyOrder(new[] {
                new EventPropertyDescriptor("xpathElement1", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("xpathCountE21", typeof(double?), null, false, false, false, false, false),
                new EventPropertyDescriptor("xpathAttrString", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("xpathAttrNum", typeof(double?), null, false, false, false, false, false),
                new EventPropertyDescriptor("xpathAttrBool", typeof(bool?), null, false, false, false, false, false),
                new EventPropertyDescriptor("stringCastLong", typeof(long), null, false, false, false, false, false),
                new EventPropertyDescriptor("stringCastDouble", typeof(double), null, false, false, false, false, false),
                new EventPropertyDescriptor("numCastInt", typeof(int), null, false, false, false, false, false),
            }, type.PropertyDescriptors);

            String stmt =
                "select xpathElement1, xpathCountE21, xpathAttrString, xpathAttrNum, xpathAttrBool," +
                "stringCastLong," +
                "stringCastDouble," +
                "numCastInt " +
                "from TestXMLNoSchemaType.win:length(100)";

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

            joinView.Events += _updateListener.Update;

            // Generate document with the specified in element1 to confirm we have independent events
            SendEvent("EventA");
            AssertDataSimpleXPath("EventA");

            SendEvent("EventB");
            AssertDataSimpleXPath("EventB");

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestNamespaceXPathAbsolute()
        {
            Configuration configuration       = SupportConfigFactory.GetConfiguration();
            ConfigurationEventTypeXMLDOM desc = new ConfigurationEventTypeXMLDOM();

            desc.AddXPathProperty("symbol_a", "//m0:symbol", XPathResultType.String);
            desc.AddXPathProperty("symbol_b", "//*[local-name(.) = 'getQuote' and namespace-uri(.) = 'http://services.samples/xsd']", XPathResultType.String);
            desc.AddXPathProperty("symbol_c", "/m0:getQuote/m0:request/m0:symbol", XPathResultType.String);
            desc.RootElementName      = "getQuote";
            desc.DefaultNamespace     = "http://services.samples/xsd";
            desc.RootElementNamespace = "http://services.samples/xsd";
            desc.AddNamespacePrefix("m0", "http://services.samples/xsd");
            desc.IsXPathResolvePropertiesAbsolute = true;
            desc.IsXPathPropertyExpr = true;
            configuration.AddEventType("StockQuote", desc);

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

            _updateListener = new SupportUpdateListener();

            String      stmt     = "select symbol_a, symbol_b, symbol_c, request.symbol as symbol_d, symbol as symbol_e from StockQuote";
            EPStatement joinView = _epService.EPAdministrator.CreateEPL(stmt);

            joinView.Events += _updateListener.Update;

            String xml = "<m0:getQuote xmlns:m0=\"http://services.samples/xsd\"><m0:request><m0:symbol>IBM</m0:symbol></m0:request></m0:getQuote>";
            //String xml = "<getQuote><request><symbol>IBM</symbol></request></getQuote>";

            var doc = new XmlDocument();

            doc.LoadXml(xml);

            // For XPath resolution testing and namespaces...

            /*
             * XPathFactory xPathFactory = XPathFactory.NewInstance();
             * XPath xPath = xPathFactory.NewXPath();
             * XPathNamespaceContext ctx = new XPathNamespaceContext();
             * ctx.AddPrefix("m0", "http://services.samples/xsd");
             * xPath.NamespaceContext = ctx;
             * XPathExpression expression = xPath.Compile("/m0:getQuote/m0:request/m0:symbol");
             * xPath.NamespaceContext = ctx;
             * Console.WriteLine("result=" + expression.Evaluate(doc,XPathResultType.String));
             */

            _epService.EPRuntime.SendEvent(doc);
            EventBean theEvent = _updateListener.AssertOneGetNewAndReset();

            Assert.AreEqual("IBM", theEvent.Get("symbol_a"));
            Assert.AreEqual("IBM", theEvent.Get("symbol_b"));
            Assert.AreEqual("IBM", theEvent.Get("symbol_c"));
            Assert.AreEqual("IBM", theEvent.Get("symbol_d"));
            Assert.AreEqual(null, theEvent.Get("symbol_e"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Exemple #30
0
        public void TestXML()
        {
            Configuration configuration = SupportConfigFactory.GetConfiguration();
            var           typeMeta      = new ConfigurationEventTypeXMLDOM();

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

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

            String      stmtText = "select b.c as type, element1 from AEvent";
            EPStatement stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.Events += _listener.Update;

            XmlDocument doc    = GetDocument("<a><b><c>text</c></b></a>");
            EventSender sender = _epService.EPRuntime.GetEventSender("AEvent");

            sender.SendEvent(doc);

            EventBean theEvent = _listener.AssertOneGetNewAndReset();

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

            // send wrong event
            try
            {
                sender.SendEvent(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 'com.espertech.esper.support.bean.SupportBean' encountered, please supply a System.Xml.XmlDocument or Element 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.std:lastevent()";
            EPStatement stmtTwo = _epService.EPAdministrator.CreateEPL(stmtText);

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

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

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

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }