Search in sources :

Example 6 with CompatibilityInfo

use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.

the class TestResourceCompatibilityChecker method testPassSimpleFile.

@Test
public void testPassSimpleFile() throws IOException {
    final Collection<CompatibilityInfo> resourceTestDiffs = new HashSet<CompatibilityInfo>();
    final Collection<CompatibilityInfo> modelTestDiffs = new HashSet<CompatibilityInfo>();
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList(""), CompatibilityInfo.Type.OPTIONAL_VALUE, "namespace"));
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "supports"), CompatibilityInfo.Type.SUPERSET, new HashSet<String>(Arrays.asList("update"))));
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "methods"), CompatibilityInfo.Type.SUPERSET, new HashSet<String>(Arrays.asList("update"))));
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "methods", "get", "parameters", "param1", "default"), CompatibilityInfo.Type.VALUE_DIFFERENT, "abcd", "abc"));
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "actions", "oneAction", "parameters", "bitfield"), CompatibilityInfo.Type.DEPRECATED, "The \"items\" field"));
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "actions", "oneAction", "parameters", "someString"), CompatibilityInfo.Type.OPTIONAL_PARAMETER));
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "actions", "oneAction", "parameters"), CompatibilityInfo.Type.PARAMETER_NEW_OPTIONAL, "newParam"));
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "actions", "oneAction", "parameters", "someString2", "default"), CompatibilityInfo.Type.VALUE_DIFFERENT, "default", "changed"));
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "actions", "twoAction", "annotations", "deprecated"), CompatibilityInfo.Type.ANNOTATIONS_CHANGED, "added"));
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "annotations", "deprecated"), CompatibilityInfo.Type.ANNOTATIONS_CHANGED, "added"));
    resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "simple", "methods", "get", "annotations", "deprecated"), CompatibilityInfo.Type.ANNOTATIONS_CHANGED, "added"));
    modelTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("com.linkedin.greetings.api.Greeting"), CompatibilityInfo.Type.TYPE_INFO, "new record added optional fields newField"));
    final ResourceSchema prevResource = idlToResource(IDLS_SUFFIX + PREV_SIMPLE_FILE);
    final ResourceSchema currResource = idlToResource(IDLS_SUFFIX + CURR_SIMPLE_PASS_FILE);
    ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevResource, prevSchemaResolver, currResource, compatSchemaResolver);
    boolean check = checker.check(CompatibilityLevel.BACKWARDS);
    Assert.assertTrue(check);
    final Collection<CompatibilityInfo> resourceIncompatibles = checker.getInfoMap().getRestSpecIncompatibles();
    final Collection<CompatibilityInfo> resourceCompatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getRestSpecCompatibles());
    for (CompatibilityInfo di : resourceTestDiffs) {
        Assert.assertTrue(resourceCompatibles.contains(di), "Reported resource compatibles should contain: " + di.toString());
        resourceCompatibles.remove(di);
    }
    Assert.assertTrue(resourceIncompatibles.isEmpty());
    Assert.assertTrue(resourceCompatibles.isEmpty());
    final Collection<CompatibilityInfo> modelIncompatibles = checker.getInfoMap().getModelIncompatibles();
    final Collection<CompatibilityInfo> modelCompatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getModelCompatibles());
    for (CompatibilityInfo di : modelTestDiffs) {
        Assert.assertTrue(modelCompatibles.contains(di), "Reported model compatibles should contain: " + di.toString());
        modelCompatibles.remove(di);
    }
    Assert.assertTrue(modelIncompatibles.isEmpty());
    Assert.assertTrue(modelCompatibles.isEmpty());
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) CompatibilityInfo(com.linkedin.restli.tools.idlcheck.CompatibilityInfo) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 7 with CompatibilityInfo

use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.

the class TestResourceCompatibilityChecker method testPassActionsSetFile.

@Test
public void testPassActionsSetFile() throws IOException {
    final Collection<CompatibilityInfo> testDiffs = new HashSet<CompatibilityInfo>();
    testDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "doc"), CompatibilityInfo.Type.DOC_NOT_EQUAL));
    testDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "actionsSet", "actions", "handshake", "parameters"), CompatibilityInfo.Type.PARAMETER_NEW_OPTIONAL, "param"));
    testDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "actionsSet", "actions", "handshake", "parameters", "me", "doc"), CompatibilityInfo.Type.DOC_NOT_EQUAL));
    final ResourceSchema prevResource = idlToResource(IDLS_SUFFIX + PREV_AS_FILE);
    final ResourceSchema currResource = idlToResource(IDLS_SUFFIX + CURR_AS_PASS_FILE);
    ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevResource, prevSchemaResolver, currResource, prevSchemaResolver);
    Assert.assertTrue(checker.check(CompatibilityLevel.BACKWARDS));
    final Collection<CompatibilityInfo> incompatibles = checker.getInfoMap().getIncompatibles();
    Assert.assertTrue(incompatibles.isEmpty());
    final Collection<CompatibilityInfo> compatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getCompatibles());
    for (CompatibilityInfo td : testDiffs) {
        Assert.assertTrue(compatibles.contains(td), "Reported compatibles should contain: " + td.toString());
        compatibles.remove(td);
    }
    Assert.assertTrue(compatibles.isEmpty());
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) CompatibilityInfo(com.linkedin.restli.tools.idlcheck.CompatibilityInfo) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 8 with CompatibilityInfo

use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.

the class TestRestliSnapshotCompatibilityChecker method testIncompatibleRestLiDataAnnotations.

@Test
public void testIncompatibleRestLiDataAnnotations() {
    final Collection<CompatibilityInfo> errors = new HashSet<CompatibilityInfo>();
    errors.add(new CompatibilityInfo(Arrays.<Object>asList("", "annotations", "intB"), CompatibilityInfo.Type.ANNOTATION_CHANGE_BREAKS_OLD_CLIENT, "Cannot add ReadOnly annotation"));
    errors.add(new CompatibilityInfo(Arrays.<Object>asList("", "annotations", "validationDemoNext/intA"), CompatibilityInfo.Type.ANNOTATION_CHANGE_BREAKS_OLD_CLIENT, "Cannot add CreateOnly annotation"));
    // Removing ReadOnly annotation on a required field
    errors.add(new CompatibilityInfo(Arrays.<Object>asList("", "annotations", "validationDemoNext/stringB"), CompatibilityInfo.Type.ANNOTATION_CHANGE_BREAKS_NEW_SERVER, "Cannot remove ReadOnly annotation"));
    // Removing ReadOnly annotation on an optional field
    errors.add(new CompatibilityInfo(Arrays.<Object>asList("", "annotations", "intA"), CompatibilityInfo.Type.ANNOTATION_CHANGE_MAY_REQUIRE_CLIENT_CODE_CHANGE, "Cannot remove ReadOnly annotation"));
    // Removing CreateOnly annotation on a required field
    errors.add(new CompatibilityInfo(Arrays.<Object>asList("", "annotations", "stringB"), CompatibilityInfo.Type.ANNOTATION_CHANGE_MAY_REQUIRE_CLIENT_CODE_CHANGE, "Cannot remove CreateOnly annotation"));
    // Removing CreateOnly annotation on an optional field
    errors.add(new CompatibilityInfo(Arrays.<Object>asList("", "annotations", "intB"), CompatibilityInfo.Type.ANNOTATION_CHANGE_MAY_REQUIRE_CLIENT_CODE_CHANGE, "Cannot remove CreateOnly annotation"));
    final RestLiSnapshotCompatibilityChecker checker = new RestLiSnapshotCompatibilityChecker();
    final CompatibilityInfoMap infoMap = checker.check(RESOURCES_DIR + FS + "snapshots" + FS + "prev-validationdemos.snapshot.json", RESOURCES_DIR + FS + "snapshots" + FS + "curr-validationdemos-fail.snapshot.json", CompatibilityLevel.BACKWARDS);
    final Collection<CompatibilityInfo> restSpecIncompatibles = infoMap.getRestSpecIncompatibles();
    for (CompatibilityInfo e : errors) {
        Assert.assertTrue(restSpecIncompatibles.contains(e), "Reported restspec incompatibles should contain: " + e.toString());
        restSpecIncompatibles.remove(e);
    }
    Assert.assertTrue(restSpecIncompatibles.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)

Example 9 with CompatibilityInfo

use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.

the class TestRestliSnapshotCompatibilityChecker method testFileNotFound.

@Test
public void testFileNotFound() {
    final String nonExistentFilename1 = "NonExistentFile1";
    final String nonExistentFilename2 = "NonExistentFile2";
    final Collection<CompatibilityInfo> testIncompatibles = new HashSet<CompatibilityInfo>();
    final Collection<CompatibilityInfo> testCompatibles = new HashSet<CompatibilityInfo>();
    testIncompatibles.add(new CompatibilityInfo(Arrays.<Object>asList(""), CompatibilityInfo.Type.RESOURCE_MISSING, nonExistentFilename1));
    testCompatibles.add(new CompatibilityInfo(Arrays.<Object>asList(""), CompatibilityInfo.Type.RESOURCE_NEW, nonExistentFilename2));
    final RestLiSnapshotCompatibilityChecker checker = new RestLiSnapshotCompatibilityChecker();
    CompatibilityInfoMap infoMap = checker.check(nonExistentFilename1, nonExistentFilename2, CompatibilityLevel.BACKWARDS);
    Assert.assertFalse(infoMap.isCompatible(CompatibilityLevel.BACKWARDS));
    final Collection<CompatibilityInfo> incompatibles = new HashSet<CompatibilityInfo>(infoMap.getIncompatibles());
    final Collection<CompatibilityInfo> compatibles = new HashSet<CompatibilityInfo>(infoMap.getCompatibles());
    for (CompatibilityInfo te : incompatibles) {
        Assert.assertTrue(testIncompatibles.contains(te), "Reported incompatibles should contain: " + te.toString());
        incompatibles.remove(te);
    }
    for (CompatibilityInfo di : compatibles) {
        Assert.assertTrue(testCompatibles.contains(di), "Reported compatibles should contain: " + di.toString());
        compatibles.remove(di);
    }
}
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)

Example 10 with CompatibilityInfo

use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.

the class CompatibilityInfoMap method addRestSpecInfo.

public void addRestSpecInfo(Message message) {
    final CompatibilityInfo.Type infoType = CompatibilityInfo.Type.OTHER_ERROR;
    _restSpecMap.get(infoType.getLevel()).add(new CompatibilityInfo(Arrays.asList(message.getPath()), infoType, message.toString()));
}
Also used : CompatibilityInfo(com.linkedin.restli.tools.idlcheck.CompatibilityInfo)

Aggregations

CompatibilityInfo (com.linkedin.restli.tools.idlcheck.CompatibilityInfo)16 HashSet (java.util.HashSet)11 Test (org.testng.annotations.Test)11 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)8 StringArray (com.linkedin.data.template.StringArray)3 CompatibilityInfoMap (com.linkedin.restli.tools.compatibility.CompatibilityInfoMap)3 SchemaParser (com.linkedin.data.schema.SchemaParser)1 AssocKeySchema (com.linkedin.restli.restspec.AssocKeySchema)1 AssocKeySchemaArray (com.linkedin.restli.restspec.AssocKeySchemaArray)1