Search in sources :

Example 1 with ClientMethodType

use of com.google.api.codegen.viewmodel.ClientMethodType 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()) {
        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 (methodConfig.isLongRunningOperation()) {
                // 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;
            }
            for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                GapicMethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                testCaseViews.add(createFlattenedTestCase(methodContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeSync, Synchronicity.Sync));
                testCaseViews.add(createFlattenedTestCase(methodContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeAsync, Synchronicity.Async));
            }
            GapicMethodContext requestContext = context.asRequestMethodContext(method);
            testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Sync));
            testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Async));
        } else {
            if (methodConfig.isPageStreaming() || methodConfig.isLongRunningOperation() || 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) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) 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 2 with ClientMethodType

use of com.google.api.codegen.viewmodel.ClientMethodType 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.getMethodConfig().isLongRunningOperation()) {
            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.transformer.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 3 with ClientMethodType

use of com.google.api.codegen.viewmodel.ClientMethodType in project toolkit by googleapis.

the class PythonGapicSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
    ImmutableList.Builder<TestCaseView> testCaseViews = ImmutableList.builder();
    // certain string until all of the types have been disambiguated.
    for (int i = 0; i < 2; ++i) {
        testCaseViews = ImmutableList.builder();
        SymbolTable testNameTable = new SymbolTable();
        for (MethodModel method : context.getSupportedMethods()) {
            GapicMethodContext methodContext = context.asRequestMethodContext(method);
            ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
            if (methodContext.getMethodConfig().isLongRunningOperation()) {
                clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
            } else if (methodContext.getMethodConfig().isPageStreaming()) {
                clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
            }
            Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
            InitCodeOutputType initCodeOutputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
            InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
            testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
        }
    }
    return testCaseViews.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ImmutableList(com.google.common.collect.ImmutableList) FieldConfig(com.google.api.codegen.config.FieldConfig) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)

Example 4 with ClientMethodType

use of com.google.api.codegen.viewmodel.ClientMethodType in project toolkit by googleapis.

the class JavaSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(InterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        if (methodConfig.isGrpcStreaming()) {
            if (methodConfig.getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
                // Issue: https://github.com/googleapis/toolkit/issues/946
                continue;
            }
            addGrpcStreamingTestImports(context, methodConfig.getGrpcStreamingType());
            MethodContext methodContext = context.asRequestMethodContext(method);
            InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
            testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, ClientMethodType.CallableMethod));
        } else if (methodConfig.isFlattening()) {
            ClientMethodType clientMethodType;
            if (methodConfig.isPageStreaming()) {
                clientMethodType = ClientMethodType.PagedFlattenedMethod;
            } else if (methodConfig.isLongRunningOperation()) {
                clientMethodType = ClientMethodType.AsyncOperationFlattenedMethod;
            } else {
                clientMethodType = ClientMethodType.FlattenedMethod;
            }
            for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), flatteningGroup.getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, valueGenerator);
                testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
            }
        } else {
            // TODO: Add support of non-flattening method
            // Github issue: https://github.com/googleapis/toolkit/issues/393
            System.err.println("Non-flattening method test is not supported yet for " + method.getSimpleName());
        }
    }
    return testCaseViews;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) 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) MethodContext(com.google.api.codegen.transformer.MethodContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext)

Example 5 with ClientMethodType

use of com.google.api.codegen.viewmodel.ClientMethodType in project toolkit by googleapis.

the class PhpGapicSurfaceTestTransformer 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);
        if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
            // Issue: https://github.com/googleapis/toolkit/issues/946
            continue;
        }
        InitCodeOutputType initCodeOutputType = InitCodeOutputType.FieldList;
        if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.BidiStreaming) {
            initCodeOutputType = InitCodeOutputType.SingleObject;
        }
        ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
        if (methodContext.getMethodConfig().isLongRunningOperation()) {
            clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
        } else if (methodContext.getMethodConfig().isPageStreaming()) {
            clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
        }
        Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
        InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
        testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
    }
    return testCaseViews;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)

Aggregations

MethodModel (com.google.api.codegen.config.MethodModel)5 SymbolTable (com.google.api.codegen.util.SymbolTable)5 ClientMethodType (com.google.api.codegen.viewmodel.ClientMethodType)5 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)5 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)4 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)4 ArrayList (java.util.ArrayList)4 FieldConfig (com.google.api.codegen.config.FieldConfig)2 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)2 MethodConfig (com.google.api.codegen.config.MethodConfig)2 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)2 MethodContext (com.google.api.codegen.transformer.MethodContext)1 ImmutableList (com.google.common.collect.ImmutableList)1