Search in sources :

Example 6 with LongrunningOperation

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

the class ServiceClientCallableMethodSampleComposerTest method valid_composeLroCallableMethod_withReturnResponse.

/*Testing composeLroCallableMethod*/
@Test
public void valid_composeLroCallableMethod_withReturnResponse() {
    Descriptors.FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    TypeNode clientType = TypeNode.withReference(VaporReference.builder().setName("EchoClient").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode inputType = TypeNode.withReference(VaporReference.builder().setName("WaitRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("Operation").setPakkage(LRO_PACKAGE_NAME).build());
    TypeNode responseType = TypeNode.withReference(VaporReference.builder().setName("WaitResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode metadataType = TypeNode.withReference(VaporReference.builder().setName("WaitMetadata").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    LongrunningOperation lro = LongrunningOperation.builder().setResponseType(responseType).setMetadataType(metadataType).build();
    Method method = Method.builder().setName("Wait").setInputType(inputType).setOutputType(outputType).setLro(lro).build();
    String results = writeStatements(ServiceClientCallableMethodSampleComposer.composeLroCallableMethod(method, clientType, resourceNames, messageTypes));
    String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", "  WaitRequest request = WaitRequest.newBuilder().build();\n", "  OperationFuture<WaitResponse, WaitMetadata> future =\n", "      echoClient.waitOperationCallable().futureCall(request);\n", "  // Do something.\n", "  WaitResponse response = future.get();\n", "}");
    Assert.assertEquals(results, expected);
}
Also used : LongrunningOperation(com.google.api.generator.gapic.model.LongrunningOperation) Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) Descriptors(com.google.protobuf.Descriptors) TypeNode(com.google.api.generator.engine.ast.TypeNode) Method(com.google.api.generator.gapic.model.Method) Test(org.junit.Test)

Example 7 with LongrunningOperation

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

the class ServiceClientCallableMethodSampleComposerTest method valid_composeRegularCallableMethod_lroRpc.

@Test
public void valid_composeRegularCallableMethod_lroRpc() {
    Descriptors.FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    TypeNode clientType = TypeNode.withReference(VaporReference.builder().setName("EchoClient").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode inputType = TypeNode.withReference(VaporReference.builder().setName("WaitRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("Operation").setPakkage(LRO_PACKAGE_NAME).build());
    TypeNode responseType = TypeNode.withReference(VaporReference.builder().setName("WaitResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode metadataType = TypeNode.withReference(VaporReference.builder().setName("WaitMetadata").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    LongrunningOperation lro = LongrunningOperation.builder().setResponseType(responseType).setMetadataType(metadataType).build();
    Method method = Method.builder().setName("Wait").setInputType(inputType).setOutputType(outputType).setLro(lro).build();
    String results = writeStatements(ServiceClientCallableMethodSampleComposer.composeRegularCallableMethod(method, clientType, resourceNames, messageTypes));
    String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", "  WaitRequest request = WaitRequest.newBuilder().build();\n", "  ApiFuture<Operation> future = echoClient.waitCallable().futureCall(request);\n", "  // Do something.\n", "  Operation response = future.get();\n", "}");
    Assert.assertEquals(results, expected);
}
Also used : LongrunningOperation(com.google.api.generator.gapic.model.LongrunningOperation) Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) Descriptors(com.google.protobuf.Descriptors) TypeNode(com.google.api.generator.engine.ast.TypeNode) Method(com.google.api.generator.gapic.model.Method) Test(org.junit.Test)

Example 8 with LongrunningOperation

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

the class ServiceClientHeaderSampleComposerTest method valid_composeShowcaseMethodSample_lroRpcWithReturnVoid.

@Test
public void valid_composeShowcaseMethodSample_lroRpcWithReturnVoid() {
    Descriptors.FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    TypeNode clientType = TypeNode.withReference(VaporReference.builder().setName("EchoClient").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode inputType = TypeNode.withReference(VaporReference.builder().setName("WaitRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("Operation").setPakkage(LRO_PACKAGE_NAME).build());
    TypeNode responseType = TypeNode.withReference(VaporReference.builder().setName("Empty").setPakkage(PROTO_PACKAGE_NAME).build());
    TypeNode metadataType = TypeNode.withReference(VaporReference.builder().setName("WaitMetadata").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    LongrunningOperation lro = LongrunningOperation.builder().setResponseType(responseType).setMetadataType(metadataType).build();
    TypeNode ttlTypeNode = TypeNode.withReference(VaporReference.builder().setName("Duration").setPakkage(PROTO_PACKAGE_NAME).build());
    MethodArgument ttl = MethodArgument.builder().setName("ttl").setType(ttlTypeNode).setField(Field.builder().setName("ttl").setType(ttlTypeNode).setIsMessage(true).setIsContainedInOneof(true).build()).build();
    List<MethodArgument> arguments = Arrays.asList(ttl);
    Method method = Method.builder().setName("Wait").setInputType(inputType).setOutputType(outputType).setLro(lro).setMethodSignatures(Arrays.asList(arguments)).build();
    String results = writeStatements(ServiceClientHeaderSampleComposer.composeShowcaseMethodSample(method, clientType, arguments, resourceNames, messageTypes));
    String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", "  Duration ttl = Duration.newBuilder().build();\n", "  echoClient.waitAsync(ttl).get();\n", "}");
    Assert.assertEquals(results, expected);
}
Also used : LongrunningOperation(com.google.api.generator.gapic.model.LongrunningOperation) Message(com.google.api.generator.gapic.model.Message) MethodArgument(com.google.api.generator.gapic.model.MethodArgument) ResourceName(com.google.api.generator.gapic.model.ResourceName) Descriptors(com.google.protobuf.Descriptors) TypeNode(com.google.api.generator.engine.ast.TypeNode) Method(com.google.api.generator.gapic.model.Method) Test(org.junit.Test)

Example 9 with LongrunningOperation

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

the class ServiceClientHeaderSampleComposerTest method composeClassHeaderSample_firstMethodIsNotUnaryRpc.

@Test
public void composeClassHeaderSample_firstMethodIsNotUnaryRpc() {
    Descriptors.FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    TypeNode inputType = TypeNode.withReference(VaporReference.builder().setName("WaitRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("Operation").setPakkage(LRO_PACKAGE_NAME).build());
    TypeNode responseType = TypeNode.withReference(VaporReference.builder().setName("WaitResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode metadataType = TypeNode.withReference(VaporReference.builder().setName("WaitMetadata").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    LongrunningOperation lro = LongrunningOperation.builder().setResponseType(responseType).setMetadataType(metadataType).build();
    TypeNode ttlTypeNode = TypeNode.withReference(VaporReference.builder().setName("Duration").setPakkage(PROTO_PACKAGE_NAME).build());
    MethodArgument ttl = MethodArgument.builder().setName("ttl").setType(ttlTypeNode).setField(Field.builder().setName("ttl").setType(ttlTypeNode).setIsMessage(true).setIsContainedInOneof(true).build()).build();
    Method method = Method.builder().setName("Wait").setInputType(inputType).setOutputType(outputType).setLro(lro).setMethodSignatures(Arrays.asList(Arrays.asList(ttl))).build();
    Service service = Service.builder().setName("Echo").setDefaultHost("localhost:7469").setOauthScopes(Arrays.asList("https://www.googleapis.com/auth/cloud-platform")).setPakkage(SHOWCASE_PACKAGE_NAME).setProtoPakkage(SHOWCASE_PACKAGE_NAME).setOriginalJavaPackage(SHOWCASE_PACKAGE_NAME).setOverriddenName("Echo").setMethods(Arrays.asList(method)).build();
    TypeNode clientType = TypeNode.withReference(VaporReference.builder().setName("EchoClient").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    String results = writeStatements(ServiceClientHeaderSampleComposer.composeClassHeaderSample(service, clientType, resourceNames, messageTypes));
    String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", "  Duration ttl = Duration.newBuilder().build();\n", "  WaitResponse response = echoClient.waitAsync(ttl).get();\n", "}");
    Assert.assertEquals(results, expected);
}
Also used : LongrunningOperation(com.google.api.generator.gapic.model.LongrunningOperation) Message(com.google.api.generator.gapic.model.Message) MethodArgument(com.google.api.generator.gapic.model.MethodArgument) ResourceName(com.google.api.generator.gapic.model.ResourceName) Service(com.google.api.generator.gapic.model.Service) Descriptors(com.google.protobuf.Descriptors) TypeNode(com.google.api.generator.engine.ast.TypeNode) Method(com.google.api.generator.gapic.model.Method) Test(org.junit.Test)

Example 10 with LongrunningOperation

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

the class ServiceClientHeaderSampleComposerTest method valid_composeShowcaseMethodSample_lroUnaryRpcWithNoMethodArgument.

@Test
public void valid_composeShowcaseMethodSample_lroUnaryRpcWithNoMethodArgument() {
    Descriptors.FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    TypeNode clientType = TypeNode.withReference(VaporReference.builder().setName("EchoClient").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode inputType = TypeNode.withReference(VaporReference.builder().setName("WaitRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("Operation").setPakkage(LRO_PACKAGE_NAME).build());
    TypeNode responseType = TypeNode.withReference(VaporReference.builder().setName("WaitResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode metadataType = TypeNode.withReference(VaporReference.builder().setName("WaitMetadata").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    LongrunningOperation lro = LongrunningOperation.builder().setResponseType(responseType).setMetadataType(metadataType).build();
    Method method = Method.builder().setName("Wait").setInputType(inputType).setOutputType(outputType).setLro(lro).setMethodSignatures(Collections.emptyList()).build();
    String results = writeStatements(ServiceClientHeaderSampleComposer.composeShowcaseMethodSample(method, clientType, Collections.emptyList(), resourceNames, messageTypes));
    String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", "  WaitResponse response = echoClient.waitAsync().get();\n", "}");
    Assert.assertEquals(results, expected);
}
Also used : LongrunningOperation(com.google.api.generator.gapic.model.LongrunningOperation) Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) Descriptors(com.google.protobuf.Descriptors) TypeNode(com.google.api.generator.engine.ast.TypeNode) Method(com.google.api.generator.gapic.model.Method) Test(org.junit.Test)

Aggregations

TypeNode (com.google.api.generator.engine.ast.TypeNode)12 LongrunningOperation (com.google.api.generator.gapic.model.LongrunningOperation)12 Message (com.google.api.generator.gapic.model.Message)11 Method (com.google.api.generator.gapic.model.Method)11 ResourceName (com.google.api.generator.gapic.model.ResourceName)11 Test (org.junit.Test)10 Descriptors (com.google.protobuf.Descriptors)8 MethodArgument (com.google.api.generator.gapic.model.MethodArgument)4 AnnotationNode (com.google.api.generator.engine.ast.AnnotationNode)2 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)2 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)2 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)2 ApiFunction (com.google.api.core.ApiFunction)1 ApiFuture (com.google.api.core.ApiFuture)1 ApiFutures (com.google.api.core.ApiFutures)1 BetaApi (com.google.api.core.BetaApi)1 BackgroundResource (com.google.api.gax.core.BackgroundResource)1 OperationFuture (com.google.api.gax.longrunning.OperationFuture)1 AbstractFixedSizeCollection (com.google.api.gax.paging.AbstractFixedSizeCollection)1 AbstractPage (com.google.api.gax.paging.AbstractPage)1