use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.
the class CSharpGapicSmokeTestTransformer method generateSmokeTestViewBuilder.
private SmokeTestClassView.Builder generateSmokeTestViewBuilder(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
SmokeTestClassView.Builder smokeTestBuilder = SmokeTestClassView.newBuilder();
SmokeTestConfig smokeTestConfig = context.getInterfaceConfig().getSmokeTestConfig();
if (smokeTestConfig == null) {
return null;
}
MethodModel method = smokeTestConfig.getMethod();
GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(defaultMethodContext.getMethodConfig());
GapicMethodContext methodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
smokeTestBuilder.name(name);
smokeTestBuilder.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
smokeTestBuilder.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(context, methodContext);
smokeTestBuilder.apiMethod(apiMethodView);
smokeTestBuilder.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), namer));
// must be done as the last step to catch all imports
smokeTestBuilder.fileHeader(fileHeaderTransformer.generateFileHeader(context));
return smokeTestBuilder;
}
use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.
the class CSharpGapicUnitTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
MethodConfig methodConfig = context.getMethodConfig(method);
if (methodConfig.isGrpcStreaming()) {
// TODO: Add support for streaming methods
} else if (methodConfig.isFlattening()) {
ClientMethodType clientMethodTypeSync;
ClientMethodType clientMethodTypeAsync;
if (methodConfig.isPageStreaming()) {
// TODO: Add support for page-streaming methods
continue;
} else if (defaultMethodContext.isLongRunningMethodContext()) {
// TODO: Add support for LRO methods
continue;
} else {
clientMethodTypeSync = ClientMethodType.FlattenedMethod;
clientMethodTypeAsync = ClientMethodType.FlattenedAsyncCallSettingsMethod;
}
if (methodConfig.getRerouteToGrpcInterface() != null) {
// TODO: Add support for rerouted methods
continue;
}
GapicMethodContext requestContext = context.asRequestMethodContext(method);
for (FlatteningConfig flatteningGroup : FlatteningConfigs.getRepresentativeFlatteningConfigs(methodConfig.getFlatteningConfigs())) {
GapicMethodContext methodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
testCaseViews.add(createFlattenedTestCase(methodContext, requestContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeSync, Synchronicity.Sync));
testCaseViews.add(createFlattenedTestCase(methodContext, requestContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeAsync, Synchronicity.Async));
}
testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Sync));
testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Async));
} else {
if (methodConfig.isPageStreaming() || defaultMethodContext.isLongRunningMethodContext() || methodConfig.getRerouteToGrpcInterface() != null) {
// TODO: Add support for page-streaming, LRO, and rerouted methods
continue;
}
GapicMethodContext requestContext = context.asRequestMethodContext(method);
testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Sync));
testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Async));
}
}
return testCaseViews;
}
use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.
the class CSharpApiMethodTransformer method generateApiMethods.
@Override
public List<StaticLangApiMethodView> generateApiMethods(InterfaceContext interfaceContext) {
Preconditions.checkArgument(interfaceContext instanceof GapicInterfaceContext, "Only applicable for protobuf-based API in CSharp.");
GapicInterfaceContext context = (GapicInterfaceContext) interfaceContext;
List<ParamWithSimpleDoc> pagedMethodAdditionalParams = new ImmutableList.Builder<ParamWithSimpleDoc>().addAll(csharpCommonTransformer.pagedMethodAdditionalParams()).addAll(csharpCommonTransformer.callSettingsParam()).build();
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
// gRPC streaming methods.
for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
MethodConfig methodConfig = context.getMethodConfig(method);
MethodContext requestMethodContext = context.asRequestMethodContext(method);
if (methodConfig.isGrpcStreaming()) {
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup).withCallingForms(ImmutableList.of(CallingForm.FlattenedStreamingBidi, CallingForm.FlattenedStreamingServer));
apiMethods.add(generateGrpcStreamingFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam(), null));
}
}
requestMethodContext = requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestStreamingBidi, CallingForm.RequestStreamingServer));
apiMethods.add(generateGrpcStreamingRequestObjectMethod(requestMethodContext, null));
} else if (requestMethodContext.isLongRunningMethodContext()) {
// LRO methods.
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
apiMethods.addAll(generateFlattenedLroMethods(methodContext));
}
}
apiMethods.add(generateAsyncOperationRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.LongRunningRequestAsyncPollUntilComplete)), csharpCommonTransformer.callSettingsParam(), true, null));
apiMethods.add(generateOperationRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.LongRunningRequestPollUntilComplete)), csharpCommonTransformer.callSettingsParam(), null));
} else if (methodConfig.isPageStreaming()) {
// Paged streaming methods.
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
apiMethods.addAll(generatePageStreamingFlattenedMethods(methodContext, pagedMethodAdditionalParams));
}
}
apiMethods.add(generatePagedRequestObjectAsyncMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestAsyncPaged, CallingForm.RequestAsyncPagedAll, CallingForm.RequestAsyncPagedPageSize)), csharpCommonTransformer.callSettingsParam(), null));
apiMethods.add(generatePagedRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestPaged, CallingForm.RequestPagedAll, CallingForm.RequestPagedPageSize)), csharpCommonTransformer.callSettingsParam(), null));
} else {
// Unary methods.
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
apiMethods.addAll(generateNormalFlattenedMethods(methodContext));
}
}
apiMethods.add(generateRequestObjectAsyncMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.RequestAsync)), csharpCommonTransformer.callSettingsParam(), ClientMethodType.AsyncRequestObjectCallSettingsMethod, null));
apiMethods.add(generateRequestObjectAsyncMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.RequestAsync)), csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.AsyncRequestObjectCancellationMethod, null));
apiMethods.add(generateRequestObjectMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.Request)), csharpCommonTransformer.callSettingsParam(), null));
}
}
return apiMethods;
}
use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.
the class GoGapicSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
ClientMethodType clientMethodType = ClientMethodType.RequestObjectMethod;
if (methodContext.getMethodConfig().isPageStreaming()) {
clientMethodType = ClientMethodType.PagedRequestObjectMethod;
} else if (methodContext.isLongRunningMethodContext()) {
clientMethodType = ClientMethodType.OperationRequestObjectMethod;
}
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
return testCaseViews;
}
use of com.google.api.codegen.config.GapicMethodContext in project toolkit by googleapis.
the class NodeJSGapicSurfaceTestTransformer method createSmokeTestClassView.
private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context, boolean packageHasMultipleServices) {
SurfaceNamer namer = context.getNamer();
String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(defaultMethodContext, 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(SMOKE_TEST_OUTPUT_BASE_PATH, name));
testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
testClass.apiMethod(apiMethodView);
testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
testClass.fileHeader(fileHeader);
return testClass.build();
}
Aggregations