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