Exemplo n.º 1
0
        public void TestCreateUnderlying()
        {
            SupportBean   beanOne = new SupportBean();
            SupportBean_A beanTwo = new SupportBean_A("a");

            // Set up event type
            _testTypesMap.Clear();
            _testTypesMap["a"] = typeof(SupportBean);
            _testTypesMap["b"] = typeof(SupportBean_A);
            EventType eventType = SupportEventAdapterService.Service.CreateAnonymousMapType("test", _testTypesMap, true);

            IDictionary <String, Object> events = new Dictionary <String, Object>();

            events["a"] = beanOne;
            events["b"] = beanTwo;

            MapEventBean theEvent = new MapEventBean(events, eventType);

            Assert.AreSame(theEvent.Get("a"), beanOne);
            Assert.AreSame(theEvent.Get("b"), beanTwo);
        }
Exemplo n.º 2
0
        public void TestGet()
        {
            Assert.AreEqual(_eventType, _eventBean.EventType);
            Assert.AreEqual(_testValuesMap, _eventBean.Underlying);

            Assert.AreEqual("test", _eventBean.Get("aString"));
            Assert.AreEqual(10, _eventBean.Get("anInt"));

            Assert.AreEqual("NestedValue", _eventBean.Get("myComplexBean.Nested.NestedValue"));

            // test wrong property name
            try
            {
                _eventBean.Get("dummy");
                Assert.IsTrue(false);
            }
            catch (PropertyAccessException ex)
            {
                // Expected
                log.Debug(".testGetter Expected exception, msg=" + ex.Message);
            }
        }
Exemplo n.º 3
0
        public void TestNestedMap()
        {
            IDictionary <String, Object> levelThree = new Dictionary <String, Object>();

            levelThree["simpleThree"]   = typeof(long);
            levelThree["objThree"]      = typeof(SupportBean_D);
            levelThree["nodefmapThree"] = typeof(Map);

            IDictionary <String, Object> levelTwo = new Dictionary <String, Object>();

            levelTwo["simpleTwo"]   = typeof(float);
            levelTwo["objTwo"]      = typeof(SupportBean_C);
            levelTwo["nodefmapTwo"] = typeof(Map);
            levelTwo["mapTwo"]      = levelThree;

            IDictionary <String, Object> levelOne = new Dictionary <String, Object>();

            levelOne["simpleOne"]   = typeof(int);
            levelOne["objOne"]      = typeof(SupportBean_B);
            levelOne["nodefmapOne"] = typeof(Map);
            levelOne["mapOne"]      = levelTwo;

            IDictionary <String, Object> levelZero = new Dictionary <String, Object>();

            levelZero["simple"]   = typeof(double);
            levelZero["obj"]      = typeof(SupportBean_A);
            levelZero["nodefmap"] = typeof(Map);
            levelZero["map"]      = levelOne;

            EventTypeMetadata metadata = EventTypeMetadata.CreateNonPonoApplicationType(ApplicationType.MAP, "testtype", true, true, true, false, false);
            MapEventType      mapType  = new MapEventType(metadata, "M1", 1, _eventAdapterService, levelZero, null, null, null);

            IDictionary <String, Object> testData = GetTestData();
            var theEvent = new MapEventBean(testData, mapType);

            var expected = new[]
            {
                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 object[] { "map.mapOne", typeof(Map), ((Map)testData.Get("map")).Get("mapOne") },
                new object[] { "map.mapOne.objTwo", typeof(SupportBean_C), new SupportBean_C("C1") },
                new object[] { "map.mapOne.mapTwo", typeof(Map), ((Map)((Map)testData.Get("map")).Get("mapOne")).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 object[] { "nodefmap", typeof(Map), testData.Get("nodefmap") },
                new object[] { "map", typeof(Map), testData.Get("map") },
            };

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

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

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

            EPAssertionUtil.AssertEqualsAnyOrder(expectedPropNames, receivedPropNames);

            // assert get value through (1) type getter  (2) event-get
            for (int i = 0; i < expected.Length; i++)
            {
                var    propName      = (String)expected[i][0];
                Object 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 (int i = 0; i < expected.Length; i++)
            {
                var    propName            = (String)expected[i][0];
                var    propType            = (Type)expected[i][1];
                object valueExpected       = expected[i][2];
                EventPropertyGetter 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);
            }
        }