Search in sources :

Example 81 with Method

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

the class ServiceClientMethodSampleComposerTest method valid_composeDefaultSample_isPagedMethod.

@Test
public void valid_composeDefaultSample_isPagedMethod() {
    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("PagedExpandRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("PagedExpandResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    Method method = Method.builder().setName("PagedExpand").setInputType(inputType).setOutputType(outputType).setMethodSignatures(Collections.emptyList()).setPageSizeFieldName(PAGINATED_FIELD_NAME).build();
    String results = writeStatements(ServiceClientMethodSampleComposer.composeCanonicalSample(method, clientType, resourceNames, messageTypes));
    String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", "  PagedExpandRequest request =\n", "      PagedExpandRequest.newBuilder()\n", "          .setContent(\"content951530617\")\n", "          .setPageSize(883849137)\n", "          .setPageToken(\"pageToken873572522\")\n", "          .build();\n", "  for (EchoResponse element : echoClient.pagedExpand(request).iterateAll()) {\n", "    // doThingsWith(element);\n", "  }\n", "}");
    Assert.assertEquals(results, expected);
}
Also used : 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

Method (com.google.api.generator.gapic.model.Method)81 TypeNode (com.google.api.generator.engine.ast.TypeNode)75 Message (com.google.api.generator.gapic.model.Message)71 ResourceName (com.google.api.generator.gapic.model.ResourceName)60 Test (org.junit.Test)44 List (java.util.List)39 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)38 Expr (com.google.api.generator.engine.ast.Expr)37 ArrayList (java.util.ArrayList)36 Service (com.google.api.generator.gapic.model.Service)34 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)33 Arrays (java.util.Arrays)33 Field (com.google.api.generator.gapic.model.Field)32 Collectors (java.util.stream.Collectors)32 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)31 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)31 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)31 Preconditions (com.google.common.base.Preconditions)31 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)30 Variable (com.google.api.generator.engine.ast.Variable)30