Search in sources :

Example 1 with JacksonRepresentation

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

Example 2 with JacksonRepresentation

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);
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Request(org.restlet.Request) BadRequestException(org.forgerock.oauth2.core.exceptions.BadRequestException) Map(java.util.Map) BadRequestException(org.forgerock.oauth2.core.exceptions.BadRequestException) Test(org.testng.annotations.Test)

Example 3 with JacksonRepresentation

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);
}
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 4 with JacksonRepresentation

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

Example 5 with JacksonRepresentation

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);
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Request(org.restlet.Request) Map(java.util.Map) BadRequestException(org.forgerock.oauth2.core.exceptions.BadRequestException) 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