Search in sources :

Example 86 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class ParserTest method parseMethodSignatures_validArgstAndEmptyString.

@Test
public void parseMethodSignatures_validArgstAndEmptyString() {
    // TODO(miraleung): Move this to MethodSignatureParserTest.
    MethodDescriptor methodDescriptor = echoService.getMethods().get(0);
    assertEquals("Echo", methodDescriptor.getName());
    TypeNode inputType = TypeParser.parseType(methodDescriptor.getInputType());
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Set<ResourceName> outputResourceNames = new HashSet<>();
    List<List<MethodArgument>> methodArgs = MethodSignatureParser.parseMethodSignatures(methodDescriptor, ECHO_PACKAGE, inputType, messageTypes, resourceNames, outputResourceNames);
    assertEquals(Collections.emptyList(), methodArgs.get(0));
    assertEquals(1, methodArgs.get(1).size());
    assertEquals("parent", methodArgs.get(1).get(0).name());
}
Also used : Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) TypeNode(com.google.api.generator.engine.ast.TypeNode) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 87 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class ParserTest method parseMethods_basicLro.

@Test
public void parseMethods_basicLro() {
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Set<ResourceName> outputResourceNames = new HashSet<>();
    List<Method> methods = Parser.parseMethods(echoService, ECHO_PACKAGE, messageTypes, resourceNames, Optional.empty(), outputResourceNames, Transport.GRPC);
    assertEquals(10, methods.size());
    // Methods should appear in the same order as in the protobuf file.
    Method waitMethod = methods.get(7);
    assertEquals("Wait", waitMethod.name());
    assertTrue(waitMethod.hasLro());
    TypeNode waitResponseType = messageTypes.get("com.google.showcase.v1beta1.WaitResponse").type();
    TypeNode waitMetadataType = messageTypes.get("com.google.showcase.v1beta1.WaitMetadata").type();
    assertThat(waitMethod.lro().responseType()).isEqualTo(waitResponseType);
    assertThat(waitMethod.lro().metadataType()).isEqualTo(waitMetadataType);
}
Also used : Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) Method(com.google.api.generator.gapic.model.Method) TypeNode(com.google.api.generator.engine.ast.TypeNode) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 88 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class ParserTest method parseMethodSignatures_empty.

@Test
public void parseMethodSignatures_empty() {
    // TODO(miraleung): Move this to MethodSignatureParserTest.
    MethodDescriptor methodDescriptor = echoService.getMethods().get(5);
    assertEquals("PagedExpand", methodDescriptor.getName());
    TypeNode inputType = TypeParser.parseType(methodDescriptor.getInputType());
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Set<ResourceName> outputResourceNames = new HashSet<>();
    assertThat(MethodSignatureParser.parseMethodSignatures(methodDescriptor, ECHO_PACKAGE, inputType, messageTypes, resourceNames, outputResourceNames)).isEmpty();
}
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) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 89 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class ServiceClientMethodSampleComposerTest method valid_composeDefaultSample_pureUnaryReturnResponse.

@Test
public void valid_composeDefaultSample_pureUnaryReturnResponse() {
    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("EchoRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("EchoResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    Method method = Method.builder().setName("Echo").setInputType(inputType).setOutputType(outputType).setMethodSignatures(Collections.emptyList()).build();
    String results = writeStatements(ServiceClientMethodSampleComposer.composeCanonicalSample(method, clientType, resourceNames, messageTypes));
    String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", "  EchoRequest request =\n", "      EchoRequest.newBuilder()\n", "          .setName(FoobarName.ofProjectFoobarName(\"[PROJECT]\"," + " \"[FOOBAR]\").toString())\n", "          .setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\"," + " \"[FOOBAR]\").toString())\n", "          .setSeverity(Severity.forNumber(0))\n", "          .setFoobar(Foobar.newBuilder().build())\n", "          .build();\n", "  EchoResponse response = echoClient.echo(request);\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)

Example 90 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class ServiceClientMethodSampleComposerTest method invalid_composeDefaultSample_isPagedMethod.

@Test
public void invalid_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("NotExistRequest").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();
    Assert.assertThrows(NullPointerException.class, () -> ServiceClientMethodSampleComposer.composeCanonicalSample(method, clientType, resourceNames, messageTypes));
}
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

TypeNode (com.google.api.generator.engine.ast.TypeNode)232 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)119 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)111 Test (org.junit.Test)103 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)84 Message (com.google.api.generator.gapic.model.Message)81 ArrayList (java.util.ArrayList)81 Expr (com.google.api.generator.engine.ast.Expr)77 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)77 Method (com.google.api.generator.gapic.model.Method)72 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)68 ResourceName (com.google.api.generator.gapic.model.ResourceName)65 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)64 List (java.util.List)63 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)61 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)59 Variable (com.google.api.generator.engine.ast.Variable)55 Statement (com.google.api.generator.engine.ast.Statement)53 Collectors (java.util.stream.Collectors)46 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)45