Search in sources :

Example 1 with MessageContext

use of org.forgerock.caf.authentication.api.MessageContext in project OpenAM by OpenRock.

the class XMLResourceExceptionHandlerTest method testWrite.

@Test
public void testWrite() throws Exception {
    //given
    MessageContext context = mock(MessageContext.class);
    AuditTrail mockAudit = mock(AuditTrail.class);
    Response response = new Response();
    doReturn(mockAudit).when(context).getAuditTrail();
    doReturn(response).when(context).getResponse();
    String message = "I don't know where it is";
    ResourceException ex = new NotFoundException(message);
    AuthenticationException ex2 = new AuthenticationException(ex);
    //when
    handler.write(context, ex2);
    //then
    assertThat(response.getStatus()).isEqualTo(Status.NOT_FOUND);
    String text = response.getEntity().getString();
    assertThat(text).contains("<message>" + message + "</message>");
    assertThat(text).contains("<code>404</code>");
}
Also used : Response(org.forgerock.http.protocol.Response) AuthenticationException(org.forgerock.caf.authentication.api.AuthenticationException) NotFoundException(org.forgerock.json.resource.NotFoundException) ResourceException(org.forgerock.json.resource.ResourceException) MessageContext(org.forgerock.caf.authentication.api.MessageContext) AuditTrail(org.forgerock.caf.authentication.framework.AuditTrail) Test(org.testng.annotations.Test)

Aggregations

AuthenticationException (org.forgerock.caf.authentication.api.AuthenticationException)1 MessageContext (org.forgerock.caf.authentication.api.MessageContext)1 AuditTrail (org.forgerock.caf.authentication.framework.AuditTrail)1 Response (org.forgerock.http.protocol.Response)1 NotFoundException (org.forgerock.json.resource.NotFoundException)1 ResourceException (org.forgerock.json.resource.ResourceException)1 Test (org.testng.annotations.Test)1