Search in sources :

Example 26 with Message

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

the class ParserTest method parseResourceNames_inputTypeHasReferenceNotInMethodSignature.

@Test
public void parseResourceNames_inputTypeHasReferenceNotInMethodSignature() {
    FileDescriptor testingFileDescriptor = TestingOuterClass.getDescriptor();
    ServiceDescriptor testingService = testingFileDescriptor.getServices().get(0);
    assertEquals(testingService.getName(), "Testing");
    Map<String, Message> messageTypes = Parser.parseMessages(testingFileDescriptor);
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(testingFileDescriptor);
    Set<ResourceName> outputResourceNames = new HashSet<>();
    Parser.parseService(testingFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
    assertEquals(2, outputResourceNames.size());
    ResourceName resname = resourceNames.get("showcase.googleapis.com/Session");
    assertThat(outputResourceNames).contains(resname);
    resname = resourceNames.get("showcase.googleapis.com/Test");
    assertThat(outputResourceNames).contains(resname);
}
Also used : Message(com.google.api.generator.gapic.model.Message) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) ResourceName(com.google.api.generator.gapic.model.ResourceName) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with Message

use of com.google.api.generator.gapic.model.Message 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 28 with Message

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

the class ParserTest method parseMethods_basic.

@Test
public void parseMethods_basic() {
    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 echoMethod = methods.get(0);
    assertEquals(echoMethod.name(), "Echo");
    assertEquals(echoMethod.stream(), Method.Stream.NONE);
    // Detailed method signature parsing tests are in a separate unit test.
    List<List<MethodArgument>> methodSignatures = echoMethod.methodSignatures();
    assertEquals(8, methodSignatures.size());
    Method expandMethod = methods.get(1);
    assertEquals("Expand", expandMethod.name());
    assertEquals(TypeNode.withReference(VaporReference.builder().setName("ExpandRequest").setPakkage(ECHO_PACKAGE).build()), expandMethod.inputType());
    assertEquals(TypeNode.withReference(VaporReference.builder().setName("EchoResponse").setPakkage(ECHO_PACKAGE).build()), expandMethod.outputType());
    assertEquals(Method.Stream.SERVER, expandMethod.stream());
    assertEquals(1, expandMethod.methodSignatures().size());
    assertMethodArgumentEquals("content", TypeNode.STRING, ImmutableList.of(), expandMethod.methodSignatures().get(0).get(0));
    assertMethodArgumentEquals("error", TypeNode.withReference(createStatusReference()), ImmutableList.of(), expandMethod.methodSignatures().get(0).get(1));
    Method collectMethod = methods.get(2);
    assertEquals("Collect", collectMethod.name());
    assertEquals(Method.Stream.CLIENT, collectMethod.stream());
    Method chatMethod = methods.get(3);
    assertEquals("Chat", chatMethod.name());
    assertEquals(Method.Stream.BIDI, chatMethod.stream());
}
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) Method(com.google.api.generator.gapic.model.Method) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 29 with Message

use of com.google.api.generator.gapic.model.Message 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 30 with Message

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

the class ParserTest method parseLro_missingMetadataType.

@Test
public void parseLro_missingMetadataType() {
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    MethodDescriptor waitMethodDescriptor = echoService.getMethods().get(7);
    assertEquals("Wait", waitMethodDescriptor.getName());
    messageTypes.remove("com.google.showcase.v1beta1.WaitMetadata");
    assertThrows(NullPointerException.class, () -> Parser.parseLro("", waitMethodDescriptor, messageTypes));
}
Also used : Message(com.google.api.generator.gapic.model.Message) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor) Test(org.junit.Test)

Aggregations

Message (com.google.api.generator.gapic.model.Message)123 ResourceName (com.google.api.generator.gapic.model.ResourceName)85 TypeNode (com.google.api.generator.engine.ast.TypeNode)74 Test (org.junit.Test)68 Method (com.google.api.generator.gapic.model.Method)60 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)44 HashSet (java.util.HashSet)39 ArrayList (java.util.ArrayList)36 Service (com.google.api.generator.gapic.model.Service)35 List (java.util.List)34 Expr (com.google.api.generator.engine.ast.Expr)32 Field (com.google.api.generator.gapic.model.Field)31 Descriptors (com.google.protobuf.Descriptors)30 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)29 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)26 ServiceDescriptor (com.google.protobuf.Descriptors.ServiceDescriptor)26 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)25 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)25 Statement (com.google.api.generator.engine.ast.Statement)24 HashMap (java.util.HashMap)23