use of org.apache.calcite.avatica.remote.Handler.HandlerResponse in project calcite-avatica by apache.
the class AbstractHandlerTest method testFailedResponseSerialization.
@Test
public void testFailedResponseSerialization() throws IOException {
@SuppressWarnings("unchecked") final AbstractHandler<String> handler = Mockito.mock(AbstractHandler.class);
final Request request = Mockito.mock(Request.class);
final Response response = Mockito.mock(Response.class);
final IOException exception = new IOException();
final ErrorResponse errorResponse = Mockito.mock(ErrorResponse.class);
final String serializedErrorResponse = "An ErrorResponse";
// Accept a serialized request
Mockito.when(handler.apply(Mockito.anyString())).thenCallRealMethod();
// Deserialize it back into a POJO
Mockito.when(handler.decode(Mockito.anyString())).thenReturn(request);
// Construct the Response for that Request
Mockito.when(request.accept(Mockito.nullable(Service.class))).thenReturn(response);
// Throw an IOException when serializing the Response.
Mockito.when(handler.encode(response)).thenThrow(exception);
Mockito.when(handler.convertToErrorResponse(exception)).thenCallRealMethod();
// Convert the IOException into an ErrorResponse
Mockito.when(handler.unwrapException(exception)).thenReturn(errorResponse);
Mockito.when(handler.encode(errorResponse)).thenReturn(serializedErrorResponse);
HandlerResponse<String> handlerResp = handler.apply("this is mocked out");
assertEquals(500, handlerResp.getStatusCode());
assertEquals(serializedErrorResponse, handlerResp.getResponse());
}
Aggregations