Example #1
0
        public void SetUp()
        {
            testTypesMap = new Dictionary <string, object>();
            testTypesMap.Put("aString", typeof(string));
            testTypesMap.Put("anInt", typeof(int?));
            testTypesMap.Put("MyComplexBean", typeof(SupportBeanComplexProps));

            testValuesMap = new Dictionary <string, object>();
            testValuesMap.Put("aString", "test");
            testValuesMap.Put("anInt", 10);
            testValuesMap.Put("MyComplexBean", supportBean);

            EventTypeMetadata metadata = new EventTypeMetadata("MyType", null, EventTypeTypeClass.STREAM, EventTypeApplicationType.MAP, NameAccessModifier.INTERNAL, EventTypeBusModifier.NONBUS, false, EventTypeIdPair.Unassigned());

            eventType = new MapEventType(metadata, testTypesMap, null, null, null, null,
                                         SupportEventTypeFactory.GetInstance(container).BEAN_EVENT_TYPE_FACTORY);
            eventBean = new MapEventBean(testValuesMap, eventType);
        }
Example #2
0
        public void TestGetGetter()
        {
            var nestedSupportBean = new SupportBean();

            nestedSupportBean.IntPrimitive = 100;
            var complexPropBean = SupportBeanComplexProps.MakeDefaultBean();

            Assert.AreEqual(null, eventType.GetGetter("dummy"));

            IDictionary <string, object> valuesMap = new Dictionary <string, object>();

            valuesMap.Put("MyInt", 20);
            valuesMap.Put("MyString", "a");
            valuesMap.Put("MySupportBean", nestedSupportBean);
            valuesMap.Put("MyComplexBean", complexPropBean);
            valuesMap.Put("MyNullableSupportBean", null);
            valuesMap.Put("MyNullableString", null);
            EventBean eventBean = new MapEventBean(valuesMap, eventType);

            var getter = eventType.GetGetter("MyInt");

            Assert.AreEqual(20, getter.Get(eventBean));

            getter = eventType.GetGetter("MyString");
            Assert.AreEqual("a", getter.Get(eventBean));

            getter = eventType.GetGetter("MyNullableString");
            Assert.IsNull(getter.Get(eventBean));

            getter = eventType.GetGetter("MySupportBean");
            Assert.AreEqual(nestedSupportBean, getter.Get(eventBean));

            getter = eventType.GetGetter("MySupportBean.IntPrimitive");
            Assert.AreEqual(100, getter.Get(eventBean));

            getter = eventType.GetGetter("MyNullableSupportBean.IntPrimitive");
            Assert.IsNull(getter.Get(eventBean));

            getter = eventType.GetGetter("MyComplexBean.Nested.NestedValue");
            Assert.AreEqual("NestedValue", getter.Get(eventBean));
        }
Example #3
0
        public void TestCreateUnderlying()
        {
            SupportBean   beanOne = new SupportBean();
            SupportBean_A beanTwo = new SupportBean_A("a");

            // Set up event type
            testTypesMap.Clear();
            testTypesMap.Put("a", typeof(SupportBean));
            testTypesMap.Put("b", typeof(SupportBean_A));
            EventTypeMetadata metadata  = new EventTypeMetadata("MyType", null, EventTypeTypeClass.STREAM, EventTypeApplicationType.MAP, NameAccessModifier.INTERNAL, EventTypeBusModifier.NONBUS, false, EventTypeIdPair.Unassigned());
            EventType         eventType = new MapEventType(metadata, testTypesMap, null, null, null, null,
                                                           SupportEventTypeFactory.GetInstance(container).BEAN_EVENT_TYPE_FACTORY);

            IDictionary <string, object> events = new Dictionary <string, object>();

            events.Put("a", beanOne);
            events.Put("b", beanTwo);

            MapEventBean theEvent = new MapEventBean(events, eventType);

            Assert.AreSame(theEvent.Get("a"), beanOne);
            Assert.AreSame(theEvent.Get("b"), beanTwo);
        }
Example #4
0
        public void TestNestedMap()
        {
            IDictionary <string, object> levelThree = new Dictionary <string, object>();

            levelThree.Put("simpleThree", typeof(long));
            levelThree.Put("objThree", typeof(SupportBean_D));
            levelThree.Put("nodefmapThree", typeof(IDictionary <string, object>));

            IDictionary <string, object> levelTwo = new Dictionary <string, object>();

            levelTwo.Put("simpleTwo", typeof(float));
            levelTwo.Put("objTwo", typeof(SupportBean_C));
            levelTwo.Put("nodefmapTwo", typeof(IDictionary <string, object>));
            levelTwo.Put("mapTwo", levelThree);

            IDictionary <string, object> levelOne = new Dictionary <string, object>();

            levelOne.Put("simpleOne", typeof(int?));
            levelOne.Put("objOne", typeof(SupportBean_B));
            levelOne.Put("nodefmapOne", typeof(IDictionary <string, object>));
            levelOne.Put("mapOne", levelTwo);

            IDictionary <string, object> levelZero = new Dictionary <string, object>();

            levelZero.Put("simple", typeof(double?));
            levelZero.Put("obj", typeof(SupportBean_A));
            levelZero.Put("nodefmap", typeof(IDictionary <string, object>));
            levelZero.Put("map", levelOne);

            var metadata = new EventTypeMetadata(
                "MyType",
                null,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.MAP,
                NameAccessModifier.INTERNAL,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var mapType  = new MapEventType(metadata, levelZero, null, null, null, null, supportEventTypeFactory.BEAN_EVENT_TYPE_FACTORY);
            var testData = GetTestData();
            var theEvent = new MapEventBean(testData, mapType);

            object[][] expected =
            {
                new object[] { "map.mapOne.simpleTwo",          typeof(float?),                                 300f },
                new object[] { "nodefmap.item?",                typeof(object),             "|nodefmap.item|"        },
                new object[] { "map.objOne",                    typeof(SupportBean_B),      new SupportBean_B("B1")  },
                new object[] { "map.simpleOne",                 typeof(int?),                                     20 },
                new[]        {
                    "map.mapOne", typeof(IDictionary <string, object>),
                    testData.Get("map").AsDataMap().Get("mapOne")
                },
                new object[] { "map.mapOne.objTwo",             typeof(SupportBean_C),      new SupportBean_C("C1")  },
                new[]        {
                    "map.mapOne.mapTwo", typeof(IDictionary <string, object>),
                    testData.Get("map").AsDataMap().Get("mapOne").AsDataMap().Get("mapTwo")
                },
                new object[] { "map.mapOne.mapTwo.simpleThree", typeof(long?),                                 4000L },
                new object[] { "map.mapOne.mapTwo.objThree",    typeof(SupportBean_D),      new SupportBean_D("D1")  },
                new object[] { "simple",                        typeof(double?),                                  1d },
                new object[] { "obj",                           typeof(SupportBean_A),      new SupportBean_A("A1")  },
                new[]        { "nodefmap",                      typeof(IDictionary <string, object>), testData.Get("nodefmap")},
                new[]        { "map",                           typeof(IDictionary <string, object>), testData.Get("map")}
            };

            // assert getter available for all properties
            for (var i = 0; i < expected.Length; i++)
            {
                var propName = (string)expected[i][0];
                Assert.IsNotNull(mapType.GetGetter(propName), "failed for property:" + propName);
            }

            // assert property types
            for (var i = 0; i < expected.Length; i++)
            {
                var propName    = (string)expected[i][0];
                var propType    = (Type)expected[i][1];
                var mapPropType = mapType.GetPropertyType(propName);
                Assert.AreEqual(propType, mapPropType, "failed for property:" + propName);
            }

            // assert property names
            string[] expectedPropNames = { "simple", "obj", "map", "nodefmap" };
            var      receivedPropNames = mapType.PropertyNames;

            EPAssertionUtil.AssertEqualsAnyOrder(expectedPropNames, receivedPropNames);

            // assert get value through (1) type getter  (2) event-get
            for (var i = 0; i < expected.Length; i++)
            {
                var propName      = (string)expected[i][0];
                var valueExpected = expected[i][2];
                Assert.AreEqual(valueExpected, mapType.GetGetter(propName).Get(theEvent), "failed for property type-getter:" + propName);
                Assert.AreEqual(valueExpected, theEvent.Get(propName), "failed for property event-getter:" + propName);
            }

            // assert access to objects nested within
            expected = new[] {
                new object[] { "map.objOne.Id", typeof(string), "B1" },
                new object[] { "map.mapOne.objTwo.Id", typeof(string), "C1" },
                new object[] { "obj.Id", typeof(string), "A1" }
            };
            for (var i = 0; i < expected.Length; i++)
            {
                var propName      = (string)expected[i][0];
                var propType      = (Type)expected[i][1];
                var valueExpected = expected[i][2];
                var getter        = mapType.GetGetter(propName);
                Assert.AreEqual(propType, mapType.GetPropertyType(propName), "failed for property:" + propName);
                Assert.AreEqual(valueExpected, getter.Get(theEvent), "failed for property type-getter:" + propName);
                Assert.AreEqual(valueExpected, theEvent.Get(propName), "failed for property event-getter:" + propName);
            }
        }