Search in sources :

Example 6 with SymbolTable

use of com.google.api.codegen.util.SymbolTable 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 7 with SymbolTable

use of com.google.api.codegen.util.SymbolTable 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 8 with SymbolTable

use of com.google.api.codegen.util.SymbolTable in project toolkit by googleapis.

the class PhpGapicSurfaceTestTransformer method createSmokeTestClassViewBuilder.

private SmokeTestClassView.Builder createSmokeTestClassViewBuilder(GapicInterfaceContext context) {
    addSmokeTestImports(context.getImportTypeTable());
    SurfaceNamer namer = context.getNamer();
    MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
    GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
    SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
    OptionalArrayMethodView apiMethod = createSmokeTestCaseApiMethodView(flattenedMethodContext);
    testClass.apiSettingsClassName(context.getNamer().getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(context.getNamer().getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.apiName(PhpPackageMetadataNamer.getApiNameFromPackageName(context.getNamer().getPackageName()).toLowerUnderscore());
    testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
    testClass.apiMethod(apiMethod);
    testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethod.initCode(), context.getNamer()));
    testClass.methodName(namer.getTestCaseName(new SymbolTable(), method));
    ImportSectionView importSection = importSectionTransformer.generateImportSection(context.getImportTypeTable().getImports());
    SurfaceNamer testPackageNamer = namer.cloneWithPackageName(namer.getTestPackageName(SurfaceNamer.TestKind.SYSTEM));
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSection, testPackageNamer);
    testClass.fileHeader(fileHeader);
    return testClass;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) SymbolTable(com.google.api.codegen.util.SymbolTable) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 9 with SymbolTable

use of com.google.api.codegen.util.SymbolTable 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 10 with SymbolTable

use of com.google.api.codegen.util.SymbolTable in project toolkit by googleapis.

the class RubyGapicSurfaceTestTransformer method createUnitTestCaseViews.

private List<TestCaseView> createUnitTestCaseViews(GapicInterfaceContext context, boolean packageHasMultipleServices) {
    ImmutableList.Builder<TestCaseView> testCases = ImmutableList.builder();
    for (MethodModel method : context.getSupportedMethods()) {
        GapicMethodContext requestMethodContext = context.withNewTypeTable().asRequestMethodContext(method);
        MethodConfig methodConfig = requestMethodContext.getMethodConfig();
        TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
        TestCaseView testCase = testCaseTransformer.createTestCaseView(requestMethodContext, new SymbolTable(), createUnitTestCaseInitCodeContext(context, method), getMethodType(methodConfig));
        testCases.add(testCase);
    }
    return testCases.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ImmutableList(com.google.common.collect.ImmutableList) TestCaseTransformer(com.google.api.codegen.transformer.TestCaseTransformer) SymbolTable(com.google.api.codegen.util.SymbolTable)

Aggregations

SymbolTable (com.google.api.codegen.util.SymbolTable)14 MethodModel (com.google.api.codegen.config.MethodModel)8 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)7 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)7 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)7 ClientMethodType (com.google.api.codegen.viewmodel.ClientMethodType)5 ArrayList (java.util.ArrayList)5 FieldConfig (com.google.api.codegen.config.FieldConfig)4 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)3 MethodConfig (com.google.api.codegen.config.MethodConfig)3 Schema (com.google.api.codegen.discovery.Schema)3 LinkedList (java.util.LinkedList)3 FieldModel (com.google.api.codegen.config.FieldModel)2 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)2 StaticLangApiMessageView (com.google.api.codegen.viewmodel.StaticLangApiMessageView)2 ImmutableList (com.google.common.collect.ImmutableList)2 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)1 SmokeTestConfig (com.google.api.codegen.config.SmokeTestConfig)1 SchemaTransformationContext (com.google.api.codegen.discogapic.SchemaTransformationContext)1 Method (com.google.api.codegen.discovery.Method)1