use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class TestAbstractGenerator method verify.
private void verify(String[] args, Map.Entry<File, Map.Entry<String, String>> entry, Exception exc, File targetDir, boolean debug) throws IOException {
if (debug) {
out.println(entry);
if (exc != null)
out.println(exc);
}
String pdscFileName = (entry.getValue().getKey());
if (_expectedSchemas.contains(pdscFileName)) {
File expectedOutputFile = schemaOutputFile(targetDir.getCanonicalPath(), entry.getValue().getValue());
assertTrue(expectedOutputFile.exists());
FileInputStream is = new FileInputStream(expectedOutputFile);
byte[] bytes = new byte[is.available()];
try {
is.read(bytes);
} finally {
is.close();
}
String fileSchemaText = new String(bytes);
DataSchema fileSchema = DataTemplateUtil.parseSchema(fileSchemaText);
assertTrue(fileSchema instanceof NamedDataSchema);
// run the generator again
// verify that output file has not changed
// test up-to-date
long beforeLastModified = expectedOutputFile.lastModified();
TestGenerator.main(args, debug);
long afterLastModified = expectedOutputFile.lastModified();
assertEquals(beforeLastModified, afterLastModified, expectedOutputFile.getPath());
} else if (_badPegasusSchemas.containsKey(pdscFileName)) {
assertTrue(exc != null);
String message = exc.getMessage();
assertTrue(message.contains(_badPegasusSchemas.get(pdscFileName)));
}
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class TestSchemaFilter method testInputs.
private static void testInputs(Object[][] inputs, boolean isAvroUnionMode) throws IOException {
for (Object[] row : inputs) {
String schemaText = (String) row[0];
Predicate predicate = (Predicate) row[1];
String expected = (String) row[2];
NamedDataSchema schema = dataSchemaFromString(schemaText, isAvroUnionMode);
DataSchema filteredSchema = null;
SchemaParser parser = new SchemaParser();
parser.getValidationOptions().setAvroUnionMode(isAvroUnionMode);
filteredSchema = Filters.removeByPredicate(schema, predicate, parser);
if (filteredSchema != null) {
// Schema string match
String expectedSchemaText = expected;
DataSchema expectedSchema = dataSchemaFromString(expectedSchemaText, isAvroUnionMode);
assertEquals(filteredSchema.toString(), expectedSchema.toString());
assertEquals(filteredSchema, expectedSchema);
} else {
String parserMessage = parser.errorMessage();
assertTrue(parserMessage.contains(expected), "\nContains :" + expected + "\nActual :" + parserMessage);
}
}
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class PdlEncoderTest method assertRoundTrip.
private void assertRoundTrip(String relativeName) throws IOException {
String fullName = "com.linkedin.pegasus.generator.test.idl." + relativeName;
String path = "/" + fullName.replace('.', '/') + ".pdl";
NamedDataSchema parsed = parseSchema(fullName);
String original = loadSchema(path);
assertNotNull(parsed, "Failed to resolve: " + fullName + "resolver path: " + pegasusSrcDir.getAbsolutePath());
StringWriter writer = new StringWriter();
SchemaToPdlEncoder encoder = new SchemaToPdlEncoder(writer);
encoder.setTypeReferenceFormat(SchemaToPdlEncoder.TypeReferenceFormat.PRESERVE);
encoder.encode(parsed);
String encoded = writer.toString();
assertEqualsIgnoringSpacing(original, encoded);
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class PdlEncoderTest method parseSchema.
private NamedDataSchema parseSchema(String name) throws IOException {
StringBuilder errors = new StringBuilder();
NamedDataSchema dataSchema = resolver.findDataSchema(name, errors);
if (errors.length() > 0) {
fail("Parse error: " + errors.toString());
}
return dataSchema;
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class TemplateSpecGenerator method getImmediateCustomInfo.
private CustomInfoSpec getImmediateCustomInfo(DataSchema schema) {
if (_immediateCustomMap.containsKey(schema)) {
return _immediateCustomMap.get(schema);
}
CustomInfoSpec immediate = null;
for (DataSchema current = schema; current != null; current = dereferenceIfTyperef(current)) {
final CustomClasses customClasses = getCustomClasses(current);
if (customClasses != null) {
immediate = new CustomInfoSpec((NamedDataSchema) schema, (NamedDataSchema) current, customClasses.customClass, customClasses.customCoercerClass);
break;
}
}
// immediate may be null
_immediateCustomMap.put(schema, immediate);
return immediate;
}
Aggregations