Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ggj][codegen][test] feat: add ServiceClientTest.rpcTest for unary and LRO methods #351

Merged
merged 11 commits into from
Sep 26, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
import com.google.api.generator.engine.ast.StringObjectValue;
import com.google.api.generator.engine.ast.TypeNode;
import com.google.api.generator.engine.ast.ValueExpr;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.model.Field;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.MethodArgument;
import com.google.api.generator.gapic.model.ResourceName;
import com.google.api.generator.gapic.utils.JavaStyle;
import com.google.api.generator.gapic.utils.ResourceNameConstants;
import com.google.common.base.Preconditions;
import com.google.longrunning.Operation;
import com.google.protobuf.Any;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -38,6 +41,10 @@
import java.util.stream.Collectors;

public class DefaultValueComposer {
private static TypeNode OPERATION_TYPE =
TypeNode.withReference(ConcreteReference.withClazz(Operation.class));
private static TypeNode ANY_TYPE = TypeNode.withReference(ConcreteReference.withClazz(Any.class));

static Expr createDefaultValue(
MethodArgument methodArg, Map<String, ResourceName> resourceNames) {
if (methodArg.isResourceNameHelper()) {
Expand Down Expand Up @@ -237,4 +244,42 @@ static Expr createSimpleMessageBuilderExpr(
.setReturnType(message.type())
.build();
}

static Expr createSimpleOperationBuilderExpr(String name, VariableExpr responseExpr) {
Expr operationExpr =
MethodInvocationExpr.builder()
.setStaticReferenceType(OPERATION_TYPE)
.setMethodName("newBuilder")
.build();
operationExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(operationExpr)
.setMethodName("setName")
.setArguments(ValueExpr.withValue(StringObjectValue.withValue(name)))
.build();
operationExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(operationExpr)
.setMethodName("setDone")
.setArguments(
ValueExpr.withValue(
PrimitiveValue.builder().setType(TypeNode.BOOLEAN).setValue("true").build()))
.build();
operationExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(operationExpr)
.setMethodName("setResponse")
.setArguments(
MethodInvocationExpr.builder()
.setStaticReferenceType(ANY_TYPE)
.setMethodName("pack")
.setArguments(responseExpr)
.build())
.build();
return MethodInvocationExpr.builder()
.setExprReferenceExpr(operationExpr)
.setMethodName("build")
.setReturnType(OPERATION_TYPE)
.build();
}
}
Loading