use of com.linkedin.restli.restspec.ResourceSchema 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());
}
use of com.linkedin.restli.restspec.ResourceSchema 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());
}
use of com.linkedin.restli.restspec.ResourceSchema 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());
}
use of com.linkedin.restli.restspec.ResourceSchema in project rest.li by linkedin.
the class RestLiResourceModelExporter method generateIDLFiles.
private GeneratorResult generateIDLFiles(String apiName, String outdir, Map<String, ResourceModel> rootResourceMap, DocsProvider docsProvider) throws IOException {
Result result = new Result();
final File outdirFile = new File(outdir);
if (!outdirFile.exists()) {
if (!outdirFile.mkdirs()) {
throw new RuntimeException("Output directory '" + outdir + "' could not be created!");
}
}
if (!outdirFile.isDirectory()) {
throw new RuntimeException("Output directory '" + outdir + "' is not a directory");
}
if (!outdirFile.canRead() || !outdirFile.canWrite()) {
throw new RuntimeException("Output directory '" + outdir + "' must be writeable");
}
final ResourceModelEncoder encoder = new ResourceModelEncoder(docsProvider);
final List<ResourceSchema> rootResourceNodes = new ArrayList<ResourceSchema>();
for (Entry<String, ResourceModel> entry : rootResourceMap.entrySet()) {
final ResourceSchema rootResourceNode = encoder.buildResourceSchema(entry.getValue());
rootResourceNodes.add(rootResourceNode);
}
for (ResourceSchema rootResourceNode : rootResourceNodes) {
String fileName = rootResourceNode.getName();
if (rootResourceNode.getNamespace() != null) {
final String namespace = rootResourceNode.getNamespace();
fileName = namespace + "." + fileName;
}
if (apiName != null && !apiName.isEmpty()) {
fileName = apiName + "-" + fileName;
}
File writtenFile = writeIDLFile(outdirFile, fileName, rootResourceNode);
result.addModifiedFile(writtenFile);
result.addTargetFile(writtenFile);
}
return result;
}
use of com.linkedin.restli.restspec.ResourceSchema in project rest.li by linkedin.
the class TestRequestBuilderSpecGenerator method generateBuilderSpec.
private Set<BuilderSpec> generateBuilderSpec(String[] sources) {
final DataSchemaParser schemaParser = new DataSchemaParser(RESOLVER_DIR);
final TemplateSpecGenerator specGenerator = new TemplateSpecGenerator(schemaParser.getSchemaResolver());
final RestSpecParser parser = new RestSpecParser();
final Map<ResourceMethod, String> builderBaseMap = new HashMap<ResourceMethod, String>();
builderBaseMap.put(ResourceMethod.GET, "GetRequestBuilder");
builderBaseMap.put(ResourceMethod.DELETE, "DeleteRequestBuilder");
builderBaseMap.put(ResourceMethod.UPDATE, "UpdateRequestBuilder");
builderBaseMap.put(ResourceMethod.CREATE, "CreateIdRequestBuilder");
builderBaseMap.put(ResourceMethod.PARTIAL_UPDATE, "PartialUpdateRequestBuilder");
builderBaseMap.put(ResourceMethod.GET_ALL, "GetAllRequestBuilder");
builderBaseMap.put(ResourceMethod.OPTIONS, "OptionsRequestBuilder");
builderBaseMap.put(ResourceMethod.ACTION, "ActionRequestBuilder");
builderBaseMap.put(ResourceMethod.FINDER, "FinderRequestBuilder");
builderBaseMap.put(ResourceMethod.BATCH_GET, "BatchGetRequestBuilder");
builderBaseMap.put(ResourceMethod.BATCH_UPDATE, "BatchUpdateRequestBuilder");
builderBaseMap.put(ResourceMethod.BATCH_PARTIAL_UPDATE, "BatchPartialUpdateRequestBuilder");
builderBaseMap.put(ResourceMethod.BATCH_DELETE, "BatchDeleteRequestBuilder");
builderBaseMap.put(ResourceMethod.BATCH_CREATE, "BatchCreateIdRequestBuilder");
final RequestBuilderSpecGenerator builderSpecGenerator = new RequestBuilderSpecGenerator(schemaParser.getSchemaResolver(), specGenerator, RestliVersion.RESTLI_2_0_0, builderBaseMap);
// parse idl to ResourceSchemas
final RestSpecParser.ParseResult parseResult = parser.parseSources(sources);
// generate Builder specs from ResourceSchema
for (CodeUtil.Pair<ResourceSchema, File> pair : parseResult.getSchemaAndFiles()) {
builderSpecGenerator.generate(pair.first, pair.second);
}
return builderSpecGenerator.getBuilderSpec();
}
Aggregations