use of com.linkedin.restli.tools.compatibility.CompatibilityInfoMap 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());
}
Aggregations