use of com.linkedin.data.schema.grammar.PdlSchemaParser in project rest.li by linkedin.
the class TestDataSchemaResolver method lookup.
public void lookup(DataSchemaResolver resolver, String[][] lookups, char separator, boolean debug, SchemaFormatType extension) {
PegasusSchemaParser parser = extension.equals(PDSC) ? new SchemaParser(resolver) : new PdlSchemaParser(resolver);
for (String[] entry : lookups) {
String name = entry[0];
String expectFound = entry[1];
String expected = entry[2];
DataSchema schema = parser.lookupName(name);
if (debug) {
out.println("----" + name + "-----");
}
String errorMessage = parser.errorMessage();
if (debug && errorMessage.isEmpty() == false) {
out.println(errorMessage);
}
if (expectFound == ERROR) {
assertTrue(parser.hasError());
assertTrue(expected == null || errorMessage.contains(expected), "Expected: " + expected + "\n Actual: " + errorMessage);
} else if (expectFound == FOUND) {
assertTrue(schema != null);
String schemaText = schema.toString();
if (debug) {
out.println(schemaText);
}
assertFalse(parser.hasError());
assertTrue(schema instanceof NamedDataSchema);
NamedDataSchema namedSchema = (NamedDataSchema) schema;
assertEquals(namedSchema.getFullName(), name);
assertTrue(schemaText.contains(expected));
assertTrue(resolver.bindings().containsKey(name));
assertSame(resolver.bindings().get(name), namedSchema);
String location = entry[3];
DataSchemaLocation namedSchemalocation = resolver.nameToDataSchemaLocations().get(name);
String locationNorm;
if (namedSchemalocation.toString().contains(".jar")) {
locationNorm = location.replace(separator, '/');
} else {
locationNorm = location.replace('/', separator);
}
assertNotNull(namedSchemalocation);
assertEquals(namedSchemalocation.toString().indexOf(locationNorm), namedSchemalocation.toString().length() - locationNorm.length());
assertTrue(resolver.locationResolved(namedSchemalocation));
} else if (expectFound == NOT_FOUND) {
assertTrue(schema == null);
assertFalse(parser.hasError());
assertTrue(expected == null || errorMessage.contains(expected));
assertFalse(resolver.bindings().containsKey(name));
} else {
assertTrue(false);
}
}
}
use of com.linkedin.data.schema.grammar.PdlSchemaParser in project rest.li by linkedin.
the class PdlEncoderTest method parseSchema.
private DataSchema parseSchema(File file) throws IOException {
DataSchemaResolver resolver = MultiFormatDataSchemaResolver.withBuiltinFormats(pegasusSrcDir.getAbsolutePath());
AbstractSchemaParser parser = new PdlSchemaParser(resolver);
parser.parse(new FileInputStream(file));
return extractSchema(parser, file.getAbsolutePath());
}
Aggregations