use of org.restlet.Response in project OpenAM by OpenRock.
the class UmaExceptionHandlerTest method shouldSetUmaExceptionResponseWithDetail.
@Test
@SuppressWarnings("unchecked")
public void shouldSetUmaExceptionResponseWithDetail() throws IOException {
//Given
Response response = mock(Response.class);
Throwable throwable = mock(Throwable.class);
Exception exception = new UmaException(444, "ERROR", "DESCRIPTION").setDetail(json(object(field("DETAIL", "VALUE"))));
given(throwable.getCause()).willReturn(exception);
Status status = new Status(444, exception);
given(response.getStatus()).willReturn(status);
//When
exceptionFilter.handleException(response, throwable);
//Then
ArgumentCaptor<JacksonRepresentation> exceptionResponseCaptor = ArgumentCaptor.forClass(JacksonRepresentation.class);
verify(response).setEntity(exceptionResponseCaptor.capture());
Map<String, String> responseBody = (Map<String, String>) exceptionResponseCaptor.getValue().getObject();
assertThat(responseBody).containsOnly(entry("error", "ERROR"), entry("error_description", "DESCRIPTION"), entry("DETAIL", "VALUE"));
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(response).setStatus(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(444);
assertThat(statusCaptor.getValue().getThrowable()).isEqualTo(exception);
}
Aggregations