Search in sources :

Example 11 with CompatibilityInfo

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();
}
Also used : CompatibilityInfo(com.linkedin.restli.tools.idlcheck.CompatibilityInfo)

Example 12 with CompatibilityInfo

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();
}
Also used : CompatibilityInfo(com.linkedin.restli.tools.idlcheck.CompatibilityInfo)

Example 13 with CompatibilityInfo

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());
}
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 14 with CompatibilityInfo

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
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) StringArray(com.linkedin.data.template.StringArray) CompatibilityInfo(com.linkedin.restli.tools.idlcheck.CompatibilityInfo) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 15 with CompatibilityInfo

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());
}
Also used : AssocKeySchemaArray(com.linkedin.restli.restspec.AssocKeySchemaArray) ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) StringArray(com.linkedin.data.template.StringArray) CompatibilityInfo(com.linkedin.restli.tools.idlcheck.CompatibilityInfo) AssocKeySchema(com.linkedin.restli.restspec.AssocKeySchema) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

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