use of com.linkedin.data.schema.SchemaParser in project rest.li by linkedin.
the class TestDataSchemaResolver method testClassNameDataSchemaResolver.
@Test
public void testClassNameDataSchemaResolver() {
@SuppressWarnings("deprecation") final ClassNameDataSchemaResolver resolver = new ClassNameDataSchemaResolver();
final PegasusSchemaParser parser = new SchemaParser(resolver);
final Class<? extends RecordTemplate> testClass = ClassNameFooRecord.class;
final String nonExistSchemaName = "Non-Existing Schema";
final DataSchema existSchema = parser.lookupName(testClass.getName());
assertNotNull(existSchema);
assertTrue(existSchema instanceof RecordDataSchema);
assertEquals(((RecordDataSchema) existSchema).getFullName(), testClass.getCanonicalName());
assertFalse(resolver.isBadLocation(new ClassNameDataSchemaLocation(testClass.getName())));
final DataSchema nonExistSchema = parser.lookupName(nonExistSchemaName);
assertNull(nonExistSchema);
assertTrue(parser.errorMessage().contains(nonExistSchemaName));
assertTrue(resolver.isBadLocation(new ClassNameDataSchemaLocation(nonExistSchemaName)));
}
use of com.linkedin.data.schema.SchemaParser 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.SchemaParser in project rest.li by linkedin.
the class TestUtil method schemaParserFromString.
public static PegasusSchemaParser schemaParserFromString(String s) throws UnsupportedEncodingException, IOException {
PegasusSchemaParser parser = new SchemaParser();
parser.parse(inputStreamFromString(s));
return parser;
}
use of com.linkedin.data.schema.SchemaParser in project rest.li by linkedin.
the class TestUtil method schemaParserFromObjects.
public static PegasusSchemaParser schemaParserFromObjects(List<Object> objects) throws IOException {
SchemaParser parser = new SchemaParser();
parser.parse(objects);
return parser;
}
use of com.linkedin.data.schema.SchemaParser in project rest.li by linkedin.
the class TestResourceCompatibilityChecker method testFailCollectionFile.
@Test
public void testFailCollectionFile() throws IOException {
final SchemaParser sp = new SchemaParser();
sp.parse("\"StringRef\"");
final Collection<CompatibilityInfo> resourceTestErrors = new HashSet<CompatibilityInfo>();
final Collection<CompatibilityInfo> modelTestErrors = new HashSet<CompatibilityInfo>();
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "identifier", "params"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to long"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "supports"), CompatibilityInfo.Type.ARRAY_NOT_CONTAIN, new StringArray(Arrays.asList("batch_get", "create", "delete", "get", "get_all"))));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "methods"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "batch_get"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "metadata", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from array to int"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "assocKeys"), CompatibilityInfo.Type.VALUE_NOT_EQUAL, new StringArray(Arrays.asList("q", "s")), new StringArray(Arrays.asList("q", "changed_key"))));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "find_assocKey_downgrade", "assocKeys"), CompatibilityInfo.Type.FINDER_ASSOCKEYS_DOWNGRADE));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "bitfield", "items"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from boolean to int"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "someString", "type"), CompatibilityInfo.Type.TYPE_UNKNOWN, sp.errorMessage()));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "stringMap", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to int"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "anotherAction", "parameters"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "subMap"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "exceptionTest", "throws"), CompatibilityInfo.Type.ARRAY_NOT_CONTAIN, new StringArray(Arrays.asList("com.linkedin.groups.api.GroupOwnerException", "java.io.FileNotFoundException"))));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters", "a", "optional"), CompatibilityInfo.Type.PARAMETER_WRONG_OPTIONALITY));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters", "b", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to int"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "e"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters"), CompatibilityInfo.Type.PARAMETER_NEW_REQUIRED, "f"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "returns"), CompatibilityInfo.Type.TYPE_MISSING));
resourceTestErrors.add(new CompatibilityInfo(Arrays.asList("", "collection", "finders", "oneFinder"), CompatibilityInfo.Type.PAGING_REMOVED));
modelTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("com.linkedin.greetings.api.Greeting"), CompatibilityInfo.Type.TYPE_BREAKS_NEW_READER, "new record added required fields newField"));
modelTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("com.linkedin.greetings.api.Greeting"), CompatibilityInfo.Type.TYPE_BREAKS_OLD_READER, "new record removed required fields message"));
modelTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("com.linkedin.greetings.api.Greeting", "id", "string"), CompatibilityInfo.Type.TYPE_BREAKS_NEW_AND_OLD_READERS, "schema type changed from long to string"));
final ResourceSchema prevResource = idlToResource(IDLS_SUFFIX + PREV_COLL_FILE);
final ResourceSchema currResource = idlToResource(IDLS_SUFFIX + CURR_COLL_FAIL_FILE);
ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevResource, prevSchemaResolver, currResource, incompatSchemaResolver);
Assert.assertFalse(checker.check(CompatibilityLevel.BACKWARDS));
final Collection<CompatibilityInfo> resourceIncompatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getRestSpecIncompatibles());
for (CompatibilityInfo te : resourceTestErrors) {
Assert.assertTrue(resourceIncompatibles.contains(te), "Reported resource incompatibles should contain: " + te.toString());
resourceIncompatibles.remove(te);
}
Assert.assertTrue(resourceIncompatibles.isEmpty());
final Collection<CompatibilityInfo> modelIncompatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getModelIncompatibles());
for (CompatibilityInfo te : modelTestErrors) {
Assert.assertTrue(modelIncompatibles.contains(te), "Reported model incompatibles should contain: " + te.toString());
modelIncompatibles.remove(te);
}
Assert.assertTrue(modelIncompatibles.isEmpty());
// ignore compatibles
}
Aggregations