use of com.google.cloud.functions.HttpResponse in project spring-cloud-function by spring-cloud.
the class FunctionInvokerHttpTests method testHttpFunction.
private <I, O> void testHttpFunction(Class<?> configurationClass, I input, O expectedOutput) throws Exception {
try (FunctionInvoker handler = new FunctionInvoker(configurationClass)) {
HttpRequest request = Mockito.mock(HttpRequest.class);
if (input != null) {
when(request.getReader()).thenReturn(new BufferedReader(new StringReader(gson.toJson(input))));
}
HttpResponse response = Mockito.mock(HttpResponse.class);
StringWriter writer = new StringWriter();
BufferedWriter bufferedWriter = new BufferedWriter(writer);
when(response.getWriter()).thenReturn(bufferedWriter);
handler.service(request, response);
// Closing the writer is done by the Framework/caller.
bufferedWriter.close();
if (expectedOutput != null) {
assertThat(writer.toString()).isEqualTo(gson.toJson(expectedOutput));
}
}
}
Aggregations