Search in sources :

Example 46 with Service

use of com.google.api.generator.gapic.model.Service in project gapic-generator-java by googleapis.

the class GrpcServiceStubClassComposerTest method generateGrpcServiceStubClass_createBatchingCallable.

@Test
public void generateGrpcServiceStubClass_createBatchingCallable() {
    GapicContext context = GrpcTestProtoLoader.instance().parseLogging();
    Service service = context.services().get(0);
    GapicClass clazz = GrpcServiceStubClassComposer.instance().generate(context, service);
    Assert.assertGoldenClass(this.getClass(), clazz, "GrpcLoggingStub.golden");
    Assert.assertEmptySamples(clazz.samples());
}
Also used : GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) GapicContext(com.google.api.generator.gapic.model.GapicContext) Test(org.junit.Test)

Example 47 with Service

use of com.google.api.generator.gapic.model.Service in project gapic-generator-java by googleapis.

the class MockServiceImplClassComposerTest method generateMockServiceImplClasses.

@Test
public void generateMockServiceImplClasses() {
    Service service = context.services().get(0);
    GapicClass clazz = MockServiceImplClassComposer.instance().generate(context, service);
    Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden");
    Assert.assertEmptySamples(clazz.samples());
}
Also used : GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) Test(org.junit.Test)

Example 48 with Service

use of com.google.api.generator.gapic.model.Service in project gapic-generator-java by googleapis.

the class ServiceClientTestClassComposerTest method generateServiceClientTestClasses.

@Test
public void generateServiceClientTestClasses() {
    Service echoProtoService = context.services().get(serviceIndex);
    GapicClass clazz = ServiceClientTestClassComposer.instance().generate(context, echoProtoService);
    Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden");
    Assert.assertEmptySamples(clazz.samples());
}
Also used : GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) Test(org.junit.Test)

Example 49 with Service

use of com.google.api.generator.gapic.model.Service in project gapic-generator-java by googleapis.

the class AbstractServiceClientClassComposer method createVaporTypes.

private static void createVaporTypes(Service service, TypeStore typeStore) {
    // Client stub typeStore.
    typeStore.putAll(String.format("%s.stub", service.pakkage()), Arrays.asList(ClassNames.getServiceStubClassName(service), ClassNames.getServiceStubSettingsClassName(service)));
    // Client ServiceClient and ServiceSettings typeStore.
    typeStore.putAll(service.pakkage(), Arrays.asList(ClassNames.getServiceClientClassName(service), ClassNames.getServiceSettingsClassName(service)));
    // Nested class typeStore.
    for (Method method : service.methods()) {
        if (!method.isPaged()) {
            continue;
        }
        typeStore.putAll(service.pakkage(), Arrays.asList("%sPagedResponse", "%sPage", "%sFixedSizeCollection").stream().map(p -> String.format(p, JavaStyle.toUpperCamelCase(method.name()))).collect(Collectors.toList()), true, ClassNames.getServiceClientClassName(service));
    }
    // Pagination types.
    typeStore.putAll(service.pakkage(), service.methods().stream().filter(m -> m.isPaged()).map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())).collect(Collectors.toList()), true, ClassNames.getServiceClientClassName(service));
}
Also used : Arrays(java.util.Arrays) ServiceClientHeaderSampleComposer(com.google.api.generator.gapic.composer.samplecode.ServiceClientHeaderSampleComposer) OperationFuture(com.google.api.gax.longrunning.OperationFuture) BiFunction(java.util.function.BiFunction) Reference(com.google.api.generator.engine.ast.Reference) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) Variable(com.google.api.generator.engine.ast.Variable) BackgroundResource(com.google.api.gax.core.BackgroundResource) Field(com.google.api.generator.gapic.model.Field) Generated(javax.annotation.Generated) 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) LongrunningOperation(com.google.api.generator.gapic.model.LongrunningOperation) Stream(com.google.api.generator.gapic.model.Method.Stream) Map(java.util.Map) ServiceClientMethodSampleComposer(com.google.api.generator.gapic.composer.samplecode.ServiceClientMethodSampleComposer) ServerStreamingCallable(com.google.api.gax.rpc.ServerStreamingCallable) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) ApiFutures(com.google.api.core.ApiFutures) PageContext(com.google.api.gax.rpc.PageContext) Status(com.google.rpc.Status) Set(java.util.Set) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) ServiceClientCommentComposer(com.google.api.generator.gapic.composer.comment.ServiceClientCommentComposer) Collectors(java.util.stream.Collectors) ApiFuture(com.google.api.core.ApiFuture) Objects(java.util.Objects) ClassNames(com.google.api.generator.gapic.composer.utils.ClassNames) List(java.util.List) ServiceClientCallableMethodSampleComposer(com.google.api.generator.gapic.composer.samplecode.ServiceClientCallableMethodSampleComposer) SampleCodeWriter(com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter) Optional(java.util.Optional) GapicContext(com.google.api.generator.gapic.model.GapicContext) ApiFunction(com.google.api.core.ApiFunction) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) BetaApi(com.google.api.core.BetaApi) TypeNode(com.google.api.generator.engine.ast.TypeNode) BidiStreamingCallable(com.google.api.gax.rpc.BidiStreamingCallable) Kind(com.google.api.generator.gapic.model.GapicClass.Kind) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) PackageChecker(com.google.api.generator.gapic.composer.utils.PackageChecker) HashMap(java.util.HashMap) GapicMetadata(com.google.gapic.metadata.GapicMetadata) Operation(com.google.longrunning.Operation) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Strings(com.google.common.base.Strings) Expr(com.google.api.generator.engine.ast.Expr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) ClientStreamingCallable(com.google.api.gax.rpc.ClientStreamingCallable) TriFunction(com.google.api.generator.util.TriFunction) AbstractFixedSizeCollection(com.google.api.gax.paging.AbstractFixedSizeCollection) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Iterator(java.util.Iterator) AbstractPage(com.google.api.gax.paging.AbstractPage) CastExpr(com.google.api.generator.engine.ast.CastExpr) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) IOException(java.io.IOException) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) Sample(com.google.api.generator.gapic.model.Sample) GapicClass(com.google.api.generator.gapic.model.GapicClass) ResourceName(com.google.api.generator.gapic.model.ResourceName) Trie(com.google.api.generator.util.Trie) TimeUnit(java.util.concurrent.TimeUnit) OperationCallable(com.google.api.gax.rpc.OperationCallable) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Statement(com.google.api.generator.engine.ast.Statement) Service(com.google.api.generator.gapic.model.Service) LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) SuperObjectValue(com.google.api.generator.engine.ast.SuperObjectValue) SampleComposerUtil(com.google.api.generator.gapic.composer.samplecode.SampleComposerUtil) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Message(com.google.api.generator.gapic.model.Message) Collections(java.util.Collections) AbstractPagedListResponse(com.google.api.gax.paging.AbstractPagedListResponse) Method(com.google.api.generator.gapic.model.Method)

Example 50 with Service

use of com.google.api.generator.gapic.model.Service in project gapic-generator-java by googleapis.

the class AbstractServiceClientTestClassComposer method addDynamicTypes.

private void addDynamicTypes(GapicContext context, Service service, TypeStore typeStore) {
    typeStore.putAll(service.pakkage(), Arrays.asList(ClassNames.getMockServiceClassName(service), ClassNames.getServiceClientClassName(service), ClassNames.getServiceSettingsClassName(service)));
    String stubPakkage = String.format("%s.stub", service.pakkage());
    typeStore.put(stubPakkage, getTransportContext().classNames().getTransportServiceStubClassName(service));
    // Pagination types.
    typeStore.putAll(service.pakkage(), service.methods().stream().filter(m -> m.isPaged()).map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())).collect(Collectors.toList()), true, ClassNames.getServiceClientClassName(service));
    for (Service mixinService : context.mixinServices()) {
        typeStore.put(mixinService.pakkage(), ClassNames.getMockServiceClassName(mixinService));
        for (Method mixinMethod : mixinService.methods()) {
            if (!mixinMethod.isPaged()) {
                continue;
            }
            typeStore.put(service.pakkage(), String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, mixinMethod.name()), true, ClassNames.getServiceClientClassName(service));
        }
    }
}
Also used : Arrays(java.util.Arrays) Reference(com.google.api.generator.engine.ast.Reference) Variable(com.google.api.generator.engine.ast.Variable) NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) DefaultValueComposer(com.google.api.generator.gapic.composer.defaultvalue.DefaultValueComposer) Field(com.google.api.generator.gapic.model.Field) Generated(javax.annotation.Generated) 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) After(org.junit.After) ServerStreamingCallable(com.google.api.gax.rpc.ServerStreamingCallable) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) AfterClass(org.junit.AfterClass) ApiClientHeaderProvider(com.google.api.gax.rpc.ApiClientHeaderProvider) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) UUID(java.util.UUID) EmptyLineStatement(com.google.api.generator.engine.ast.EmptyLineStatement) Collectors(java.util.stream.Collectors) ApiStreamObserver(com.google.api.gax.rpc.ApiStreamObserver) ClassNames(com.google.api.generator.gapic.composer.utils.ClassNames) List(java.util.List) Optional(java.util.Optional) Any(com.google.protobuf.Any) GapicContext(com.google.api.generator.gapic.model.GapicContext) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) TypeNode(com.google.api.generator.engine.ast.TypeNode) BeforeClass(org.junit.BeforeClass) BidiStreamingCallable(com.google.api.gax.rpc.BidiStreamingCallable) Kind(com.google.api.generator.gapic.model.GapicClass.Kind) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) Operation(com.google.longrunning.Operation) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Expr(com.google.api.generator.engine.ast.Expr) Lists(com.google.common.collect.Lists) ClientStreamingCallable(com.google.api.gax.rpc.ClientStreamingCallable) TryCatchStatement(com.google.api.generator.engine.ast.TryCatchStatement) LineComment(com.google.api.generator.engine.ast.LineComment) Before(org.junit.Before) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) AbstractMessage(com.google.protobuf.AbstractMessage) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) IOException(java.io.IOException) Test(org.junit.Test) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) GapicClass(com.google.api.generator.gapic.model.GapicClass) ResourceName(com.google.api.generator.gapic.model.ResourceName) ExecutionException(java.util.concurrent.ExecutionException) Statement(com.google.api.generator.engine.ast.Statement) Service(com.google.api.generator.gapic.model.Service) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) 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) Assert(org.junit.Assert) Message(com.google.api.generator.gapic.model.Message) Collections(java.util.Collections) Service(com.google.api.generator.gapic.model.Service) Method(com.google.api.generator.gapic.model.Method)

Aggregations

Service (com.google.api.generator.gapic.model.Service)87 GapicContext (com.google.api.generator.gapic.model.GapicContext)54 GapicClass (com.google.api.generator.gapic.model.GapicClass)48 Message (com.google.api.generator.gapic.model.Message)45 Test (org.junit.Test)45 Method (com.google.api.generator.gapic.model.Method)39 List (java.util.List)39 TypeNode (com.google.api.generator.engine.ast.TypeNode)37 ResourceName (com.google.api.generator.gapic.model.ResourceName)35 Expr (com.google.api.generator.engine.ast.Expr)34 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)32 GapicServiceConfig (com.google.api.generator.gapic.model.GapicServiceConfig)32 ArrayList (java.util.ArrayList)32 Arrays (java.util.Arrays)32 Collectors (java.util.stream.Collectors)32 Path (java.nio.file.Path)31 HashSet (java.util.HashSet)31 Function (java.util.function.Function)31 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)30 Preconditions (com.google.common.base.Preconditions)30