use of com.linkedin.data.schema.compatibility.CompatibilityResult in project rest.li by linkedin.
the class TestCompatibilityChecker method testCompatibility.
private void testCompatibility(String olderSchemaText, String newerSchemaText, List<CompatibilityOptions> compatibilityOptions, boolean hasError, Object[] expected, int expectedIndex) throws IOException {
if (_debug)
out.println(olderSchemaText + "\n" + newerSchemaText);
DataSchema olderSchema = TestUtil.dataSchemaFromString(olderSchemaText);
DataSchema newerSchema = TestUtil.dataSchemaFromString(newerSchemaText);
assertNotNull(olderSchema, olderSchemaText);
assertNotNull(newerSchema, newerSchemaText);
for (CompatibilityOptions option : compatibilityOptions) {
CompatibilityResult result = CompatibilityChecker.checkCompatibility(olderSchema, newerSchema, option);
String messageText = result.getMessages().toString();
if (_debug)
out.println(result);
assertEquals(result.isError(), hasError, olderSchemaText + "\n" + newerSchemaText + "\n" + messageText);
for (int i = expectedIndex; i < expected.length; i++) {
String expectedText = ".*" + expected[i] + "\n.*";
if (_debug)
out.println(expectedText);
Pattern pattern = Pattern.compile(expectedText, Pattern.DOTALL);
Matcher matcher = pattern.matcher(messageText);
boolean matches = matcher.matches();
assertTrue(matches, messageText + "\n" + expectedText);
}
}
}
use of com.linkedin.data.schema.compatibility.CompatibilityResult in project rest.li by linkedin.
the class ResourceCompatibilityChecker method checkType.
/**
* @return whether the optionality check passes
*/
private boolean checkType(Object pathTail, String prevType, String currType, boolean allowNull) {
if (prevType == null && currType == null && allowNull) {
return true;
}
if (prevType == null || currType == null) {
_infoMap.addRestSpecInfo(pathTail, CompatibilityInfo.Type.TYPE_MISSING, _infoPath);
return false;
}
try {
final DataSchema prevSchema = RestSpecCodec.textToSchema(prevType, _prevSchemaResolver);
final DataSchema currSchema = RestSpecCodec.textToSchema(currType, _currSchemaResolver);
CompatibilityResult compatibilityResult = CompatibilityChecker.checkCompatibility(prevSchema, currSchema, defaultOptions);
if (!compatibilityResult.getMessages().isEmpty()) {
if (prevType.equals(currType) && prevSchema instanceof NamedDataSchema) {
if (!_namedSchemasChecked.contains(prevType)) {
addNamedCompatibilityMessages(compatibilityResult.getMessages());
_namedSchemasChecked.add(prevType);
}
return compatibilityResult.isError();
}
addCompatibilityMessages(pathTail, compatibilityResult.getMessages());
return compatibilityResult.isError();
}
return true;
} catch (IllegalArgumentException e) {
_infoMap.addRestSpecInfo(pathTail, CompatibilityInfo.Type.TYPE_UNKNOWN, _infoPath, e.getMessage());
return false;
}
}
Aggregations