Search in sources :

Example 11 with LongrunningOperation

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

the class ServiceClientMethodSampleComposerTest method valid_composeDefaultSample_hasLroMethodWithReturnResponse.

@Test
public void valid_composeDefaultSample_hasLroMethodWithReturnResponse() {
    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();
    Method method = Method.builder().setName("Wait").setInputType(inputType).setOutputType(outputType).setMethodSignatures(Collections.emptyList()).setLro(lro).build();
    String results = writeStatements(ServiceClientMethodSampleComposer.composeCanonicalSample(method, clientType, resourceNames, messageTypes));
    String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", "  WaitRequest request = WaitRequest.newBuilder().build();\n", "  echoClient.waitAsync(request).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) TypeNode(com.google.api.generator.engine.ast.TypeNode) Method(com.google.api.generator.gapic.model.Method) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Example 12 with LongrunningOperation

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

the class ServiceClientMethodSampleComposerTest method valid_composeDefaultSample_hasLroMethodWithReturnVoid.

@Test
public void valid_composeDefaultSample_hasLroMethodWithReturnVoid() {
    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).setMethodSignatures(Collections.emptyList()).setLro(lro).build();
    String results = writeStatements(ServiceClientMethodSampleComposer.composeCanonicalSample(method, clientType, resourceNames, messageTypes));
    String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", "  WaitRequest request = WaitRequest.newBuilder().build();\n", "  WaitResponse response = echoClient.waitAsync(request).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) TypeNode(com.google.api.generator.engine.ast.TypeNode) Method(com.google.api.generator.gapic.model.Method) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) 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