Search in sources :

Example 6 with JacksonRepresentation

use of org.restlet.ext.jackson.JacksonRepresentation in project OpenAM by OpenRock.

the class UmaExceptionHandlerTest method shouldSet500ExceptionResponse.

@Test
@SuppressWarnings("unchecked")
public void shouldSet500ExceptionResponse() throws IOException {
    //Given
    Response response = mock(Response.class);
    Exception exception = new Exception("MESSAGE");
    Status status = new Status(444, exception);
    given(response.getStatus()).willReturn(status);
    //When
    exceptionFilter.handleException(response, exception);
    //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(444);
    assertThat(statusCaptor.getValue().getThrowable()).isEqualTo(exception);
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Map(java.util.Map) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 7 with JacksonRepresentation

use of org.restlet.ext.jackson.JacksonRepresentation 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);
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Map(java.util.Map) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Aggregations

Map (java.util.Map)7 Response (org.restlet.Response)7 Status (org.restlet.data.Status)7 JacksonRepresentation (org.restlet.ext.jackson.JacksonRepresentation)7 Test (org.testng.annotations.Test)7 Request (org.restlet.Request)4 IOException (java.io.IOException)3 BadRequestException (org.forgerock.oauth2.core.exceptions.BadRequestException)2