Search in sources :

Example 1 with ClientTestFileView

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

the class CSharpGapicUnitTestTransformer method generateUnitTestCsproj.

private ClientTestFileView generateUnitTestCsproj(GapicInterfaceContext context) {
    ClientTestFileView.Builder builder = generateUnitTestBuilder(context);
    GapicProductConfig productConfig = context.getProductConfig();
    String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), productConfig);
    builder.outputPath(outputPath + File.separator + productConfig.getPackageName() + ".Tests.csproj");
    builder.templateFileName(UNITTEST_CSPROJ_TEMPLATE_FILENAME);
    return builder.build();
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView)

Example 2 with ClientTestFileView

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

the class CSharpGapicUnitTestTransformer method generateUnitTest.

private ClientTestFileView generateUnitTest(GapicInterfaceContext context) {
    ClientTestFileView.Builder builder = generateUnitTestBuilder(context);
    SurfaceNamer namer = context.getNamer();
    String name = namer.getUnitTestClassName(context.getInterfaceConfig());
    String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), context.getProductConfig());
    builder.outputPath(outputPath + File.separator + name + ".g.cs");
    builder.templateFileName(UNITTEST_SNIPPETS_TEMPLATE_FILENAME);
    return builder.build();
}
Also used : SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView)

Example 3 with ClientTestFileView

use of com.google.api.codegen.viewmodel.testing.ClientTestFileView 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)

Example 4 with ClientTestFileView

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

the class PhpGapicSurfaceTestTransformer method createUnitTestFileView.

private ClientTestFileView createUnitTestFileView(GapicInterfaceContext context) {
    addUnitTestImports(context.getImportTypeTable());
    String outputPath = PhpGapicCodePathMapper.newBuilder().setPrefix("tests/unit").build().getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    SurfaceNamer namer = context.getNamer();
    String name = namer.getUnitTestClassName(context.getInterfaceConfig());
    ClientTestClassView.Builder testClass = ClientTestClassView.newBuilder();
    testClass.apiSettingsClassName(namer.getNotImplementedString("PhpGapicSurfaceTestTransformer.generateTestView - apiSettingsClassName"));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(name);
    testClass.apiName(PhpPackageMetadataNamer.getApiNameFromPackageName(namer.getPackageName()).toLowerUnderscore());
    testClass.testCases(createTestCaseViews(context));
    testClass.apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations());
    // Add gRPC client imports.
    for (InterfaceModel grpcInterface : mockServiceTransformer.getGrpcInterfacesForService(context.getApiModel(), context.getProductConfig(), context.getInterfaceModel()).values()) {
        context.getImportTypeTable().getAndSaveNicknameFor(namer.getGrpcClientTypeName(grpcInterface));
    }
    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(UNIT_TEST_TEMPLATE_FILE);
    ImportSectionView importSection = importSectionTransformer.generateImportSection(context.getImportTypeTable().getImports());
    SurfaceNamer testPackageNamer = namer.cloneWithPackageName(namer.getTestPackageName(SurfaceNamer.TestKind.UNIT));
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSection, testPackageNamer);
    testFile.fileHeader(fileHeader);
    return testFile.build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) 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) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 5 with ClientTestFileView

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

the class RubyGapicSurfaceTestTransformer method createUnitTestViews.

// /////////////////////////////////// Unit Test ///////////////////////////////////////
private List<ClientTestFileView> createUnitTestViews(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ClientTestFileView> views = ImmutableList.builder();
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        String testClassName = namer.getUnitTestClassName(context.getInterfaceConfig());
        String outputPath = unitTestPathMapper.getOutputPath(context.getInterfaceModel().getFullName(), productConfig);
        ImportSectionView importSection = importSectionTransformer.generateTestImportSection(context);
        views.add(ClientTestFileView.newBuilder().templateFileName(UNIT_TEST_TEMPLATE_FILE).outputPath(namer.getSourceFilePath(outputPath, testClassName)).testClass(createUnitTestClassView(context, model.hasMultipleServices())).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).apiVersion(packageConfig.apiVersion()).build());
    }
    return views.build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

ClientTestFileView (com.google.api.codegen.viewmodel.testing.ClientTestFileView)5 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)4 InterfaceModel (com.google.api.codegen.config.InterfaceModel)2 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)2 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)2 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)2 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)1 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)1 ImmutableList (com.google.common.collect.ImmutableList)1