use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method valid_composeLroCallableMethod_withReturnVoid.
@Test
public void valid_composeLroCallableMethod_withReturnVoid() {
Descriptors.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("WaitRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("Operation").setPakkage(LRO_PACKAGE_NAME).build());
TypeNode responseType = TypeNode.withReference(VaporReference.builder().setName("Empty").setPakkage(PROTO_PACKAGE_NAME).build());
TypeNode metadataType = TypeNode.withReference(VaporReference.builder().setName("WaitMetadata").setPakkage(SHOWCASE_PACKAGE_NAME).build());
LongrunningOperation lro = LongrunningOperation.builder().setResponseType(responseType).setMetadataType(metadataType).build();
Method method = Method.builder().setName("Wait").setInputType(inputType).setOutputType(outputType).setLro(lro).build();
String results = writeStatements(ServiceClientCallableMethodSampleComposer.composeLroCallableMethod(method, clientType, resourceNames, messageTypes));
String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", " WaitRequest request = WaitRequest.newBuilder().build();\n", " OperationFuture<Empty, WaitMetadata> future =\n", " echoClient.waitOperationCallable().futureCall(request);\n", " // Do something.\n", " future.get();\n", "}");
Assert.assertEquals(results, expected);
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method invalid_composePagedCallableMethod_noExistMethodResponse.
@Test
public void invalid_composePagedCallableMethod_noExistMethodResponse() {
Descriptors.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("NoExistResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
Method method = Method.builder().setName("PagedExpand").setInputType(inputType).setOutputType(outputType).setPageSizeFieldName(PAGINATED_FIELD_NAME).build();
Assert.assertThrows(NullPointerException.class, () -> ServiceClientCallableMethodSampleComposer.composePagedCallableMethod(method, clientType, resourceNames, messageTypes));
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method valid_composeStreamCallableMethod_clientStream.
@Test
public void valid_composeStreamCallableMethod_clientStream() {
Descriptors.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("Collect").setInputType(inputType).setOutputType(outputType).setStream(Method.Stream.CLIENT).build();
String results = writeStatements(ServiceClientCallableMethodSampleComposer.composeStreamCallableMethod(method, clientType, resourceNames, messageTypes));
String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", " ApiStreamObserver<EchoRequest> responseObserver =\n", " new ApiStreamObserver<EchoRequest>() {\n", " {@literal @}Override\n", " public void onNext(EchoResponse response) {\n", " // Do something when a response is received.\n", " }\n", "\n", " {@literal @}Override\n", " public void onError(Throwable t) {\n", " // Add error-handling\n", " }\n", "\n", " {@literal @}Override\n", " public void onCompleted() {\n", " // Do something when complete.\n", " }\n", " };\n", " ApiStreamObserver<EchoRequest> requestObserver =\n", " echoClient.collect().clientStreamingCall(responseObserver);\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", " requestObserver.onNext(request);\n", "}");
Assert.assertEquals(results, expected);
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method valid_composeRegularCallableMethod_lroRpcWithReturnVoid.
@Test
public void valid_composeRegularCallableMethod_lroRpcWithReturnVoid() {
Descriptors.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("WaitRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("Operation").setPakkage(LRO_PACKAGE_NAME).build());
TypeNode responseType = TypeNode.withReference(VaporReference.builder().setName("Empty").setPakkage(PROTO_PACKAGE_NAME).build());
TypeNode metadataType = TypeNode.withReference(VaporReference.builder().setName("WaitMetadata").setPakkage(SHOWCASE_PACKAGE_NAME).build());
LongrunningOperation lro = LongrunningOperation.builder().setResponseType(responseType).setMetadataType(metadataType).build();
Method method = Method.builder().setName("Wait").setInputType(inputType).setOutputType(outputType).setLro(lro).build();
String results = writeStatements(ServiceClientCallableMethodSampleComposer.composeRegularCallableMethod(method, clientType, resourceNames, messageTypes));
String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", " WaitRequest request = WaitRequest.newBuilder().build();\n", " ApiFuture<Operation> future = echoClient.waitCallable().futureCall(request);\n", " // Do something.\n", " future.get();\n", "}");
Assert.assertEquals(results, expected);
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method invalid_composePagedCallableMethod_noRepeatedResponse.
@Test
public void invalid_composePagedCallableMethod_noRepeatedResponse() {
Descriptors.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("NoRepeatedResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
Method method = Method.builder().setName("PagedExpand").setInputType(inputType).setOutputType(outputType).setPageSizeFieldName(PAGINATED_FIELD_NAME).build();
Field responseField = Field.builder().setName("response").setType(TypeNode.STRING).build();
Message noRepeatedResponseMessage = Message.builder().setName("NoRepeatedResponse").setFullProtoName("google.showcase.v1beta1.NoRepeatedResponse").setType(TypeNode.withReference(VaporReference.builder().setName("NoRepeatedResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build())).setFields(Arrays.asList(responseField)).build();
messageTypes.put("NoRepeatedResponse", noRepeatedResponseMessage);
Assert.assertThrows(NullPointerException.class, () -> ServiceClientCallableMethodSampleComposer.composePagedCallableMethod(method, clientType, resourceNames, messageTypes));
}
Aggregations