Search in sources :

Example 1 with SmokeTestConfig

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

the class TestCaseTransformer method createSmokeTestInitContext.

public InitCodeContext createSmokeTestInitContext(MethodContext context) {
    SmokeTestConfig testConfig = context.getInterfaceConfig().getSmokeTestConfig();
    InitCodeContext.InitCodeOutputType outputType;
    ImmutableMap<String, FieldConfig> fieldConfigMap;
    if (context.isFlattenedMethodContext()) {
        outputType = InitCodeContext.InitCodeOutputType.FieldList;
        fieldConfigMap = FieldConfig.toFieldConfigMap(context.getFlatteningConfig().getFlattenedFieldConfigs().values());
    } else {
        outputType = InitCodeContext.InitCodeOutputType.SingleObject;
        fieldConfigMap = FieldConfig.toFieldConfigMap(context.getMethodConfig().getRequiredFieldConfigs());
    }
    // Store project ID variable name into the symbol table since it is used
    // by the execute method as a parameter.
    SymbolTable table = new SymbolTable();
    table.getNewSymbol(Name.from(InitFieldConfig.PROJECT_ID_VARIABLE_NAME));
    InitCodeContext.Builder contextBuilder = InitCodeContext.newBuilder().initObjectType(testConfig.getMethod().getInputType()).suggestedName(Name.from("request")).outputType(outputType).initValueConfigMap(InitCodeTransformer.createCollectionMap(context)).initFieldConfigStrings(testConfig.getInitFieldConfigStrings()).symbolTable(table).fieldConfigMap(fieldConfigMap);
    if (context.isFlattenedMethodContext()) {
        contextBuilder.initFields(context.getFlatteningConfig().getFlattenedFields());
    }
    return contextBuilder.build();
}
Also used : InitFieldConfig(com.google.api.codegen.metacode.InitFieldConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) SmokeTestConfig(com.google.api.codegen.config.SmokeTestConfig) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext)

Example 2 with SmokeTestConfig

use of com.google.api.codegen.config.SmokeTestConfig 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();
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
    GapicMethodContext methodContext = context.asFlattenedMethodContext(method, 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.transformer.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)

Aggregations

SmokeTestConfig (com.google.api.codegen.config.SmokeTestConfig)2 FieldConfig (com.google.api.codegen.config.FieldConfig)1 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)1 InitFieldConfig (com.google.api.codegen.metacode.InitFieldConfig)1 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 SymbolTable (com.google.api.codegen.util.SymbolTable)1 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)1 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)1