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