public void testAnnotationAvroStringableFields() throws Exception { check(RAvroStringableField.class, "{\"type\":\"record\",\"name\":\"RAvroNameCollide\",\"namespace\":" +"\"org.apache.avro.reflect.TestReflect\",\"fields\":[" +"{\"name\":\"a\",\"type\":\"String\"}]}"); }
private void check(Object o, String schemaJson) { check(o.getClass(), schemaJson); }
@Test public void testAvroAliasOnClass() { check(AliasA.class, "{\"type\":\"record\",\"name\":\"AliasA\",\"namespace\":\"org.apache.avro.reflect.TestReflect\",\"fields\":[],\"aliases\":[\"b.a\"]}"); check(AliasB.class, "{\"type\":\"record\",\"name\":\"AliasB\",\"namespace\":\"org.apache.avro.reflect.TestReflect\",\"fields\":[],\"aliases\":[\"a\"]}"); check(AliasC.class, "{\"type\":\"record\",\"name\":\"AliasC\",\"namespace\":\"org.apache.avro.reflect.TestReflect\",\"fields\":[],\"aliases\":[\"a\"]}"); }
@Test public void testList() throws Exception { check(R1.class.getDeclaredField("listField").getGenericType(), "{\"type\":\"array\",\"items\":\"string\"" +",\"java-class\":\"java.util.List\"}"); }
@Test public void testRecord() throws Exception { check(R.class, "{\"type\":\"record\",\"name\":\"R\",\"namespace\":" +"\"org.apache.avro.reflect.TestReflect\",\"fields\":[" +"{\"name\":\"a\",\"type\":\"int\"}," +"{\"name\":\"b\",\"type\":\"long\"}]}"); }
@Test public void testAnnotationAvroName() throws Exception { check(RAvroName.class, "{\"type\":\"record\",\"name\":\"RAvroName\",\"namespace\":" +"\"org.apache.avro.reflect.TestReflect\",\"fields\":[" +"{\"name\":\"b\",\"type\":\"int\"}]}"); }
@Test public void testArray() throws Exception { check(R1.class.getDeclaredField("arrayField").getGenericType(), "{\"type\":\"array\",\"items\":\"string\",\"java-class\":\"[Ljava.lang.String;\"}"); } @Test public void testList() throws Exception {
@Test public void testAnnotationAvroMeta() throws Exception { check(RAvroMeta.class, "{\"type\":\"record\",\"name\":\"RAvroMeta\",\"namespace\":" +"\"org.apache.avro.reflect.TestReflect\",\"fields\":[" +"{\"name\":\"a\",\"type\":\"int\",\"K\":\"V\"}]}"); }
@Test(expected=Exception.class) public void testAnnotationAvroNameCollide() throws Exception { check(RAvroNameCollide.class, "{\"type\":\"record\",\"name\":\"RAvroNameCollide\",\"namespace\":" +"\"org.apache.avro.reflect.TestReflect\",\"fields\":[" +"{\"name\":\"b\",\"type\":\"int\"}," +"{\"name\":\"b\",\"type\":\"int\"}]}"); }
@Test public void testAvroDefault() { check(DefaultTest.class, "{\"type\":\"record\",\"name\":\"DefaultTest\"," +"\"namespace\":\"org.apache.avro.reflect.TestReflect\",\"fields\":[" +"{\"name\":\"foo\",\"type\":\"int\",\"default\":1}]}"); }
@Test public void testAvroDoc() { check(DocTest.class, "{\"type\":\"record\",\"name\":\"DocTest\",\"namespace\":\"org.apache.avro.reflect.TestReflect\"," + "\"doc\":\"DocTest class docs\"," + "\"fields\":[{\"name\":\"foo\",\"type\":\"int\",\"doc\":\"Some Documentation\"}," + "{\"name\":\"enums\",\"type\":{\"type\":\"enum\",\"name\":\"DocTestEnum\"," + "\"symbols\":[\"ENUM_1\",\"ENUM_2\"]},\"doc\":\"Some other Documentation\"}," + "{\"name\":\"defaultTest\",\"type\":{\"type\":\"record\",\"name\":\"DefaultTest\"," + "\"fields\":[{\"name\":\"foo\",\"type\":\"int\",\"default\":1}]},\"doc\":\"And again\"}]}"); }
@Test public void testMap() throws Exception { check(R1.class.getDeclaredField("mapField").getGenericType(), "{\"type\":\"map\",\"values\":\"string\"}"); }
@Test public void testAnnotationAvroIgnore() throws Exception { check(RAvroIgnore.class, "{\"type\":\"record\",\"name\":\"RAvroIgnore\",\"namespace\":" +"\"org.apache.avro.reflect.TestReflect\",\"fields\":[]}"); }
@Test public void testAvroAliasOnField() { Schema expectedSchema = SchemaBuilder.record(ClassWithAliasOnField.class.getSimpleName()) .namespace("org.apache.avro.reflect.TestReflect").fields().name("primitiveField").aliases("aliasName") .type(Schema.create(org.apache.avro.Schema.Type.INT)).noDefault().endRecord(); check(ClassWithAliasOnField.class, expectedSchema.toString()); }