Search in sources :

Example 6 with CompatibilityInfoMap

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());
}
Also used : CompatibilityInfo(com.linkedin.restli.tools.idlcheck.CompatibilityInfo) CompatibilityInfoMap(com.linkedin.restli.tools.compatibility.CompatibilityInfoMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

CompatibilityInfoMap (com.linkedin.restli.tools.compatibility.CompatibilityInfoMap)6 Test (org.testng.annotations.Test)5 CompatibilityInfo (com.linkedin.restli.tools.idlcheck.CompatibilityInfo)3 HashSet (java.util.HashSet)3 DataSchemaResolver (com.linkedin.data.schema.DataSchemaResolver)1 ResourceCompatibilityChecker (com.linkedin.restli.tools.compatibility.ResourceCompatibilityChecker)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Stack (java.util.Stack)1