Search in sources :

Example 1 with MockServiceUsageView

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

the class PythonGapicSurfaceTestTransformer method createUnitTestViews.

private List<ViewModel> createUnitTestViews(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ViewModel> models = ImmutableList.builder();
    SurfaceNamer surfacePackageNamer = new PythonSurfaceNamer(productConfig.getPackageName());
    SurfaceNamer testPackageNamer = new PythonSurfaceNamer(surfacePackageNamer.getTestPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        ModelTypeTable typeTable = createTypeTable(surfacePackageNamer.getTestPackageName());
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, surfacePackageNamer, featureConfig);
        String testClassName = surfacePackageNamer.getUnitTestClassName(context.getInterfaceConfig());
        ClientTestClassView testClassView = ClientTestClassView.newBuilder().apiSettingsClassName(surfacePackageNamer.getNotImplementedString("PythonGapicSurfaceTestTransformer.createUnitTestViews - apiSettingsClassName")).apiClassName(surfacePackageNamer.getApiWrapperClassName(context.getInterfaceConfig())).apiVariableName(surfacePackageNamer.getApiWrapperModuleName()).name(testClassName).apiName(surfacePackageNamer.publicClassName(Name.upperCamelKeepUpperAcronyms(context.getInterfaceModel().getSimpleName()))).testCases(createTestCaseViews(context)).apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations()).apiHasUnaryUnaryMethod(hasUnaryUnary(context.getInterfaceConfig())).apiHasUnaryStreamingMethod(hasUnaryStreaming(context.getInterfaceConfig())).apiHasStreamingUnaryMethod(hasStreamingUnary(context.getInterfaceConfig())).apiHasStreamingStreamingMethod(hasStreamingStreaming(context.getInterfaceConfig())).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(ImmutableList.<MockServiceUsageView>of()).build();
        String version = packageConfig.apiVersion();
        String filename = surfacePackageNamer.classFileNameBase(Name.upperCamel(testClassName).join(version)) + ".py";
        String outputPath = Joiner.on(File.separator).join("tests", "unit", "gapic", version, filename);
        ImportSectionView importSection = importSectionTransformer.generateTestImportSection(context);
        models.add(ClientTestFileView.newBuilder().templateFileName(TEST_TEMPLATE_FILE).outputPath(outputPath).testClass(testClassView).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, testPackageNamer)).build());
    }
    return models.build();
}
Also used : MockServiceUsageView(com.google.api.codegen.viewmodel.testing.MockServiceUsageView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 2 with MockServiceUsageView

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

the class RubyGapicSurfaceTestTransformer method createUnitTestClassView.

private ClientTestClassView createUnitTestClassView(GapicInterfaceContext context, boolean packageHasMultipleServices) {
    SurfaceNamer namer = context.getNamer();
    String apiSettingsClassName = namer.getNotImplementedString("RubyGapicSurfaceTestTransformer.generateUnitTestClassView - apiSettingsClassName");
    String testClassName = namer.getNotImplementedString("RubyGapicSurfaceTestTransformer.generateUnitTestClassView - name");
    ImmutableList.Builder<ClientInitParamView> clientInitOptionalParams = ImmutableList.builder();
    if (RubyUtil.hasMajorVersion(context.getProductConfig().getPackageName())) {
        clientInitOptionalParams.add(ClientInitParamView.newBuilder().key("version").value(":" + packageConfig.apiVersion()).build());
    }
    return ClientTestClassView.newBuilder().apiSettingsClassName(apiSettingsClassName).apiClassName(namer.getFullyQualifiedApiWrapperClassName(context.getInterfaceConfig())).name(testClassName).testCases(createUnitTestCaseViews(context, packageHasMultipleServices)).apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations()).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockCredentialsClassName(namer.getMockCredentialsClassName(context.getInterface())).fullyQualifiedCredentialsClassName(namer.getFullyQualifiedCredentialsClassName()).clientInitOptionalParams(clientInitOptionalParams.build()).mockServices(ImmutableList.<MockServiceUsageView>of()).build();
}
Also used : MockServiceUsageView(com.google.api.codegen.viewmodel.testing.MockServiceUsageView) ClientInitParamView(com.google.api.codegen.viewmodel.testing.ClientInitParamView) ImmutableList(com.google.common.collect.ImmutableList) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 3 with MockServiceUsageView

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

the class MockServiceTransformer method createMockServices.

public List<MockServiceUsageView> createMockServices(SurfaceNamer namer, ApiModel model, GapicProductConfig productConfig) {
    List<MockServiceUsageView> mockServices = new ArrayList<>();
    for (InterfaceModel apiInterface : getGrpcInterfacesToMock(model, productConfig)) {
        MockServiceUsageView mockService = MockServiceUsageView.newBuilder().className(namer.getMockServiceClassName(apiInterface)).varName(namer.getMockServiceVarName(apiInterface)).implName(namer.getMockGrpcServiceImplName(apiInterface)).registerFunctionName(namer.getServerRegisterFunctionName(apiInterface)).build();
        mockServices.add(mockService);
    }
    return mockServices;
}
Also used : MockServiceUsageView(com.google.api.codegen.viewmodel.testing.MockServiceUsageView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList)

Example 4 with MockServiceUsageView

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

the class NodeJSGapicSurfaceTestTransformer method generateTestView.

private MockCombinedView generateTestView(ApiModel model, GapicProductConfig productConfig, SurfaceNamer namer) {
    ModelTypeTable typeTable = createTypeTable(productConfig);
    List<MockServiceImplView> impls = new ArrayList<>();
    List<ClientTestClassView> testClasses = new ArrayList<>();
    for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, namer, featureConfig);
        impls.add(MockServiceImplView.newBuilder().mockGrpcClassName(namer.getGrpcServerTypeName(context.getInterfaceModel())).name(namer.getMockGrpcServiceImplName(apiInterface)).grpcMethods(mockServiceTransformer.createMockGrpcMethodViews(context)).build());
    }
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        // We don't need any imports here.
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(productConfig), namer, featureConfig);
        testClasses.add(ClientTestClassView.newBuilder().apiSettingsClassName(namer.getNotImplementedString("NodeJSGapicSurfaceTestTransformer.generateTestView - apiSettingsClassName")).apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig())).name(namer.getNotImplementedString("NodeJSGapicSurfaceTestTransformer.generateTestView - name")).testCases(createTestCaseViews(context)).apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations()).packageServiceName(namer.getPackageServiceName(context.getInterfaceConfig())).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(Collections.<MockServiceUsageView>emptyList()).build());
    }
    ImportSectionView importSection = importSectionTransformer.generateImportSection(typeTable.getImports(), null);
    return MockCombinedView.newBuilder().outputPath(testCaseOutputFile(namer)).serviceImpls(impls).mockServices(new ArrayList<MockServiceUsageView>()).testClasses(testClasses).localPackageName(namer.getLocalPackageName()).templateFileName(TEST_TEMPLATE_FILE).packageHasMultipleServices(model.hasMultipleServices()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).build();
}
Also used : MockServiceUsageView(com.google.api.codegen.viewmodel.testing.MockServiceUsageView) MockServiceImplView(com.google.api.codegen.viewmodel.testing.MockServiceImplView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ArrayList(java.util.ArrayList) ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

MockServiceUsageView (com.google.api.codegen.viewmodel.testing.MockServiceUsageView)4 InterfaceModel (com.google.api.codegen.config.InterfaceModel)3 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)2 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)2 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)2 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)2 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)2 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 ViewModel (com.google.api.codegen.viewmodel.ViewModel)1 ClientInitParamView (com.google.api.codegen.viewmodel.testing.ClientInitParamView)1 MockServiceImplView (com.google.api.codegen.viewmodel.testing.MockServiceImplView)1