Пример #1
0
        public void TestEquals()
        {
            EventTypeMetadata metadata = EventTypeMetadata.CreateNonPonoApplicationType(
                ApplicationType.MAP, "", true, true, true,
                false, false);

            IDictionary <String, Object> mapTwo = new LinkedHashMap <String, Object>();

            mapTwo["MyInt"]                 = typeof(int);
            mapTwo["mySupportBean"]         = typeof(SupportBean);
            mapTwo["myNullableSupportBean"] = typeof(SupportBean);
            mapTwo["myComplexBean"]         = typeof(SupportBeanComplexProps);
            Assert.IsFalse(
                (new MapEventType(metadata, "", 1, _eventAdapterService, mapTwo, null, null, null)).Equals(_eventType));
            mapTwo["MyString"]         = typeof(string);
            mapTwo["myNullableString"] = typeof(string);
            mapTwo["myNullType"]       = null;

            // compare, should equal
            Assert.IsTrue(
                new MapEventType(metadata, "", 1, _eventAdapterService, mapTwo, null, null, null).EqualsCompareType(
                    _eventType));
            Assert.IsFalse(
                (new MapEventType(metadata, "google", 1, _eventAdapterService, mapTwo, null, null, null)).
                EqualsCompareType(_eventType));

            mapTwo["xx"] = typeof(int);
            Assert.IsFalse(
                _eventType.EqualsCompareType(new MapEventType(metadata, "", 1, _eventAdapterService, mapTwo, null, null,
                                                              null)));
            mapTwo.Remove("xx");
            Assert.IsTrue(
                _eventType.EqualsCompareType(new MapEventType(metadata, "", 1, _eventAdapterService, mapTwo, null, null,
                                                              null)));

            mapTwo["MyInt"] = typeof(int?);
            Assert.IsTrue(
                _eventType.EqualsCompareType(new MapEventType(metadata, "", 1, _eventAdapterService, mapTwo, null, null,
                                                              null)));
            mapTwo.Remove("MyInt");
            Assert.IsFalse(
                _eventType.EqualsCompareType(new MapEventType(metadata, "", 1, _eventAdapterService, mapTwo, null, null,
                                                              null)));
            mapTwo["MyInt"] = typeof(int);
            Assert.IsTrue(
                _eventType.EqualsCompareType(new MapEventType(metadata, "", 1, _eventAdapterService, mapTwo, null, null,
                                                              null)));

            // Test boxed and primitive compatible
            IDictionary <String, Object> mapOne = new LinkedHashMap <String, Object>();

            mapOne["MyInt"] = typeof(int);
            mapTwo          = new LinkedHashMap <String, Object>();
            mapTwo["MyInt"] = typeof(int);

            Assert.IsTrue(
                new MapEventType(metadata, "T1", 1, _eventAdapterService, mapOne, null, null, null).EqualsCompareType(
                    new MapEventType(metadata, "T1", 1, _eventAdapterService, mapTwo, null, null, null)));
        }
Пример #2
0
        public static AvroEventType MakeAvroSupportEventType(Schema schema)
        {
            var metadata = EventTypeMetadata.CreateNonPonoApplicationType(
                ApplicationType.AVRO, "typename", true, true, true, false, false);

            return(new AvroEventType(
                       metadata, "typename", 1, SupportEventAdapterService.Service, schema.AsRecordSchema(), null, null, null, null));
        }
Пример #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);
        }
Пример #4
0
        public void SetUp()
        {
            _eventAdapterService = SupportEventAdapterService.Service;

            EventTypeMetadata metadata = EventTypeMetadata.CreateNonPonoApplicationType(ApplicationType.OBJECTARR, "typename", true, true, true, false, false);

            String[] names = { "myInt", "myIntBoxed", "myString", "mySupportBean", "myComplexBean", "myNullType" };
            Object[] types = { typeof(int), typeof(int?), typeof(string), typeof(SupportBean), typeof(SupportBeanComplexProps), null };

            IDictionary <String, Object> namesAndTypes = new LinkedHashMap <String, Object>();

            for (int i = 0; i < names.Length; i++)
            {
                namesAndTypes.Put(names[i], types[i]);
            }

            _eventType = new ObjectArrayEventType(metadata, "typename", 1, _eventAdapterService, namesAndTypes, null, null, null);
        }
Пример #5
0
        public void SetUp()
        {
            _testProps = new String[] { "aString", "anInt", "myComplexBean" };
            _testTypes = new Object[] { typeof(String), typeof(int), typeof(SupportBeanComplexProps) };
            IDictionary <String, Object> typeRep = new LinkedHashMap <String, Object>();

            for (int i = 0; i < _testProps.Length; i++)
            {
                typeRep.Put(_testProps[i], _testTypes[i]);
            }

            _testValues = new Object[] { "test", 10, _supportBean };

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

            _eventType = new ObjectArrayEventType(metadata, "", 1, SupportEventAdapterService.Service, typeRep, null, null, null);
            _eventBean = new ObjectArrayEventBean(_testValues, _eventType);
        }
Пример #6
0
        public void SetUp()
        {
            _eventAdapterService = SupportEventAdapterService.Service;

            EventTypeMetadata metadata = EventTypeMetadata.CreateNonPonoApplicationType(
                ApplicationType.MAP, "typename", true, true,
                true, false, false);
            IDictionary <String, Object> testTypesMap = new Dictionary <String, Object>();

            testTypesMap["MyInt"]                 = typeof(int);
            testTypesMap["MyString"]              = typeof(string);
            testTypesMap["myNullableString"]      = typeof(string);
            testTypesMap["mySupportBean"]         = typeof(SupportBean);
            testTypesMap["myComplexBean"]         = typeof(SupportBeanComplexProps);
            testTypesMap["myNullableSupportBean"] = typeof(SupportBean);
            testTypesMap["myNullType"]            = null;
            _eventType = new MapEventType(metadata, "", 1, _eventAdapterService, testTypesMap, null, null, null);
        }
Пример #7
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);
            }
        }