Search in sources :

Example 1 with LocalChannelProvider

use of com.google.api.gax.grpc.testing.LocalChannelProvider in project gapic-generator-java by googleapis.

the class ServiceClientTestClassComposer method createClassMemberVarExprs.

@Override
protected Map<String, VariableExpr> createClassMemberVarExprs(Service service, GapicContext context, TypeStore typeStore) {
    BiFunction<String, TypeNode, VariableExpr> varExprFn = (name, type) -> VariableExpr.withVariable(Variable.builder().setName(name).setType(type).build());
    // Keep keys sorted in alphabetical order to ensure that the test output is deterministic.
    Map<String, TypeNode> fields = new TreeMap<>();
    fields.put(getMockServiceVarName(service), typeStore.get(ClassNames.getMockServiceClassName(service)));
    for (Service mixinService : context.mixinServices()) {
        fields.put(getMockServiceVarName(mixinService), typeStore.get(ClassNames.getMockServiceClassName(mixinService)));
    }
    fields.put(SERVICE_HELPER_VAR_NAME, FIXED_GRPC_TYPESTORE.get("MockServiceHelper"));
    fields.put(CLIENT_VAR_NAME, typeStore.get(ClassNames.getServiceClientClassName(service)));
    fields.put(CHANNEL_PROVIDER_VAR_NAME, FIXED_GRPC_TYPESTORE.get("LocalChannelProvider"));
    return fields.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> varExprFn.apply(e.getKey(), e.getValue()), (u, v) -> {
        throw new IllegalStateException();
    }, TreeMap::new));
}
Also used : LocalChannelProvider(com.google.api.gax.grpc.testing.LocalChannelProvider) Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) Variable(com.google.api.generator.engine.ast.Variable) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) GaxGrpcProperties(com.google.api.gax.grpc.GaxGrpcProperties) DefaultValueComposer(com.google.api.generator.gapic.composer.defaultvalue.DefaultValueComposer) Field(com.google.api.generator.gapic.model.Field) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Method(com.google.api.generator.gapic.model.Method) MethodArgument(com.google.api.generator.gapic.model.MethodArgument) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) Map(java.util.Map) MockServiceHelper(com.google.api.gax.grpc.testing.MockServiceHelper) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) Collectors(java.util.stream.Collectors) ClassNames(com.google.api.generator.gapic.composer.utils.ClassNames) List(java.util.List) GapicContext(com.google.api.generator.gapic.model.GapicContext) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) AbstractServiceClientTestClassComposer(com.google.api.generator.gapic.composer.common.AbstractServiceClientTestClassComposer) Function(java.util.function.Function) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ArrayList(java.util.ArrayList) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) TryCatchStatement(com.google.api.generator.engine.ast.TryCatchStatement) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) InstanceofExpr(com.google.api.generator.engine.ast.InstanceofExpr) AbstractMessage(com.google.protobuf.AbstractMessage) CastExpr(com.google.api.generator.engine.ast.CastExpr) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) ResourceName(com.google.api.generator.gapic.model.ResourceName) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Statement(com.google.api.generator.engine.ast.Statement) Service(com.google.api.generator.gapic.model.Service) TreeMap(java.util.TreeMap) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) Preconditions(com.google.common.base.Preconditions) StatusCode(com.google.api.gax.rpc.StatusCode) Message(com.google.api.generator.gapic.model.Message) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) Service(com.google.api.generator.gapic.model.Service) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

GaxGrpcProperties (com.google.api.gax.grpc.GaxGrpcProperties)1 LocalChannelProvider (com.google.api.gax.grpc.testing.LocalChannelProvider)1 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)1 MockServiceHelper (com.google.api.gax.grpc.testing.MockServiceHelper)1 MockStreamObserver (com.google.api.gax.grpc.testing.MockStreamObserver)1 StatusCode (com.google.api.gax.rpc.StatusCode)1 AnnotationNode (com.google.api.generator.engine.ast.AnnotationNode)1 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)1 CastExpr (com.google.api.generator.engine.ast.CastExpr)1 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)1 EnumRefExpr (com.google.api.generator.engine.ast.EnumRefExpr)1 Expr (com.google.api.generator.engine.ast.Expr)1 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)1 InstanceofExpr (com.google.api.generator.engine.ast.InstanceofExpr)1 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)1 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)1 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)1 PrimitiveValue (com.google.api.generator.engine.ast.PrimitiveValue)1 ScopeNode (com.google.api.generator.engine.ast.ScopeNode)1 Statement (com.google.api.generator.engine.ast.Statement)1