Example #1
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);
        }
        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();
            }
        }
Example #3
0
        public void TestNoSchemaDOMGetter()
        {
            var configuration = SupportConfigFactory.GetConfiguration();
            var desc          = new ConfigurationEventTypeXMLDOM();

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

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

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

            stmt.Events += _listener.Update;

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

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

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

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Example #4
0
        public void TestSchemaXMLWSchemaWithRestriction()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();
            ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "order";

            var schemaStream = ResourceManager.GetResourceAsStream(CLASSLOADER_SCHEMA_WITH_RESTRICTION_URI);

            Assert.NotNull(schemaStream);

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

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

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

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

            _updateListener = new SupportUpdateListener();

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

            stmt.Events += _updateListener.Update;

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

            Assert.AreEqual(typeof(double), theEvent.Get("order_amount").GetType());
            Assert.AreEqual(202.1d, theEvent.Get("order_amount"));
            _updateListener.Reset();
        }