use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.
the class PythonGapicSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ImmutableList.Builder<TestCaseView> testCaseViews = ImmutableList.builder();
// certain string until all of the types have been disambiguated.
for (int i = 0; i < 2; ++i) {
testCaseViews = ImmutableList.builder();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
if (methodContext.isLongRunningMethodContext()) {
clientMethodType = ClientMethodType.LongRunningOptionalArrayMethod;
} else if (methodContext.getMethodConfig().isPageStreaming()) {
clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
}
Collection<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
InitCodeOutputType initCodeOutputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
}
return testCaseViews.build();
}
use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.
the class PythonGapicSurfaceTestTransformer method createSmokeTestClassView.
private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context, SurfaceNamer testPackageNamer) {
SurfaceNamer namer = context.getNamer();
String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
String version = packageConfig.apiVersion();
String filename = namer.classFileNameBase(Name.upperCamel(name).join(version)) + ".py";
String outputPath = Joiner.on(File.separator).join("tests", "system", "gapic", version, filename);
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
GapicMethodContext methodContext = context.asRequestMethodContext(method);
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(methodContext, flatteningGroup);
OptionalArrayMethodView apiMethodView = createSmokeTestCaseApiMethodView(flattenedMethodContext);
boolean requireProjectId = testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer());
ImportSectionView importSection = importSectionTransformer.generateSmokeTestImportSection(context, requireProjectId);
return SmokeTestClassView.newBuilder().apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig())).apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig())).apiVariableName(namer.getApiWrapperModuleName()).name(name).outputPath(outputPath).templateFileName(SMOKE_TEST_TEMPLATE_FILE).apiMethod(apiMethodView).requireProjectId(requireProjectId).fileHeader(fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSection, testPackageNamer)).build();
}
use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method generateRestInterfaceConfigViews.
private List<RestInterfaceConfigView> generateRestInterfaceConfigViews(GapicInterfaceContext context) {
List<RestInterfaceConfigView> configViews = new ArrayList<>();
GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
SurfaceNamer namer = context.getNamer();
Map<String, List<HttpRule>> interfaces = new TreeMap<>();
Service serviceConfig = serviceModel.getServiceConfig();
for (MethodModel methodModel : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(methodModel);
MethodConfig methodConfig = methodContext.getMethodConfig();
Method method = methodContext.getMethod();
// REST does not support streaming methods
if (methodConfig.isGrpcStreaming()) {
continue;
}
String interfaceName = methodConfig.getRerouteToGrpcInterface() == null ? context.getInterface().getFullName() : methodConfig.getRerouteToGrpcInterface();
HttpRule httpRule = getHttpRule(method.getOptionFields()).toBuilder().setSelector(String.format("%s.%s", interfaceName, method.getSimpleName())).build();
addHttpRuleToMap(interfaces, interfaceName, httpRule);
}
for (HttpRule httpRule : serviceConfig.getHttp().getRulesList()) {
String selector = httpRule.getSelector();
String interfaceName = selector.substring(0, selector.lastIndexOf("."));
addHttpRuleToMap(interfaces, interfaceName, httpRule);
}
for (Map.Entry<String, List<HttpRule>> entry : interfaces.entrySet()) {
configViews.add(generateRestInterfaceConfigView(entry.getKey(), entry.getValue(), namer));
}
return configViews;
}
use of com.google.api.codegen.config.GapicMethodContext 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();
MethodContext methodContext = context.asRequestMethodContext(method);
TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(methodContext.getMethodConfig());
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(methodContext, 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();
}
use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.
the class RubyGapicSurfaceTestTransformer method createUnitTestCaseViews.
private List<TestCaseView> createUnitTestCaseViews(GapicInterfaceContext context, boolean packageHasMultipleServices) {
ImmutableList.Builder<TestCaseView> testCases = ImmutableList.builder();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext requestMethodContext = context.withNewTypeTable().asRequestMethodContext(method);
TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
TestCaseView testCase = testCaseTransformer.createTestCaseView(requestMethodContext, new SymbolTable(), createUnitTestCaseInitCodeContext(context, method), getMethodType(requestMethodContext));
testCases.add(testCase);
}
return testCases.build();
}
Aggregations