use of com.linkedin.restli.tools.clientgen.builderspec.ActionParamBindingMethodSpec in project rest.li by linkedin.
the class RequestBuilderSpecGenerator method generateActionParamBindingMethods.
private void generateActionParamBindingMethods(ParameterSchemaArray parameters, ActionBuilderSpec requestBuilderClass) {
for (ParameterSchema param : parameters) {
final String paramName = param.getName();
final ClassTemplateSpec typeClassSpec = classToTemplateSpec(param.getType());
final boolean isOptional = RestLiToolsUtils.isParameterOptional(param);
final String setMethodName = RestLiToolsUtils.nameCamelCase(paramName + "Param");
ActionParamBindingMethodSpec spec = new ActionParamBindingMethodSpec(setMethodName);
spec.setParamName(paramName);
spec.setOptional(isOptional);
spec.setArgType(typeClassSpec);
spec.setDoc(param.getDoc());
requestBuilderClass.addActionParamMethod(spec);
}
}
use of com.linkedin.restli.tools.clientgen.builderspec.ActionParamBindingMethodSpec in project rest.li by linkedin.
the class TestRequestBuilderSpecGenerator method testActionResource.
@Test
public void testActionResource() throws Exception {
String idl = moduleDir + FS + IDLS_DIR + FS + "testAction.restspec.json";
Set<BuilderSpec> builderSpecs = generateBuilderSpec(new String[] { idl });
Assert.assertNotNull(builderSpecs);
Assert.assertEquals(builderSpecs.size(), 27);
ActionSetRootBuilderSpec rootBuilder = null;
List<ActionBuilderSpec> actionBuilders = new ArrayList<ActionBuilderSpec>();
for (BuilderSpec spec : builderSpecs) {
if (spec instanceof RootBuilderSpec) {
Assert.assertTrue(spec instanceof ActionSetRootBuilderSpec);
rootBuilder = (ActionSetRootBuilderSpec) spec;
} else if (spec instanceof ActionBuilderSpec) {
actionBuilders.add((ActionBuilderSpec) spec);
} else {
Assert.fail("There should not be any other builder spec generated!");
}
}
Assert.assertNotNull(rootBuilder);
Assert.assertEquals(rootBuilder.getSourceIdlName(), idl);
Assert.assertEquals(rootBuilder.getResourcePath(), "testAction");
Assert.assertNotNull(rootBuilder.getResourceActions());
Assert.assertEquals(rootBuilder.getResourceActions().size(), 26);
for (RootBuilderMethodSpec methodSpec : rootBuilder.getMethods()) {
Assert.assertTrue(methodSpec.getReturn() instanceof ActionBuilderSpec);
Assert.assertEquals(methodSpec.getReturn().getRootBuilderMethod(), methodSpec);
}
Assert.assertNotNull(actionBuilders);
Assert.assertEquals(actionBuilders.size(), 26);
Set<String> actionNames = new HashSet<String>(Arrays.asList("arrayPromise", "echo", "echoRecord", "echoRecordArray", "echoStringArray", "echoEnumArray", "failCallbackCall", "failCallbackThrow", "failPromiseCall", "failPromiseThrow", "failTaskCall", "failTaskThrow", "failThrowInTask", "get", "nullPromise", "nullTask", "parseq", "parseq3", "returnBool", "returnBoolOptionalParam", "returnInt", "returnIntOptionalParam", "returnVoid", "timeout", "timeoutCallback", "ultimateAnswer"));
for (ActionBuilderSpec spec : actionBuilders) {
Assert.assertTrue(actionNames.contains(spec.getActionName()));
actionNames.remove(spec.getActionName());
if (spec.getActionName().equals("parseq")) {
List<ActionParamBindingMethodSpec> params = spec.getActionParamMethods();
for (ActionParamBindingMethodSpec param : params) {
if (param.getParamName().equals("a")) {
Assert.assertEquals(param.getArgType().getSchema().getType(), DataSchema.Type.INT);
} else if (param.getParamName().equals("b")) {
Assert.assertEquals(param.getArgType().getSchema().getType(), DataSchema.Type.STRING);
} else if (param.getParamName().equals("c")) {
Assert.assertEquals(param.getArgType().getSchema().getType(), DataSchema.Type.BOOLEAN);
} else {
Assert.fail("There should not be any other param method spec generated!");
}
}
Assert.assertEquals(spec.getValueClass().getSchema().getType(), DataSchema.Type.STRING);
}
}
Assert.assertTrue(actionNames.isEmpty());
}
Aggregations