public void TestGet() { var schema = SchemaBuilder .Record("typename", TypeBuilder.RequiredInt("myInt")); var eventType = SupportAvroUtil.MakeAvroSupportEventType(schema); var record = new GenericRecord(schema); record.Put("myInt", 99); var eventBean = new AvroGenericDataEventBean(record, eventType); Assert.AreEqual(eventType, eventBean.EventType); Assert.AreEqual(record, eventBean.Underlying); Assert.AreEqual(99, eventBean.Get("myInt")); // test wrong property name try { eventBean.Get("dummy"); Assert.Fail(); } catch (PropertyAccessException ex) { // Expected Log.Debug(".testGetter Expected exception, msg=" + ex.Message); } }
private void AssertValuesRequired(AvroGenericDataEventBean bean) { AssertValue(10, bean, "myInt"); AssertValue("y", bean, "myString"); AssertValue(true, bean, "myBoolean"); AssertValue(new[] { (byte)170 }, bean, "myBytes"); AssertValue(50d, bean, "myDouble"); AssertValue(100f, bean, "myFloat"); AssertValue(20L, bean, "myLong"); }
private void AssertValuesNested( GenericRecord datum, AvroGenericDataEventBean bean) { Assert.AreEqual("i1", bean.Get("innerEvent.innerValue")); Assert.AreEqual("i1", bean.EventType.GetGetter("innerEvent.innerValue").Get(bean)); Assert.AreSame(datum.Get("innerEvent"), bean.Get("innerEvent")); Assert.AreSame(datum.Get("innerEvent"), bean.EventType.GetGetter("innerEvent").Get(bean)); }
private void AssertValuesNull(AvroGenericDataEventBean bean) { AssertValue(null, bean, "myInt"); AssertValue(null, bean, "myCharSeq"); AssertValue(null, bean, "myString"); AssertValue(null, bean, "myBoolean"); AssertValue(null, bean, "myBytes"); AssertValue(null, bean, "myDouble"); AssertValue(null, bean, "myFloat"); AssertValue(null, bean, "myLong"); }
private void AssertValue( Object expected, AvroGenericDataEventBean bean, String propertyName) { if (expected is byte[]) { AreEqualsBytes((byte[])expected, (byte[])bean.Get(propertyName)); var getter = bean.EventType.GetGetter(propertyName); AreEqualsBytes((byte[])expected, (byte[])getter.Get(bean)); } else { Assert.AreEqual(expected, bean.Get(propertyName)); var getter = bean.EventType.GetGetter(propertyName); Assert.AreEqual(expected, getter.Get(bean)); } }
public void TestGetPropertyType() { var lvl2Schema = SchemaBuilder.Record( "lvl2Schema", Field("nestedValue", StringType(Property(PROP_STRING_KEY, PROP_STRING_VALUE))), Field("nestedIndexed", Array(IntType())), Field("nestedMapped", Map(StringType(Property(PROP_STRING_KEY, PROP_STRING_VALUE))))); var lvl1Schema = SchemaBuilder.Record( "lvl1Schema", Field("lvl2", lvl2Schema), RequiredInt("intPrimitive"), Field("indexed", Array(IntType())), Field("mapped", Map(StringType(Property(PROP_STRING_KEY, PROP_STRING_VALUE))))); var schema = SchemaBuilder.Record( "typename", RequiredInt("myInt"), OptionalInt("myIntBoxed"), Field("myString", StringType(Property(PROP_STRING_KEY, PROP_STRING_VALUE))), Field("lvl1", lvl1Schema), Field("myNullValue", NullType())); EventType eventType = SupportAvroUtil.MakeAvroSupportEventType(schema); AssertPropertyType(typeof(int), null, eventType, "myInt"); AssertPropertyType(typeof(int?), null, eventType, "myIntBoxed"); AssertPropertyType(typeof(string), typeof(char), eventType, "myString"); AssertPropertyType(null, null, eventType, "myNullValue"); AssertPropertyType(typeof(GenericRecord), null, eventType, "lvl1"); AssertPropertyType(typeof(int), null, eventType, "lvl1.intPrimitive"); AssertPropertyType(typeof(string), typeof(char), eventType, "lvl1.lvl2.nestedValue"); AssertPropertyType(typeof(int), null, eventType, "lvl1.indexed[1]"); AssertPropertyType(typeof(string), typeof(char), eventType, "lvl1.mapped('a')"); AssertPropertyType(typeof(string), typeof(char), eventType, "lvl1.lvl2.nestedMapped('a')"); AssertPropertyType(typeof(int), null, eventType, "lvl1.lvl2.nestedIndexed[1]"); AssertNotAProperty(eventType, "dummy"); AssertNotAProperty(eventType, "lvl1.dfgdg"); AssertNotAProperty(eventType, "xxx.intPrimitive"); AssertNotAProperty(eventType, "lvl1.lvl2.nestedValueXXX"); AssertNotAProperty(eventType, "myInt[1]"); AssertNotAProperty(eventType, "lvl1.intPrimitive[1]"); AssertNotAProperty(eventType, "myInt('a')"); AssertNotAProperty(eventType, "lvl1.intPrimitive('a')"); AssertNotAProperty(eventType, "lvl1.lvl2.nestedIndexed('a')"); AssertNotAProperty(eventType, "lvl1.lvl2.nestedMapped[1]"); var lvl2Rec = new GenericRecord(lvl2Schema); lvl2Rec.Put("nestedValue", 100); lvl2Rec.Put("nestedIndexed", Collections.List(19, 21)); lvl2Rec.Put("nestedMapped", Collections.SingletonDataMap("nestedkey", "nestedvalue")); var lvl1Rec = new GenericRecord(lvl1Schema); lvl1Rec.Put("lvl2", lvl2Rec); lvl1Rec.Put("intPrimitive", 10); lvl1Rec.Put("indexed", Collections.List(1, 2, 3)); lvl1Rec.Put("mapped", Collections.SingletonDataMap("key", "value")); var record = new GenericRecord(schema); record.Put("lvl1", lvl1Rec); record.Put("myInt", 99); record.Put("myIntBoxed", 554); record.Put("myString", "hugo"); record.Put("myNullValue", null); var eventBean = new AvroGenericDataEventBean(record, eventType); Assert.AreEqual(99, eventBean.Get("myInt")); Assert.AreEqual(554, eventBean.Get("myIntBoxed")); Assert.AreEqual("hugo", eventBean.Get("myString")); Assert.AreEqual(lvl1Rec, eventBean.Get("lvl1")); Assert.AreEqual(10, eventBean.Get("lvl1.intPrimitive")); Assert.AreEqual(100, eventBean.Get("lvl1.lvl2.nestedValue")); Assert.AreEqual(2, eventBean.Get("lvl1.indexed[1]")); Assert.AreEqual("value", eventBean.Get("lvl1.mapped('key')")); Assert.AreEqual(null, eventBean.Get("myNullValue")); Assert.AreEqual("nestedvalue", eventBean.Get("lvl1.lvl2.nestedMapped('nestedkey')")); Assert.AreEqual(21, eventBean.Get("lvl1.lvl2.nestedIndexed[1]")); }