use of com.linkedin.avroutil1.parser.exceptions.UnresolvedReferenceException in project avro-util by linkedin.
the class AvscParserTest method testParsingExternalReferences.
@Test
public void testParsingExternalReferences() throws Exception {
String referencingAvsc = TestUtil.load("schemas/TestRecordWithExternalReference.avsc");
String referencedAvsc = TestUtil.load("schemas/TestRecord.avsc");
AvscParser parser = new AvscParser();
AvscParseResult result1 = parser.parse(referencingAvsc);
Assert.assertEquals(result1.getExternalReferences().stream().map(SchemaOrRef::getRef).collect(Collectors.toList()), Collections.singletonList("com.acme.TestRecord"));
AvroRecordSchema outerSchema = (AvroRecordSchema) result1.getTopLevelSchema();
try {
outerSchema.getField("testRecordField").getSchema();
Assert.fail("accessing unresolved ref expected to fail");
} catch (UnresolvedReferenceException expected) {
Assert.assertTrue(expected.getMessage().contains("unresolved"));
Assert.assertTrue(expected.getMessage().contains("com.acme.TestRecord"));
}
AvscParseResult result2 = parser.parse(referencedAvsc);
AvroParseContext overall = new AvroParseContext();
overall.add(result1);
overall.add(result2);
overall.resolveReferences();
// now reference is resolved just fine
Assert.assertNotNull(outerSchema.getField("testRecordField").getSchema());
}
use of com.linkedin.avroutil1.parser.exceptions.UnresolvedReferenceException in project avro-util by linkedin.
the class AvscParserTest method testParsingExternalReferencesWithNoNamespace.
@Test
public void testParsingExternalReferencesWithNoNamespace() throws Exception {
String referencingAvsc = TestUtil.load("schemas/TestRecordWithExternalReferenceAndInferredNamespace.avsc");
String referencedAvsc = TestUtil.load("schemas/TestRecord.avsc");
AvscParser parser = new AvscParser();
AvscParseResult result1 = parser.parse(referencingAvsc);
AvroRecordSchema outerSchema = (AvroRecordSchema) result1.getTopLevelSchema();
try {
outerSchema.getField("testRecordField").getSchema();
Assert.fail("accessing unresolved ref expected to fail");
} catch (UnresolvedReferenceException expected) {
Assert.assertTrue(expected.getMessage().contains("unresolved"));
Assert.assertTrue(expected.getMessage().contains("TestRecord"));
}
AvscParseResult result2 = parser.parse(referencedAvsc);
AvroParseContext overall = new AvroParseContext();
overall.add(result1);
overall.add(result2);
overall.resolveReferences();
// now reference is resolved just fine
Assert.assertNotNull(outerSchema.getField("testRecordField").getSchema());
}
Aggregations