コード例 #1
0
        public override void Run(EPServiceProvider epService)
        {
            // Note that XPath Node results when transposed must be queried by XPath that is also absolute.
            // For example: "nested1" => "/n0:simpleEvent/n0:nested1" results in a Node.
            // That result Node's "prop1" =>  "/n0:simpleEvent/n0:nested1/n0:prop1" and "/n0:nested1/n0:prop1" does NOT result in a value.
            // Therefore property transposal is disabled for Property-XPath expressions.
            var eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "simpleEvent";
            string schemaUri = SupportContainer.Instance.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#lastevent");

            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());
        }
コード例 #2
0
        public void TestExpressionSimpleXPathGetter()
        {
            var eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "simpleEvent";
            var 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
            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, 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());
        }
コード例 #3
0
        public void TestNamespaceXPathRelative()
        {
            Configuration configuration = SupportConfigFactory.GetConfiguration();
            var           desc          = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName      = "getQuote";
            desc.DefaultNamespace     = "http://services.samples/xsd";
            desc.RootElementNamespace = "http://services.samples/xsd";
            desc.AddNamespacePrefix("m0", "http://services.samples/xsd");
            desc.IsXPathResolvePropertiesAbsolute = false;
            desc.IsXPathPropertyExpr = true;
            configuration.AddEventType("StockQuote", desc);

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

            String      stmt     = "select request.symbol as symbol_a, symbol as symbol_b 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>";
            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"));
        }
コード例 #4
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);
        }
コード例 #5
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();
            }
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
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();
            }
        }
コード例 #9
0
        public override void Configure(Configuration configuration)
        {
            var desc = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName      = "getQuote";
            desc.DefaultNamespace     = "http://services.samples/xsd";
            desc.RootElementNamespace = "http://services.samples/xsd";
            desc.AddNamespacePrefix("m0", "http://services.samples/xsd");
            desc.IsXPathResolvePropertiesAbsolute = false;
            desc.IsXPathPropertyExpr = true;
            configuration.AddEventType("StockQuote", desc);
        }
コード例 #10
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);
        }
コード例 #11
0
        public override void Configure(Configuration configuration)
        {
            var desc = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName = "simpleEvent";
            string schemaUri = SupportContainer.Instance.ResourceManager().ResolveResourceURL(ExecEventXMLSchemaXPathBacked.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);
        }
コード例 #12
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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        public void TestNamespaceXPathRelative()
        {
            var configuration = SupportConfigFactory.GetConfiguration();
            var desc          = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName      = "getQuote";
            desc.DefaultNamespace     = "http://services.samples/xsd";
            desc.RootElementNamespace = "http://services.samples/xsd";
            desc.AddNamespacePrefix("m0", "http://services.samples/xsd");
            desc.IsXPathResolvePropertiesAbsolute = false;
            desc.IsXPathPropertyExpr = true;
            configuration.AddEventType("StockQuote", desc);

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

            var stmt     = "select request.symbol as symbol_a, symbol as symbol_b from StockQuote";
            var joinView = _epService.EPAdministrator.CreateEPL(stmt);

            joinView.AddListener(_updateListener);

            var xml = "<m0:getQuote xmlns:m0=\"http://services.samples/xsd\"><m0:request><m0:symbol>IBM</m0:symbol></m0:request></m0:getQuote>";
            var doc = new XmlDocument();

            doc.LoadXml(xml);

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

            Assert.AreEqual("IBM", theEvent.Get("symbol_a"));
            Assert.AreEqual("IBM", theEvent.Get("symbol_b"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
コード例 #16
0
        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
        }
コード例 #17
0
        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();
            }
        }
コード例 #18
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"));
        }
コード例 #19
0
        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();
            }
        }
コード例 #20
0
        public override void Run(EPServiceProvider epService)
        {
            var rootMeta = new ConfigurationEventTypeXMLDOM();

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

            var metaNested = new ConfigurationEventTypeXMLDOM();

            metaNested.RootElementName = "nested1";
            epService.EPAdministrator.Configuration.AddEventType("MyNestedEvent", metaNested);

            var metaNestedArray = new ConfigurationEventTypeXMLDOM();

            metaNestedArray.RootElementName = "nested4";
            epService.EPAdministrator.Configuration.AddEventType("MyNestedArrayEvent", metaNestedArray);

            EPStatement stmtInsert   = epService.EPAdministrator.CreateEPL("insert into Nested3Stream select nested1simple, nested4array from MyXMLEvent");
            EPStatement stmtWildcard = epService.EPAdministrator.CreateEPL("select * from MyXMLEvent");

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

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

            Assert.IsFalse(fragmentTypeNested1.IsIndexed);
            Assert.AreEqual(0, fragmentTypeNested1.FragmentType.PropertyDescriptors.Count);
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentTypeNested1.FragmentType);

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

            Assert.IsTrue(fragmentTypeNested4.IsIndexed);
            Assert.AreEqual(0, fragmentTypeNested4.FragmentType.PropertyDescriptors.Count);
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentTypeNested4.FragmentType);

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

            EventBean received = stmtInsert.First();

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

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

            SupportEventTypeAssertionUtil.AssertConsistency(wildcardStmtEvent);

            FragmentEventType 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);
            EventBean[] 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);
        }