AvroUtils { public static Schema toSchema(String typeName) { Schema schema = null; if(typeName.startsWith(primitiveTypePrefix)){ String shortName = typeName.substring( primitiveTypePrefix.length(), typeName.length()); schema = getPrimitiveTypeSchema(shortName); } else { schema = getAvroClassSchema(typeName); } return schema; } private  AvroUtils(); static Schema toSchema(String typeName); static T getCopy(T object, Schema schema, Class<T> type); final static String primitiveTypePrefix; }
@Test(expected=IllegalArgumentException.class) public void testToSchemaForNotExistingPrimitive() throws Exception { AvroUtils.toSchema("org.apache.avro.Schema.Type.NON_EXISTING"); }
@Test public void testToSchemaForPrimitive() throws Exception { Schema schema = AvroUtils.toSchema("org.apache.avro.Schema.Type.STRING"); assertNotNull(schema); assertTrue(schema.equals(Schema.create(Schema.Type.STRING))); }
@Test(expected=RuntimeException.class) public void testToSchemaForNonExistingAvroClass() throws Exception { AvroUtils.toSchema("non.existing.Class"); }
@Test public void testToSchemaForAvroClass() throws Exception { Schema schema = AvroUtils.toSchema(Identifier.class.getCanonicalName()); assertNotNull(schema); assertTrue(schema == Identifier.SCHEMA$); }