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