Search in sources :

Example 1 with MockServiceImplView

use of com.google.api.codegen.viewmodel.testing.MockServiceImplView 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(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        // 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)).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).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).build();
}
Also used : 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.config.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 2 with MockServiceImplView

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

the class GoGapicSurfaceTestTransformer method generateMockServiceView.

private MockCombinedView generateMockServiceView(ApiModel model, GapicProductConfig productConfig, SurfaceNamer namer) {
    ModelTypeTable typeTable = GoGapicSurfaceTransformer.createTypeTable();
    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(apiInterface)).name(namer.getMockGrpcServiceImplName(apiInterface)).grpcMethods(mockServiceTransformer.createMockGrpcMethodViews(context)).build());
    }
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        // We don't need any import here.
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, namer, featureConfig);
        testClasses.add(ClientTestClassView.newBuilder().apiSettingsClassName(namer.getNotImplementedString("GoGapicSurfaceTestTransformer.generateMockServiceView - apiSettingsClassName")).apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig())).name(namer.getNotImplementedString("GoGapicSurfaceTestTransformer.generateMockServiceView - name")).testCases(createTestCaseViews(context)).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(Collections.emptyList()).build());
    }
    ImportSectionView importSection = importSectionTransformer.generateImportSection(typeTable.getImports());
    return MockCombinedView.newBuilder().outputPath(productConfig.getPackageName() + File.separator + "mock_test.go").serviceImpls(impls).testClasses(testClasses).templateFileName(MOCK_SERVICE_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).mockServices(mockServiceTransformer.createMockServices(namer, model, productConfig)).build();
}
Also used : 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.config.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)2 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)2 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)2 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)2 MockServiceImplView (com.google.api.codegen.viewmodel.testing.MockServiceImplView)2 ArrayList (java.util.ArrayList)2