use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.
the class CompatibilityInfoMap method addModelInfo.
/**
* Add info used for adding errors related to {@link com.linkedin.data.schema.NamedDataSchema} compatibility.
* The path will be the path to the relevant field within the NamedDataSchema.
* @param message {@link CompatibilityMessage}
*/
public void addModelInfo(CompatibilityMessage message) {
final CompatibilityInfo.Type infoType;
CompatibilityInfo info;
String infoMessage = String.format(message.getFormat(), message.getArgs());
if (message.isError()) {
switch(message.getImpact()) {
case BREAKS_NEW_READER:
infoType = CompatibilityInfo.Type.TYPE_BREAKS_NEW_READER;
break;
case BREAKS_OLD_READER:
infoType = CompatibilityInfo.Type.TYPE_BREAKS_OLD_READER;
break;
case BREAKS_NEW_AND_OLD_READERS:
infoType = CompatibilityInfo.Type.TYPE_BREAKS_NEW_AND_OLD_READERS;
break;
default:
infoType = CompatibilityInfo.Type.OTHER_ERROR;
break;
}
} else {
infoType = CompatibilityInfo.Type.TYPE_INFO;
}
info = new CompatibilityInfo(Arrays.asList(message.getPath()), infoType, infoMessage);
_modelMap.get(infoType.getLevel()).add(info);
}
use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.
the class CompatibilityInfoMap method createSummaryForInfo.
private static void createSummaryForInfo(Collection<CompatibilityInfo> info, String description, StringBuilder summaryMessage) {
if (info.isEmpty()) {
return;
}
summaryMessage.append(description).append(":\n");
int issueIndex = 1;
for (CompatibilityInfo i : info) {
summaryMessage.append(" ").append(issueIndex).append(") ").append(i.toString()).append("\n");
++issueIndex;
}
}
use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.
the class TestResourceCompatibilityChecker method testPassCollectionFile.
@Test
public void testPassCollectionFile() 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("", "collection", "supports"), CompatibilityInfo.Type.SUPERSET, new HashSet<String>(Arrays.asList("update"))));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "methods"), CompatibilityInfo.Type.SUPERSET, new HashSet<String>(Arrays.asList("update"))));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "parameters", "tone"), CompatibilityInfo.Type.OPTIONAL_PARAMETER));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "parameters"), CompatibilityInfo.Type.PARAMETER_NEW_OPTIONAL, "newParam"));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "parameters", "tone"), CompatibilityInfo.Type.DEPRECATED, "The \"items\" field"));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.asList("", "collection", "finders", "search"), CompatibilityInfo.Type.PAGING_ADDED));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters"), CompatibilityInfo.Type.PARAMETER_NEW_OPTIONAL, "newParam"));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "bitfield"), CompatibilityInfo.Type.DEPRECATED, "The \"items\" field"));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "someString"), CompatibilityInfo.Type.OPTIONAL_PARAMETER));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "exceptionTest", "throws"), CompatibilityInfo.Type.SUPERSET, new HashSet<String>(Arrays.asList("java.lang.NullPointerException"))));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters", "b", "default"), CompatibilityInfo.Type.VALUE_DIFFERENT, "default", "changed"));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "oneFinder", "annotations", "deprecated"), CompatibilityInfo.Type.ANNOTATIONS_CHANGED, "added"));
resourceTestDiffs.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "oneFinder", "parameters", "param1", "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_COLL_FILE);
final ResourceSchema currResource = idlToResource(IDLS_SUFFIX + CURR_COLL_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());
}
use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.
the class TestResourceCompatibilityChecker method testFailCollectionFile.
@Test
public void testFailCollectionFile() throws IOException {
final SchemaParser sp = new SchemaParser();
sp.parse("\"StringRef\"");
final Collection<CompatibilityInfo> resourceTestErrors = new HashSet<CompatibilityInfo>();
final Collection<CompatibilityInfo> modelTestErrors = new HashSet<CompatibilityInfo>();
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "identifier", "params"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to long"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "supports"), CompatibilityInfo.Type.ARRAY_NOT_CONTAIN, new StringArray(Arrays.asList("batch_get", "create", "delete", "get", "get_all"))));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "methods"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "batch_get"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "metadata", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from array to int"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "assocKeys"), CompatibilityInfo.Type.VALUE_NOT_EQUAL, new StringArray(Arrays.asList("q", "s")), new StringArray(Arrays.asList("q", "changed_key"))));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "find_assocKey_downgrade", "assocKeys"), CompatibilityInfo.Type.FINDER_ASSOCKEYS_DOWNGRADE));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "bitfield", "items"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from boolean to int"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "someString", "type"), CompatibilityInfo.Type.TYPE_UNKNOWN, sp.errorMessage()));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "stringMap", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to int"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "anotherAction", "parameters"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "subMap"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "exceptionTest", "throws"), CompatibilityInfo.Type.ARRAY_NOT_CONTAIN, new StringArray(Arrays.asList("com.linkedin.groups.api.GroupOwnerException", "java.io.FileNotFoundException"))));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters", "a", "optional"), CompatibilityInfo.Type.PARAMETER_WRONG_OPTIONALITY));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters", "b", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to int"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "e"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters"), CompatibilityInfo.Type.PARAMETER_NEW_REQUIRED, "f"));
resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "returns"), CompatibilityInfo.Type.TYPE_MISSING));
resourceTestErrors.add(new CompatibilityInfo(Arrays.asList("", "collection", "finders", "oneFinder"), CompatibilityInfo.Type.PAGING_REMOVED));
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_COLL_FILE);
final ResourceSchema currResource = idlToResource(IDLS_SUFFIX + CURR_COLL_FAIL_FILE);
ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevResource, prevSchemaResolver, currResource, incompatSchemaResolver);
Assert.assertFalse(checker.check(CompatibilityLevel.BACKWARDS));
final Collection<CompatibilityInfo> resourceIncompatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getRestSpecIncompatibles());
for (CompatibilityInfo te : resourceTestErrors) {
Assert.assertTrue(resourceIncompatibles.contains(te), "Reported resource incompatibles should contain: " + te.toString());
resourceIncompatibles.remove(te);
}
Assert.assertTrue(resourceIncompatibles.isEmpty());
final Collection<CompatibilityInfo> modelIncompatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getModelIncompatibles());
for (CompatibilityInfo te : modelTestErrors) {
Assert.assertTrue(modelIncompatibles.contains(te), "Reported model incompatibles should contain: " + te.toString());
modelIncompatibles.remove(te);
}
Assert.assertTrue(modelIncompatibles.isEmpty());
// ignore compatibles
}
use of com.linkedin.restli.tools.idlcheck.CompatibilityInfo in project rest.li by linkedin.
the class TestResourceCompatibilityChecker method testFailActionsSetFile.
@Test
public void testFailActionsSetFile() throws IOException {
final Collection<CompatibilityInfo> testErrors = new HashSet<CompatibilityInfo>();
testErrors.add(new CompatibilityInfo(Arrays.<Object>asList(""), CompatibilityInfo.Type.VALUE_WRONG_OPTIONALITY, "actionsSet"));
ResourceSchema prevResource = idlToResource(IDLS_SUFFIX + PREV_AS_FILE);
ResourceSchema currResource = idlToResource(IDLS_SUFFIX + CURR_AS_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());
final Collection<CompatibilityInfo> compatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getCompatibles());
for (CompatibilityInfo te : testErrors) {
Assert.assertTrue(incompatibles.contains(te), "Reported incompatibles should contain: " + te.toString());
incompatibles.remove(te);
}
Assert.assertTrue(incompatibles.isEmpty());
Assert.assertTrue(compatibles.isEmpty());
}
Aggregations