use of com.linkedin.avroutil1.parser.avsc.AvscParser in project avro-util by linkedin.
the class AvscParserTest method testResolveReferencesWithNullNamespace.
@Test
public void testResolveReferencesWithNullNamespace() throws IOException {
String referencingAvsc = TestUtil.load("schemas/TestRecordWithInternalNullNamespaceReference.avsc");
AvscParser parser = new AvscParser();
AvscParseResult result1 = parser.parse(referencingAvsc);
AvroRecordSchema schema = (AvroRecordSchema) result1.getTopLevelSchema();
Assert.assertNotNull(schema.getField("testField").getSchema());
}
use of com.linkedin.avroutil1.parser.avsc.AvscParser in project avro-util by linkedin.
the class SpecificRecordClassGeneratorTest method testHugeEnum.
@Test
public void testHugeEnum() throws Exception {
String avsc = TestUtil.load("schemas/SimpleEnumWithHugeDoc.avsc");
SpecificRecordClassGenerator generator = new SpecificRecordClassGenerator();
AvscParser parser = new AvscParser();
AvscParseResult result = parser.parse(avsc);
Assert.assertNull(result.getParseError());
AvroEnumSchema enumSchema = (AvroEnumSchema) result.getTopLevelSchema();
Assert.assertNotNull(enumSchema);
JavaFileObject javaSourceFile = generator.generateSpecificRecordClass(enumSchema, SpecificRecordGenerationConfig.BROAD_COMPATIBILITY);
CompilerHelper.assertCompiles(javaSourceFile);
}
use of com.linkedin.avroutil1.parser.avsc.AvscParser in project avro-util by linkedin.
the class AvscParserTest method testParsingHorribleLogicalTypes.
@Test
public void testParsingHorribleLogicalTypes() throws Exception {
String avsc = TestUtil.load("schemas/TestRecordWithHorribleLogicalTypes.avsc");
AvscParser parser = new AvscParser();
AvscParseResult result = parser.parse(avsc);
Assert.assertNull(result.getParseError());
AvroRecordSchema schema = (AvroRecordSchema) result.getTopLevelSchema();
for (AvroSchemaField field : schema.getFields()) {
Assert.assertNull(field.getSchema().logicalType(), "field " + field.getName() + " should not have a successfully-parsed logicalType");
}
}
use of com.linkedin.avroutil1.parser.avsc.AvscParser in project avro-util by linkedin.
the class AvscParserTest method testMisleadingNamespace.
@Test
public void testMisleadingNamespace() throws Exception {
String avsc = TestUtil.load("schemas/TestMisleadingNamespaceRecord.avsc");
AvscParser parser = new AvscParser();
AvscParseResult result = parser.parse(avsc);
Assert.assertNull(result.getParseError());
AvroRecordSchema schema = (AvroRecordSchema) result.getTopLevelSchema();
Assert.assertEquals(schema.getFullName(), "com.acme.TestMisleadingNamespaceRecord");
AvroRecordSchema inner1 = (AvroRecordSchema) schema.getField("f1").getSchema();
AvroRecordSchema inner2 = (AvroRecordSchema) schema.getField("f2").getSchema();
Assert.assertEquals(inner1.getFullName(), "com.acme.SimpleName");
Assert.assertEquals(inner2.getFullName(), "not.so.SimpleName");
Assert.assertEquals(result.getIssues().size(), 4);
}
use of com.linkedin.avroutil1.parser.avsc.AvscParser in project avro-util by linkedin.
the class AvscSchemaWriterTest method testParsingCycle.
/**
* given an avsc, parses and re-prints it using our code
* and compares the result to vanilla avro.
* @param avsc
*/
private void testParsingCycle(String avsc) {
Schema reference = Schema.parse(avsc);
AvscParser parser = new AvscParser();
AvscParseResult parseResults = parser.parse(avsc);
List<AvscIssue> parseIssues = parseResults.getIssues();
Assert.assertTrue(parseIssues == null || parseIssues.isEmpty(), "parse issues: " + parseIssues);
AvroSchema parsed = parseResults.getTopLevelSchema();
Assert.assertNotNull(parsed);
AvscSchemaWriter writer = new AvscSchemaWriter();
AvscFile file = writer.writeSingle(parsed);
Assert.assertNotNull(file);
if (HelperConsts.NAMED_TYPES.contains(reference.getType())) {
// for named schemas the file path is determined by schema name
Assert.assertNotNull(file.getPathFromRoot());
String expectedFileName = reference.getFullName().replaceAll("\\.", Matcher.quoteReplacement(File.separator)) + ".avsc";
Assert.assertEquals(file.getPathFromRoot().toString(), expectedFileName);
} else {
// cant auto-name files containing other schema types
Assert.assertNull(file.getPathFromRoot());
}
String avsc2 = file.getContents();
Schema afterCycle = Schema.parse(avsc2);
Assert.assertEquals(reference, afterCycle);
}
Aggregations