use of com.google.api.codegen.viewmodel.testing.PageStreamingResponseView in project toolkit by googleapis.
the class TestCaseTransformer method createPageStreamingResponseViews.
private List<PageStreamingResponseView> createPageStreamingResponseViews(MethodContext methodContext) {
MethodConfig methodConfig = methodContext.getMethodConfig();
SurfaceNamer namer = methodContext.getNamer();
List<PageStreamingResponseView> pageStreamingResponseViews = new ArrayList<>();
if (!methodConfig.isPageStreaming()) {
return pageStreamingResponseViews;
}
FieldConfig resourcesFieldConfig = methodConfig.getPageStreaming().getResourcesFieldConfig();
FieldModel resourcesField = resourcesFieldConfig.getField();
String resourceTypeName = methodContext.getTypeTable().getAndSaveNicknameForElementType(resourcesField);
// Construct the list of function calls needed to retrieve paged resource from response object.
ImmutableList.Builder<String> resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
for (FieldModel field : resourcesFieldConfig.getFieldPath()) {
resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(field));
}
pageStreamingResponseViews.add(PageStreamingResponseView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterNames(resourcesFieldGetFunctionList.build()).resourcesIterateMethod(namer.getPagedResponseIterateMethod()).resourcesVarName(namer.localVarName(Name.from("resources"))).build());
if (methodContext.getFeatureConfig().useResourceNameFormatOption(resourcesFieldConfig)) {
resourceTypeName = methodContext.getNamer().getAndSaveElementResourceTypeName(methodContext.getTypeTable(), resourcesFieldConfig);
resourcesFieldGetFunctionList = new ImmutableList.Builder<>();
for (FieldModel field : resourcesFieldConfig.getFieldPath()) {
resourcesFieldGetFunctionList.add(namer.getFieldGetFunctionName(methodContext.getFeatureConfig(), resourcesFieldConfig));
}
String expectedTransformFunction = null;
if (methodContext.getFeatureConfig().useResourceNameConverters(resourcesFieldConfig)) {
expectedTransformFunction = namer.getResourceTypeParseMethodName(methodContext.getTypeTable(), resourcesFieldConfig);
}
pageStreamingResponseViews.add(PageStreamingResponseView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterNames(resourcesFieldGetFunctionList.build()).resourcesIterateMethod(namer.getPagedResponseIterateMethod(methodContext.getFeatureConfig(), resourcesFieldConfig)).expectedValueTransformFunction(expectedTransformFunction).resourcesVarName(namer.localVarName(Name.from("resource_names"))).build());
}
return pageStreamingResponseViews;
}
Aggregations