use of org.restlet.ext.jackson.JacksonRepresentation in project OpenAM by OpenRock.
the class ResourceSetRegistrationExceptionFilterTest method shouldSet405ExceptionResponse.
@Test
@SuppressWarnings("unchecked")
public void shouldSet405ExceptionResponse() throws Exception {
//Given
Request request = mock(Request.class);
Response response = mock(Response.class);
Status status = new Status(405);
given(response.getStatus()).willReturn(status);
//When
exceptionFilter.afterHandle(request, response);
//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", "unsupported_method_type"));
}
use of org.restlet.ext.jackson.JacksonRepresentation in project OpenAM by OpenRock.
the class ResourceSetRegistrationExceptionFilterTest method shouldSetBadRequestExceptionResponse.
@Test
@SuppressWarnings("unchecked")
public void shouldSetBadRequestExceptionResponse() throws Exception {
//Given
Request request = mock(Request.class);
Response response = mock(Response.class);
Exception exception = new BadRequestException("MESSAGE");
Status status = new Status(444, exception);
given(response.getStatus()).willReturn(status);
//When
exceptionFilter.afterHandle(request, response);
//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", "bad_request"), entry("error_description", "MESSAGE"));
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(response).setStatus(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(400);
assertThat(statusCaptor.getValue().getThrowable()).isEqualTo(exception);
}
use of org.restlet.ext.jackson.JacksonRepresentation in project OpenAM by OpenRock.
the class UmaExceptionHandlerTest method shouldSetUmaExceptionResponse.
@Test
@SuppressWarnings("unchecked")
public void shouldSetUmaExceptionResponse() throws IOException {
//Given
Response response = mock(Response.class);
Throwable throwable = mock(Throwable.class);
Exception exception = new UmaException(444, "ERROR", "DESCRIPTION");
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"));
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(response).setStatus(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(444);
assertThat(statusCaptor.getValue().getThrowable()).isEqualTo(exception);
}
use of org.restlet.ext.jackson.JacksonRepresentation in project OpenAM by OpenRock.
the class ResourceSetRegistrationExceptionFilterTest method shouldSet412ExceptionResponse.
@Test
@SuppressWarnings("unchecked")
public void shouldSet412ExceptionResponse() throws Exception {
//Given
Request request = mock(Request.class);
Response response = mock(Response.class);
Status status = new Status(412);
given(response.getStatus()).willReturn(status);
//When
exceptionFilter.afterHandle(request, response);
//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", "precondition_failed"));
}
use of org.restlet.ext.jackson.JacksonRepresentation in project OpenAM by OpenRock.
the class ResourceSetRegistrationExceptionFilterTest method shouldSetAnyOtherExceptionResponse.
@Test
@SuppressWarnings("unchecked")
public void shouldSetAnyOtherExceptionResponse() throws Exception {
//Given
Request request = mock(Request.class);
Response response = mock(Response.class);
Exception exception = new Exception("MESSAGE");
Status status = new Status(444, exception);
given(response.getStatus()).willReturn(status);
//When
exceptionFilter.afterHandle(request, response);
//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", "server_error"), entry("error_description", "MESSAGE"));
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(response).setStatus(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(500);
assertThat(statusCaptor.getValue().getThrowable()).isEqualTo(exception);
}
Aggregations