use of com.google.api.codegen.viewmodel.testing.TestCaseView 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()) {
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 (methodConfig.isLongRunningOperation()) {
// 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;
}
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
GapicMethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
testCaseViews.add(createFlattenedTestCase(methodContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeSync, Synchronicity.Sync));
testCaseViews.add(createFlattenedTestCase(methodContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeAsync, Synchronicity.Async));
}
GapicMethodContext requestContext = context.asRequestMethodContext(method);
testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Sync));
testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Async));
} else {
if (methodConfig.isPageStreaming() || methodConfig.isLongRunningOperation() || 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.viewmodel.testing.TestCaseView 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.getMethodConfig().isLongRunningOperation()) {
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.viewmodel.testing.TestCaseView 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.getMethodConfig().isLongRunningOperation()) {
clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
} else if (methodContext.getMethodConfig().isPageStreaming()) {
clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
}
Iterable<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.viewmodel.testing.TestCaseView 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);
MethodConfig methodConfig = requestMethodContext.getMethodConfig();
TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
TestCaseView testCase = testCaseTransformer.createTestCaseView(requestMethodContext, new SymbolTable(), createUnitTestCaseInitCodeContext(context, method), getMethodType(methodConfig));
testCases.add(testCase);
}
return testCases.build();
}
use of com.google.api.codegen.viewmodel.testing.TestCaseView in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(InterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
MethodConfig methodConfig = context.getMethodConfig(method);
if (methodConfig.isGrpcStreaming()) {
if (methodConfig.getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
// Issue: https://github.com/googleapis/toolkit/issues/946
continue;
}
addGrpcStreamingTestImports(context, methodConfig.getGrpcStreamingType());
MethodContext methodContext = context.asRequestMethodContext(method);
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, ClientMethodType.CallableMethod));
} else if (methodConfig.isFlattening()) {
ClientMethodType clientMethodType;
if (methodConfig.isPageStreaming()) {
clientMethodType = ClientMethodType.PagedFlattenedMethod;
} else if (methodConfig.isLongRunningOperation()) {
clientMethodType = ClientMethodType.AsyncOperationFlattenedMethod;
} else {
clientMethodType = ClientMethodType.FlattenedMethod;
}
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), flatteningGroup.getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, valueGenerator);
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
} else {
// TODO: Add support of non-flattening method
// Github issue: https://github.com/googleapis/toolkit/issues/393
System.err.println("Non-flattening method test is not supported yet for " + method.getSimpleName());
}
}
return testCaseViews;
}
Aggregations