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();
}
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();
}
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;
}
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();
}
Aggregations