Esempio n. 1
0
        public void TestGetGetter()
        {
            var nestedSupportBean = new SupportBean();

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

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

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

            valuesMap["MyInt"]                 = 20;
            valuesMap["MyString"]              = "a";
            valuesMap["mySupportBean"]         = nestedSupportBean;
            valuesMap["myComplexBean"]         = complexPropBean;
            valuesMap["myNullableSupportBean"] = null;
            valuesMap["myNullableString"]      = null;
            EventBean eventBean = new MapEventBean(valuesMap, _eventType);

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

            try
            {
                eventBean = SupportEventBeanFactory.CreateObject(new Object());
                getter.Get(eventBean);
                Assert.IsTrue(false);
            }
            catch (InvalidCastException ex)
            {
                // Expected
                Log.Debug(".testGetGetter Expected exception, msg=" + ex.Message);
            }
        }
Esempio n. 2
0
        public void SetUp()
        {
            _testTypesMap                  = new Dictionary <String, Object>();
            _testTypesMap["aString"]       = typeof(string);
            _testTypesMap["anInt"]         = typeof(int);
            _testTypesMap["myComplexBean"] = typeof(SupportBeanComplexProps);

            _testValuesMap                  = new Dictionary <String, Object>();
            _testValuesMap["aString"]       = "test";
            _testValuesMap["anInt"]         = 10;
            _testValuesMap["myComplexBean"] = _supportBean;

            _eventType = new MapEventType(null, "", 1, SupportEventAdapterService.Service, _testTypesMap, null, null, null);
            _eventBean = new MapEventBean(_testValuesMap, _eventType);
        }
Esempio n. 3
0
        public void SetUp()
        {
            _testTypesMap                  = new Dictionary <String, Object>();
            _testTypesMap["aString"]       = typeof(string);
            _testTypesMap["anInt"]         = typeof(int);
            _testTypesMap["myComplexBean"] = typeof(SupportBeanComplexProps);

            _testValuesMap                  = new Dictionary <String, Object>();
            _testValuesMap["aString"]       = "test";
            _testValuesMap["anInt"]         = 10;
            _testValuesMap["myComplexBean"] = _supportBean;

            EventTypeMetadata metadata = EventTypeMetadata.CreateNonPonoApplicationType(ApplicationType.MAP, "testtype", true, true, true, false, false);

            _eventType = new MapEventType(metadata, "", 1, SupportEventAdapterService.Service, _testTypesMap, null, null, null);
            _eventBean = new MapEventBean(_testValuesMap, _eventType);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
            }
        }