Search in sources :

Example 6 with FileHeaderView

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

the class PythonPackageMetadataTransformer method computeInitFiles.

/**
 * Determines which __init__.py files to generate given a list of Python packages. Each Python
 * package corresponds to exactly one __init__.py file, although the contents of that file depend
 * on whether the package is a namespace package.
 */
private List<ViewModel> computeInitFiles(List<String> packages, SurfaceNamer namer, GapicProductConfig productConfig) {
    List<ViewModel> initFiles = new ArrayList<>();
    for (String packageName : packages) {
        final String template;
        if (isNamespacePackage(packageName)) {
            template = NAMESPACE_INIT_TEMPLATE_FILE;
        } else if (isVersionedDirectoryPackage(namer, packageName)) {
            continue;
        } else {
            template = INIT_TEMPLATE_FILE;
        }
        String outputPath = Paths.get(packageName.replace(".", File.separator)).resolve("__init__.py").toString();
        FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), new PythonSurfaceNamer(productConfig.getPackageName()));
        initFiles.add(SimpleInitFileView.create(template, outputPath, fileHeader));
    }
    return initFiles;
}
Also used : ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView)

Example 7 with FileHeaderView

use of com.google.api.codegen.viewmodel.FileHeaderView 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();
    TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
    GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, 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.transformer.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) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView)

Example 8 with FileHeaderView

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

the class CSharpGapicUnitTestTransformer method generateUnitTestBuilder.

private ClientTestFileView.Builder generateUnitTestBuilder(GapicInterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    String name = namer.getUnitTestClassName(context.getInterfaceConfig());
    ClientTestClassView.Builder testClass = ClientTestClassView.newBuilder();
    testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.apiVariableName("client");
    testClass.name(name);
    testClass.testCases(createTestCaseViews(context));
    testClass.apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations());
    testClass.mockServices(mockServiceTransformer.createMockServices(context.getNamer(), context.getApiModel(), context.getProductConfig()));
    testClass.grpcServiceClassName(namer.getGrpcServiceClassName(context.getInterfaceModel()));
    testClass.missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress());
    testClass.missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes());
    testClass.reroutedGrpcClients(csharpCommonTransformer.generateReroutedGrpcView(context));
    testClass.hasLongRunningOperations(context.getLongRunningMethods().iterator().hasNext());
    ClientTestFileView.Builder testFile = ClientTestFileView.newBuilder();
    testFile.testClass(testClass.build());
    // Imports must be done as the last step to catch all imports.
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
    testFile.fileHeader(fileHeader);
    return testFile;
}
Also used : ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView)

Example 9 with FileHeaderView

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

the class GoGapicSurfaceTestTransformer method createSmokeTestClassView.

private SmokeTestClassView createSmokeTestClassView(InterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
    MethodContext methodContext = context.asRequestMethodContext(method);
    SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
    StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(methodContext);
    testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(namer.getSmokeTestClassName(context.getInterfaceConfig()));
    testClass.outputPath(context.getProductConfig().getPackageName() + File.separator + method.getSimpleName() + "_smoke_test.go");
    testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
    testClass.apiMethod(apiMethodView);
    testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
    // The shared code above add imports both for input and output.
    // Since we use short decls, we don't need to import anything for output.
    context.getImportTypeTable().getImports().clear();
    method.getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
    testClass.fileHeader(fileHeader);
    return testClass.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) MethodContext(com.google.api.codegen.transformer.MethodContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView)

Example 10 with FileHeaderView

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

the class JavaSurfaceTestTransformer method createUnitTestFileView.

// /////////////////////////////////// Unit Test /////////////////////////////////////////
private ClientTestFileView createUnitTestFileView(InterfaceContext context) {
    addUnitTestImports(context);
    String outputPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    SurfaceNamer namer = context.getNamer();
    String name = namer.getUnitTestClassName(context.getInterfaceConfig());
    ClientTestClassView.Builder testClass = ClientTestClassView.newBuilder();
    testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiStubSettingsClassName(namer.getApiStubSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(name);
    testClass.testCases(createTestCaseViews(context));
    testClass.apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations());
    testClass.mockServices(mockServiceTransformer.createMockServices(context.getNamer(), context.getApiModel(), context.getProductConfig()));
    testClass.missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress());
    testClass.missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes());
    ClientTestFileView.Builder testFile = ClientTestFileView.newBuilder();
    testFile.testClass(testClass.build());
    testFile.outputPath(namer.getSourceFilePath(outputPath, name));
    testFile.templateFileName(unitTestTemplateFile);
    // Imports must be done as the last step to catch all imports.
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
    testFile.fileHeader(fileHeader);
    return testFile.build();
}
Also used : ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView)

Aggregations

FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)11 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)10 MethodModel (com.google.api.codegen.config.MethodModel)5 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)5 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)4 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)4 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)3 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 ClientTestFileView (com.google.api.codegen.viewmodel.testing.ClientTestFileView)3 MethodContext (com.google.api.codegen.transformer.MethodContext)2 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)2 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 TestCaseTransformer (com.google.api.codegen.transformer.TestCaseTransformer)1 SymbolTable (com.google.api.codegen.util.SymbolTable)1 ViewModel (com.google.api.codegen.viewmodel.ViewModel)1 MockServiceImplFileView (com.google.api.codegen.viewmodel.testing.MockServiceImplFileView)1 MockServiceView (com.google.api.codegen.viewmodel.testing.MockServiceView)1 ArrayList (java.util.ArrayList)1