use of com.google.api.generator.gapic.model.Method in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method invalid_composeStreamCallableMethod_bidiStreamNotExistRequest.
@Test
public void invalid_composeStreamCallableMethod_bidiStreamNotExistRequest() {
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("NotExistRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("EchoResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
Method method = Method.builder().setName("chat").setInputType(inputType).setOutputType(outputType).setStream(Method.Stream.BIDI).build();
Assert.assertThrows(NullPointerException.class, () -> ServiceClientCallableMethodSampleComposer.composeStreamCallableMethod(method, clientType, resourceNames, messageTypes));
}
use of com.google.api.generator.gapic.model.Method in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method invalid_composeRegularCallableMethod_noExistMethodResponsePagedRpc.
@Test
public void invalid_composeRegularCallableMethod_noExistMethodResponsePagedRpc() {
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.composeRegularCallableMethod(method, clientType, resourceNames, messageTypes));
}
use of com.google.api.generator.gapic.model.Method in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method invalid_composeRegularCallableMethod_noRepeatedResponsePagedRpc.
@Test
public void invalid_composeRegularCallableMethod_noRepeatedResponsePagedRpc() {
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.composeRegularCallableMethod(method, clientType, resourceNames, messageTypes));
}
use of com.google.api.generator.gapic.model.Method in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method valid_composeLroCallableMethod_withReturnResponse.
/*Testing composeLroCallableMethod*/
@Test
public void valid_composeLroCallableMethod_withReturnResponse() {
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("WaitResponse").setPakkage(SHOWCASE_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<WaitResponse, WaitMetadata> future =\n", " echoClient.waitOperationCallable().futureCall(request);\n", " // Do something.\n", " WaitResponse response = future.get();\n", "}");
Assert.assertEquals(results, expected);
}
use of com.google.api.generator.gapic.model.Method in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method valid_composeStreamCallableMethod_serverStream.
/*Testing composeStreamCallableMethod*/
@Test
public void valid_composeStreamCallableMethod_serverStream() {
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("ExpandRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("EchoResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
Method method = Method.builder().setName("Expand").setInputType(inputType).setOutputType(outputType).setStream(Method.Stream.SERVER).build();
String results = writeStatements(ServiceClientCallableMethodSampleComposer.composeStreamCallableMethod(method, clientType, resourceNames, messageTypes));
String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", " ExpandRequest request =\n", " ExpandRequest.newBuilder().setContent(\"content951530617\").setInfo(\"info3237038\").build();\n", " ServerStream<EchoResponse> stream = echoClient.expandCallable().call(request);\n", " for (EchoResponse response : stream) {\n", " // Do something when a response is received.\n", " }\n", "}");
Assert.assertEquals(results, expected);
}
Aggregations