Search in sources :

Example 16 with ResourceName

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

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

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

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

the class ResourceNameParserTest method parseResourceNames_deletedTopic.

@Test
public void parseResourceNames_deletedTopic() {
    Map<String, ResourceName> typeStringsToResourceNames = ResourceNameParser.parseResourceNamesFromFile(lockerServiceFileDescriptor);
    assertEquals(4, typeStringsToResourceNames.size());
    ResourceName resourceName = typeStringsToResourceNames.get("pubsub.googleapis.com/Topic");
    assertEquals(1, resourceName.patterns().size());
    assertEquals(ResourceNameConstants.DELETED_TOPIC_LITERAL, resourceName.patterns().get(0));
    assertEquals(ResourceNameConstants.DELETED_TOPIC_LITERAL, resourceName.variableName());
    assertEquals("pubsub.googleapis.com/Topic", resourceName.resourceTypeString());
    assertEquals(MAIN_PACKAGE, resourceName.pakkage());
    assertFalse(resourceName.hasParentMessageName());
    assertFalse(resourceName.isOnlyWildcard());
}
Also used : ResourceName(com.google.api.generator.gapic.model.ResourceName) Test(org.junit.Test)

Example 20 with ResourceName

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

the class ResourceNameParserTest method parseResourceNames_basicOnePattern.

@Test
public void parseResourceNames_basicOnePattern() {
    Map<String, ResourceName> typeStringsToResourceNames = ResourceNameParser.parseResourceNamesFromFile(lockerServiceFileDescriptor);
    assertEquals(4, typeStringsToResourceNames.size());
    ResourceName resourceName = typeStringsToResourceNames.get("cloudbilling.googleapis.com/BillingAccount");
    assertEquals(1, resourceName.patterns().size());
    assertEquals("billingAccounts/{billing_account}", resourceName.patterns().get(0));
    assertEquals("billing_account", resourceName.variableName());
    assertEquals("cloudbilling.googleapis.com/BillingAccount", resourceName.resourceTypeString());
    assertEquals(MAIN_PACKAGE, resourceName.pakkage());
    assertFalse(resourceName.hasParentMessageName());
    assertThat(resourceName.parentMessageName()).isNull();
    assertFalse(resourceName.isOnlyWildcard());
}
Also used : ResourceName(com.google.api.generator.gapic.model.ResourceName) Test(org.junit.Test)

Aggregations

ResourceName (com.google.api.generator.gapic.model.ResourceName)112 Message (com.google.api.generator.gapic.model.Message)82 Test (org.junit.Test)76 TypeNode (com.google.api.generator.engine.ast.TypeNode)58 Method (com.google.api.generator.gapic.model.Method)50 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)47 HashSet (java.util.HashSet)35 Descriptors (com.google.protobuf.Descriptors)30 List (java.util.List)29 Expr (com.google.api.generator.engine.ast.Expr)28 Service (com.google.api.generator.gapic.model.Service)28 HashMap (java.util.HashMap)28 ServiceDescriptor (com.google.protobuf.Descriptors.ServiceDescriptor)20 ArrayList (java.util.ArrayList)19 Preconditions (com.google.common.base.Preconditions)18 Path (java.nio.file.Path)18 Map (java.util.Map)18 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)17 Field (com.google.api.generator.gapic.model.Field)17 GapicClass (com.google.api.generator.gapic.model.GapicClass)17