Search in sources :

Example 1 with ActionParamBindingMethodSpec

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);
    }
}
Also used : ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec) ActionParamBindingMethodSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionParamBindingMethodSpec) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema)

Example 2 with ActionParamBindingMethodSpec

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());
}
Also used : ActionBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionBuilderSpec) ActionParamBindingMethodSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionParamBindingMethodSpec) ArrayList(java.util.ArrayList) ActionSetRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionSetRootBuilderSpec) RootBuilderMethodSpec(com.linkedin.restli.tools.clientgen.builderspec.RootBuilderMethodSpec) RootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.RootBuilderSpec) SimpleRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.SimpleRootBuilderSpec) ActionSetRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionSetRootBuilderSpec) CollectionRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.CollectionRootBuilderSpec) BuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.BuilderSpec) RestMethodBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.RestMethodBuilderSpec) RootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.RootBuilderSpec) ActionBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionBuilderSpec) SimpleRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.SimpleRootBuilderSpec) ActionSetRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionSetRootBuilderSpec) FinderBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.FinderBuilderSpec) CollectionRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.CollectionRootBuilderSpec) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ActionParamBindingMethodSpec (com.linkedin.restli.tools.clientgen.builderspec.ActionParamBindingMethodSpec)2 ClassTemplateSpec (com.linkedin.pegasus.generator.spec.ClassTemplateSpec)1 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)1 ActionBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.ActionBuilderSpec)1 ActionSetRootBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.ActionSetRootBuilderSpec)1 BuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.BuilderSpec)1 CollectionRootBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.CollectionRootBuilderSpec)1 FinderBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.FinderBuilderSpec)1 RestMethodBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.RestMethodBuilderSpec)1 RootBuilderMethodSpec (com.linkedin.restli.tools.clientgen.builderspec.RootBuilderMethodSpec)1 RootBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.RootBuilderSpec)1 SimpleRootBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.SimpleRootBuilderSpec)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Test (org.testng.annotations.Test)1