use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.
the class CompatibilityInfoMap method addRestSpecInfo.
public void addRestSpecInfo(Object pathTail, CompatibilityMessage message, Stack<Object> path) {
path.push(pathTail);
final CompatibilityInfo.Type infoType;
if (message.isError()) {
infoType = CompatibilityInfo.Type.TYPE_ERROR;
final String info = String.format(message.getFormat(), message.getArgs());
_restSpecMap.get(infoType.getLevel()).add(new CompatibilityInfo(path, infoType, info));
} else {
infoType = CompatibilityInfo.Type.TYPE_INFO;
final String info = String.format(message.getFormat(), message.getArgs());
_restSpecMap.get(infoType.getLevel()).add(new CompatibilityInfo(Arrays.asList(message.getPath()), infoType, info));
}
path.pop();
}
use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.
the class CompatibilityInfoMap method addRestSpecInfo.
public void addRestSpecInfo(Object pathTail, CompatibilityInfo.Type infoType, Stack<Object> path, Object... parameters) {
path.push(pathTail);
_restSpecMap.get(infoType.getLevel()).add(new CompatibilityInfo(path, infoType, parameters));
path.pop();
}
use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.
the class TestRestliSnapshotCompatibilityChecker method testIncompatibleRestSpecVsSnapshot.
@Test
public void testIncompatibleRestSpecVsSnapshot() {
final Collection<CompatibilityInfo> restSpecErrors = new HashSet<CompatibilityInfo>();
final Collection<CompatibilityInfo> restSpecDiffs = new HashSet<CompatibilityInfo>();
restSpecErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "identifier", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from int to long"));
restSpecErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "alternativeKeys"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "altTwo"));
restSpecErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "alternativeKeys", "alt", "type"), CompatibilityInfo.Type.VALUE_NOT_EQUAL, "long", "string"));
restSpecErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "alternativeKeys", "alt", "keyCoercer"), CompatibilityInfo.Type.VALUE_NOT_EQUAL, "com.linkedin.restli.tools.twitter.IntLongCoercer", "com.linkedin.restli.tools.twitter.StringLongCoercer"));
restSpecDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "supports"), CompatibilityInfo.Type.SUPERSET, new HashSet<String>(Arrays.asList("create"))));
restSpecDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "methods"), CompatibilityInfo.Type.SUPERSET, new HashSet<String>(Arrays.asList("create"))));
restSpecDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "alternativeKeys"), CompatibilityInfo.Type.SUPERSET, new HashSet<String>(Arrays.asList("newAlt"))));
final RestLiSnapshotCompatibilityChecker checker = new RestLiSnapshotCompatibilityChecker();
final CompatibilityInfoMap incompatibleInfoMap = checker.checkRestSpecVsSnapshot(RESOURCES_DIR + FS + "idls" + FS + "twitter-statuses-incompatible.restspec.json", RESOURCES_DIR + FS + "snapshots" + FS + "twitter-statuses.snapshot.json", CompatibilityLevel.EQUIVALENT);
Assert.assertTrue(incompatibleInfoMap.isModelEquivalent());
final Collection<CompatibilityInfo> restSpecIncompatibles = incompatibleInfoMap.getRestSpecIncompatibles();
final Collection<CompatibilityInfo> restSpecCompatibles = incompatibleInfoMap.getRestSpecCompatibles();
for (CompatibilityInfo te : restSpecErrors) {
Assert.assertTrue(restSpecIncompatibles.contains(te), "Reported restspec incompatibles should contain: " + te.toString());
restSpecIncompatibles.remove(te);
}
for (CompatibilityInfo di : restSpecDiffs) {
Assert.assertTrue(restSpecCompatibles.contains(di), "Reported restspec compatibles should contain: " + di.toString());
restSpecCompatibles.remove(di);
}
Assert.assertTrue(restSpecIncompatibles.isEmpty());
Assert.assertTrue(restSpecCompatibles.isEmpty());
}
use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.
the class TestResourceCompatibilityChecker method testFailSimpleFile.
@Test
public void testFailSimpleFile() throws IOException {
final Collection<CompatibilityInfo> resourceTestErrors = new HashSet<CompatibilityInfo>();
final Collection<CompatibilityInfo> modelTestErrors = new HashSet<CompatibilityInfo>();
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "supports"), CompatibilityInfo.Type.ARRAY_NOT_CONTAIN, new StringArray(Arrays.asList("delete", "get"))));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "methods"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "delete"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "methods", "get", "parameters", "param1", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to int"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "actions", "oneAction", "parameters", "bitfield", "items"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from boolean to int"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "actions", "oneAction", "parameters"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "someString"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "actions", "oneAction", "parameters"), CompatibilityInfo.Type.PARAMETER_NEW_REQUIRED, "someStringNew"));
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_SIMPLE_FILE);
final ResourceSchema currResource = idlToResource(IDLS_SUFFIX + CURR_SIMPLE_FAIL_FILE);
ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevResource, prevSchemaResolver, currResource, incompatSchemaResolver);
Assert.assertFalse(checker.check(CompatibilityLevel.BACKWARDS));
final Collection<CompatibilityInfo> resourceIncompatible = new HashSet<CompatibilityInfo>(checker.getInfoMap().getRestSpecIncompatibles());
for (CompatibilityInfo te : resourceTestErrors) {
Assert.assertTrue(resourceIncompatible.contains(te), "Reported resource incompatibles should contain: " + te.toString());
resourceIncompatible.remove(te);
}
Assert.assertTrue(resourceIncompatible.isEmpty());
final Collection<CompatibilityInfo> modelIncompatible = new HashSet<CompatibilityInfo>(checker.getInfoMap().getModelIncompatibles());
for (CompatibilityInfo te : modelTestErrors) {
Assert.assertTrue(modelIncompatible.contains(te), "Reported model incompatibles should contain: " + te.toString());
modelIncompatible.remove(te);
}
Assert.assertTrue(modelIncompatible.isEmpty());
// ignore compatibles
}
use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.
the class TestResourceCompatibilityChecker method testFailAssociationFile.
@Test
public void testFailAssociationFile() throws IOException {
final AssocKeySchema prevAssocKey = new AssocKeySchema();
prevAssocKey.setName("key1");
prevAssocKey.setType("string");
final Collection<CompatibilityInfo> testErrors = new HashSet<CompatibilityInfo>();
testErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "association", "assocKeys"), CompatibilityInfo.Type.ARRAY_NOT_EQUAL, new AssocKeySchemaArray(Arrays.asList(prevAssocKey))));
testErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "association", "supports"), CompatibilityInfo.Type.ARRAY_NOT_CONTAIN, new StringArray(Arrays.asList("create", "get"))));
testErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "association", "methods", "create", "parameters"), CompatibilityInfo.Type.PARAMETER_NEW_REQUIRED, "data"));
testErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "association", "methods"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "get"));
testErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "association", "entity", "path"), CompatibilityInfo.Type.VALUE_NOT_EQUAL, "/greetings/assoc/{greetingsId}", "/greetings/association/{greetingsId}"));
final ResourceSchema prevResource = idlToResource(IDLS_SUFFIX + PREV_ASSOC_FILE);
final ResourceSchema currResource = idlToResource(IDLS_SUFFIX + CURR_ASSOC_FAIL_FILE);
ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevResource, prevSchemaResolver, currResource, prevSchemaResolver);
Assert.assertFalse(checker.check(CompatibilityLevel.BACKWARDS));
final Collection<CompatibilityInfo> incompatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getIncompatibles());
for (CompatibilityInfo te : testErrors) {
Assert.assertTrue(incompatibles.contains(te), "Reported incompatibles should contain: " + te.toString());
incompatibles.remove(te);
}
Assert.assertTrue(incompatibles.isEmpty());
}
Aggregations