Search in sources :

Example 61 with Response

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);
}
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

Response (org.restlet.Response)61 Request (org.restlet.Request)43 Test (org.testng.annotations.Test)26 Status (org.restlet.data.Status)17 ChallengeResponse (org.restlet.data.ChallengeResponse)14 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)12 ResponseHandler (org.qi4j.library.rest.client.spi.ResponseHandler)12 Map (java.util.Map)10 Test (org.junit.Test)10 Client (org.restlet.Client)9 Representation (org.restlet.representation.Representation)9 Reference (org.restlet.data.Reference)8 ContextResourceClient (org.qi4j.library.rest.client.api.ContextResourceClient)7 HandlerCommand (org.qi4j.library.rest.client.api.HandlerCommand)7 JacksonRepresentation (org.restlet.ext.jackson.JacksonRepresentation)7 AccessToken (org.forgerock.oauth2.core.AccessToken)6 ResourceException (org.restlet.resource.ResourceException)6 Resource (org.qi4j.library.rest.common.Resource)5 Link (org.qi4j.library.rest.common.link.Link)5 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)5