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);
}
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());
}
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();
}
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());
}
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());
}
Aggregations