Search in sources :

Example 1 with TestCaseTransformer

use of com.google.api.codegen.transformer.TestCaseTransformer in project toolkit by googleapis.

the class RubyGapicSurfaceTestTransformer method createSmokeTestClassView.

private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context) {
    boolean packageHasMultipleServices = context.getApiModel().hasMultipleServices();
    String outputPath = smokeTestPathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    SurfaceNamer namer = context.getNamer();
    RubyPackageMetadataNamer metadataNamer = new RubyPackageMetadataNamer(context.getNamer().getPackageName());
    String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
    MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
    MethodContext methodContext = context.asRequestMethodContext(method);
    TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(methodContext.getMethodConfig());
    GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(methodContext, 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(outputPath, name));
    testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
    testClass.apiMethod(apiMethodView);
    testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
    testClass.projectIdVariableName(metadataNamer.getProjectVariable(true));
    testClass.apiVersion(packageConfig.apiVersion());
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSectionTransformer.generateSmokeTestImportSection(context), namer);
    testClass.fileHeader(fileHeader);
    return testClass.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) MethodContext(com.google.api.codegen.config.MethodContext) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) TestCaseTransformer(com.google.api.codegen.transformer.TestCaseTransformer) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 2 with TestCaseTransformer

use of com.google.api.codegen.transformer.TestCaseTransformer 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);
        TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
        TestCaseView testCase = testCaseTransformer.createTestCaseView(requestMethodContext, new SymbolTable(), createUnitTestCaseInitCodeContext(context, method), getMethodType(requestMethodContext));
        testCases.add(testCase);
    }
    return testCases.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.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)

Example 3 with TestCaseTransformer

use of com.google.api.codegen.transformer.TestCaseTransformer in project toolkit by googleapis.

the class RubyGapicSurfaceTestTransformer method createSmokeTestCaseApiMethodView.

private OptionalArrayMethodView createSmokeTestCaseApiMethodView(GapicMethodContext context, boolean packageHasMultipleServices) {
    OptionalArrayMethodView initialApiMethodView = new DynamicLangApiMethodTransformer(new RubyApiMethodParamTransformer()).generateApiMethod(context);
    OptionalArrayMethodView.Builder apiMethodView = initialApiMethodView.toBuilder();
    TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
    InitCodeTransformer initCodeTransformer = new InitCodeTransformer(false);
    InitCodeView initCodeView = initCodeTransformer.generateInitCode(context, testCaseTransformer.createSmokeTestInitContext(context));
    apiMethodView.initCode(initCodeView);
    return apiMethodView.build();
}
Also used : OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) TestCaseTransformer(com.google.api.codegen.transformer.TestCaseTransformer) DynamicLangApiMethodTransformer(com.google.api.codegen.transformer.DynamicLangApiMethodTransformer) InitCodeTransformer(com.google.api.codegen.transformer.InitCodeTransformer) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Aggregations

TestCaseTransformer (com.google.api.codegen.transformer.TestCaseTransformer)3 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)2 MethodModel (com.google.api.codegen.config.MethodModel)2 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)2 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)1 MethodContext (com.google.api.codegen.config.MethodContext)1 DynamicLangApiMethodTransformer (com.google.api.codegen.transformer.DynamicLangApiMethodTransformer)1 InitCodeTransformer (com.google.api.codegen.transformer.InitCodeTransformer)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 SymbolTable (com.google.api.codegen.util.SymbolTable)1 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)1 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)1 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)1 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)1 ImmutableList (com.google.common.collect.ImmutableList)1