Search in sources :

Example 1 with GapicMethodContext

use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.

the class CSharpGapicSmokeTestTransformer method generateSmokeTestViewBuilder.

private SmokeTestClassView.Builder generateSmokeTestViewBuilder(GapicInterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
    SmokeTestClassView.Builder smokeTestBuilder = SmokeTestClassView.newBuilder();
    SmokeTestConfig smokeTestConfig = context.getInterfaceConfig().getSmokeTestConfig();
    if (smokeTestConfig == null) {
        return null;
    }
    MethodModel method = smokeTestConfig.getMethod();
    GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(defaultMethodContext.getMethodConfig());
    GapicMethodContext methodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
    smokeTestBuilder.name(name);
    smokeTestBuilder.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    smokeTestBuilder.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(context, methodContext);
    smokeTestBuilder.apiMethod(apiMethodView);
    smokeTestBuilder.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), namer));
    // must be done as the last step to catch all imports
    smokeTestBuilder.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    return smokeTestBuilder;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) SmokeTestConfig(com.google.api.codegen.config.SmokeTestConfig) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 2 with GapicMethodContext

use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.

the class CSharpGapicUnitTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
        MethodConfig methodConfig = context.getMethodConfig(method);
        if (methodConfig.isGrpcStreaming()) {
        // TODO: Add support for streaming methods
        } else if (methodConfig.isFlattening()) {
            ClientMethodType clientMethodTypeSync;
            ClientMethodType clientMethodTypeAsync;
            if (methodConfig.isPageStreaming()) {
                // TODO: Add support for page-streaming methods
                continue;
            } else if (defaultMethodContext.isLongRunningMethodContext()) {
                // TODO: Add support for LRO methods
                continue;
            } else {
                clientMethodTypeSync = ClientMethodType.FlattenedMethod;
                clientMethodTypeAsync = ClientMethodType.FlattenedAsyncCallSettingsMethod;
            }
            if (methodConfig.getRerouteToGrpcInterface() != null) {
                // TODO: Add support for rerouted methods
                continue;
            }
            GapicMethodContext requestContext = context.asRequestMethodContext(method);
            for (FlatteningConfig flatteningGroup : FlatteningConfigs.getRepresentativeFlatteningConfigs(methodConfig.getFlatteningConfigs())) {
                GapicMethodContext methodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
                testCaseViews.add(createFlattenedTestCase(methodContext, requestContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeSync, Synchronicity.Sync));
                testCaseViews.add(createFlattenedTestCase(methodContext, requestContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeAsync, Synchronicity.Async));
            }
            testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Sync));
            testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Async));
        } else {
            if (methodConfig.isPageStreaming() || defaultMethodContext.isLongRunningMethodContext() || methodConfig.getRerouteToGrpcInterface() != null) {
                // TODO: Add support for page-streaming, LRO, and rerouted methods
                continue;
            }
            GapicMethodContext requestContext = context.asRequestMethodContext(method);
            testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Sync));
            testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Async));
        }
    }
    return testCaseViews;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 3 with GapicMethodContext

use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.

the class CSharpApiMethodTransformer method generateApiMethods.

@Override
public List<StaticLangApiMethodView> generateApiMethods(InterfaceContext interfaceContext) {
    Preconditions.checkArgument(interfaceContext instanceof GapicInterfaceContext, "Only applicable for protobuf-based API in CSharp.");
    GapicInterfaceContext context = (GapicInterfaceContext) interfaceContext;
    List<ParamWithSimpleDoc> pagedMethodAdditionalParams = new ImmutableList.Builder<ParamWithSimpleDoc>().addAll(csharpCommonTransformer.pagedMethodAdditionalParams()).addAll(csharpCommonTransformer.callSettingsParam()).build();
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    // gRPC streaming methods.
    for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        MethodContext requestMethodContext = context.asRequestMethodContext(method);
        if (methodConfig.isGrpcStreaming()) {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup).withCallingForms(ImmutableList.of(CallingForm.FlattenedStreamingBidi, CallingForm.FlattenedStreamingServer));
                    apiMethods.add(generateGrpcStreamingFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam(), null));
                }
            }
            requestMethodContext = requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestStreamingBidi, CallingForm.RequestStreamingServer));
            apiMethods.add(generateGrpcStreamingRequestObjectMethod(requestMethodContext, null));
        } else if (requestMethodContext.isLongRunningMethodContext()) {
            // LRO methods.
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
                    apiMethods.addAll(generateFlattenedLroMethods(methodContext));
                }
            }
            apiMethods.add(generateAsyncOperationRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.LongRunningRequestAsyncPollUntilComplete)), csharpCommonTransformer.callSettingsParam(), true, null));
            apiMethods.add(generateOperationRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.LongRunningRequestPollUntilComplete)), csharpCommonTransformer.callSettingsParam(), null));
        } else if (methodConfig.isPageStreaming()) {
            // Paged streaming methods.
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
                    apiMethods.addAll(generatePageStreamingFlattenedMethods(methodContext, pagedMethodAdditionalParams));
                }
            }
            apiMethods.add(generatePagedRequestObjectAsyncMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestAsyncPaged, CallingForm.RequestAsyncPagedAll, CallingForm.RequestAsyncPagedPageSize)), csharpCommonTransformer.callSettingsParam(), null));
            apiMethods.add(generatePagedRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestPaged, CallingForm.RequestPagedAll, CallingForm.RequestPagedPageSize)), csharpCommonTransformer.callSettingsParam(), null));
        } else {
            // Unary methods.
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
                    apiMethods.addAll(generateNormalFlattenedMethods(methodContext));
                }
            }
            apiMethods.add(generateRequestObjectAsyncMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.RequestAsync)), csharpCommonTransformer.callSettingsParam(), ClientMethodType.AsyncRequestObjectCallSettingsMethod, null));
            apiMethods.add(generateRequestObjectAsyncMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.RequestAsync)), csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.AsyncRequestObjectCancellationMethod, null));
            apiMethods.add(generateRequestObjectMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.Request)), csharpCommonTransformer.callSettingsParam(), null));
        }
    }
    return apiMethods;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) MethodContext(com.google.api.codegen.config.MethodContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) ParamWithSimpleDoc(com.google.api.codegen.transformer.ParamWithSimpleDoc) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 4 with GapicMethodContext

use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.

the class GoGapicSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        GapicMethodContext methodContext = context.asRequestMethodContext(method);
        ClientMethodType clientMethodType = ClientMethodType.RequestObjectMethod;
        if (methodContext.getMethodConfig().isPageStreaming()) {
            clientMethodType = ClientMethodType.PagedRequestObjectMethod;
        } else if (methodContext.isLongRunningMethodContext()) {
            clientMethodType = ClientMethodType.OperationRequestObjectMethod;
        }
        InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
        testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
    }
    return testCaseViews;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext)

Example 5 with GapicMethodContext

use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.

the class NodeJSGapicSurfaceTestTransformer method createSmokeTestClassView.

private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context, boolean packageHasMultipleServices) {
    SurfaceNamer namer = context.getNamer();
    String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
    MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
    GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
    GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
    SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
    OptionalArrayMethodView apiMethodView = createSmokeTestCaseApiMethodView(flattenedMethodContext, packageHasMultipleServices);
    testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(name);
    testClass.outputPath(namer.getSourceFilePath(SMOKE_TEST_OUTPUT_BASE_PATH, name));
    testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
    testClass.apiMethod(apiMethodView);
    testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
    testClass.fileHeader(fileHeader);
    return testClass.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView)

Aggregations

GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)19 MethodModel (com.google.api.codegen.config.MethodModel)18 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)10 ArrayList (java.util.ArrayList)8 SymbolTable (com.google.api.codegen.util.SymbolTable)7 ImmutableList (com.google.common.collect.ImmutableList)7 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)6 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)6 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)4 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)4 ClientMethodType (com.google.api.codegen.viewmodel.ClientMethodType)4 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)4 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)4 FieldConfig (com.google.api.codegen.config.FieldConfig)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)3 InterfaceModel (com.google.api.codegen.config.InterfaceModel)3 MethodConfig (com.google.api.codegen.config.MethodConfig)3 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)3 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)3 LongRunningConfig (com.google.api.codegen.config.LongRunningConfig)2