use of com.linkedin.restli.server.RoutingException in project rest.li by linkedin.
the class TestRestLiCallback method testOnErrorOtherExceptionNoFilters.
@SuppressWarnings("unchecked")
@Test(dataProvider = "provideExceptions")
public void testOnErrorOtherExceptionNoFilters(Exception ex) throws Exception {
ArgumentCaptor<RestLiServiceException> exCapture = ArgumentCaptor.forClass(RestLiServiceException.class);
RequestExecutionReport executionReport = new RequestExecutionReportBuilder().build();
RestLiResponseAttachments responseAttachments = new RestLiResponseAttachments.Builder().build();
PartialRestResponse partialResponse = new PartialRestResponse.Builder().build();
RestLiServiceException wrappedEx = new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, ex);
RestLiResponseDataImpl responseData = new RestLiResponseDataImpl(wrappedEx, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
responseData.setResponseEnvelope(new GetResponseEnvelope(new EmptyRecord(), responseData));
RestException restException = new RestException(new RestResponseBuilder().build());
Map<String, String> inputHeaders = Maps.newHashMap();
inputHeaders.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, "2.0.0");
// Set up.
when(_requestExecutionReportBuilder.build()).thenReturn(executionReport);
when(_restRequest.getHeaders()).thenReturn(inputHeaders);
when(_responseHandler.buildExceptionResponseData(eq(_restRequest), eq(_routingResult), exCapture.capture(), anyMap(), anyList())).thenReturn(responseData);
when(_responseHandler.buildPartialResponse(_routingResult, responseData)).thenReturn(partialResponse);
when(_responseHandler.buildRestException(wrappedEx, partialResponse)).thenReturn(restException);
// Invoke.
_noFilterRestLiCallback.onError(ex, executionReport, _requestAttachmentReader, responseAttachments);
// Verify.
verify(_responseHandler).buildExceptionResponseData(eq(_restRequest), eq(_routingResult), exCapture.capture(), anyMap(), anyList());
verify(_responseHandler).buildPartialResponse(_routingResult, responseData);
verify(_responseHandler).buildRestException(wrappedEx, partialResponse);
verify(_callback).onError(restException, executionReport, _requestAttachmentReader, responseAttachments);
verify(_restRequest, times(1)).getHeaders();
verifyZeroInteractions(_routingResult);
verifyNoMoreInteractions(_restRequest, _responseHandler, _callback);
RestLiServiceException restliEx = exCapture.getValue();
assertNotNull(restliEx);
if (ex instanceof RoutingException) {
assertEquals(HttpStatus.fromCode(((RoutingException) ex).getStatus()), restliEx.getStatus());
} else if (ex instanceof RestLiServiceException) {
assertEquals(((RestLiServiceException) ex).getStatus(), restliEx.getStatus());
} else {
assertEquals(HttpStatus.S_500_INTERNAL_SERVER_ERROR, restliEx.getStatus());
}
assertEquals(ex.getMessage(), restliEx.getMessage());
if (ex instanceof RestLiServiceException) {
assertEquals(ex, restliEx);
} else {
assertEquals(ex, restliEx.getCause());
}
}
Aggregations