@Test
public void uriWithException() throws Exception {
final ODataContext context = mockContext(ODataHttpMethod.GET);
final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, null);
ExpressionParserException exception = mock(ExpressionParserException.class);
when(exception.getMessageReference()).thenReturn(ExpressionParserException.COMMON_ERROR);
when(exception.getStackTrace()).thenReturn(new StackTraceElement[] {
new StackTraceElement("class", "method", "file", 42) });
CommonExpression filterTree = mock(CommonExpression.class);
when(filterTree.getUriLiteral()).thenReturn("wrong");
when(exception.getFilterTree()).thenReturn(filterTree);
ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), exception,
ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse();
String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(EXPECTED.replace("}}}", "}},\"server\":{"
+ "\"uri\":{\"error\":{\"expression\":\"wrong\"}},"
+ "\"stacktrace\":{\"exceptions\":[{\"class\":\"" + exception.getClass().getName() + "\","
+ "\"message\":\"Error while parsing a ODATA expression.\","
+ "\"invocation\":{\"class\":\"class\",\"method\":\"method\",\"line\":42}}],"
+ "\"stacktrace\":[{\"class\":\"class\",\"method\":\"method\",\"line\":42}]}}}"),
entity);
response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), exception,
ODataDebugResponseWrapper.ODATA_DEBUG_HTML).wrapResponse();
entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertTrue(entity.contains("wrong"));
assertTrue(entity.contains(exception.getClass().getName()));
assertTrue(entity.contains("42"));
}