public void testHandleServiceExceptionCauses() throws Exception {
// create a stack of three exceptions
IllegalArgumentException illegalArgument = new IllegalArgumentException("Illegal argument here");
IOException ioException = new IOException("I/O exception here");
ioException.initCause(illegalArgument);
ServiceException serviceException = new ServiceException("hello service exception");
serviceException.setCode("helloCode");
serviceException.setLocator("helloLocator");
serviceException.getExceptionText().add("helloText");
serviceException.initCause(ioException);
handler.handleServiceException(serviceException, requestInfo);
InputStream input = new ByteArrayInputStream(response.getOutputStreamContent().getBytes());
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);
Document doc = docBuilderFactory.newDocumentBuilder().parse(input);
Node exceptionText = XPathAPI.selectSingleNode(doc, "ows:ExceptionReport/ows:Exception/ows:ExceptionText/text()");
assertNotNull(exceptionText);
assertTrue(exceptionText.getNodeValue().indexOf(illegalArgument.getMessage()) != -1);
assertTrue(exceptionText.getNodeValue().indexOf(ioException.getMessage()) != -1);
assertTrue(exceptionText.getNodeValue().indexOf(serviceException.getMessage()) != -1);
}