/*
* $Id: ExceptionHelperTestCase.java 19556 2010-09-10 13:51:02Z aperepel $
* --------------------------------------------------------------------------------------
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
*
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.test.config;
import org.mule.api.DefaultMuleException;
import org.mule.config.ExceptionHelper;
import org.mule.config.i18n.MessageFactory;
import org.mule.tck.AbstractMuleTestCase;
import java.util.List;
import java.util.Map;
public class ExceptionHelperTestCase extends AbstractMuleTestCase
{
public void testNestedExceptionRetreval() throws Exception
{
Exception testException = getException();
Throwable t = ExceptionHelper.getRootException(testException);
assertNotNull(t);
assertEquals("blah", t.getMessage());
assertNull(t.getCause());
t = ExceptionHelper.getRootMuleException(testException);
assertNotNull(t);
assertEquals("bar", t.getMessage());
assertNotNull(t.getCause());
List<?> l = ExceptionHelper.getExceptionsAsList(testException);
assertEquals(3, l.size());
Map<?, ?> info = ExceptionHelper.getExceptionInfo(testException);
assertNotNull(info);
assertEquals(1, info.size());
assertNotNull(info.get("JavaDoc"));
}
public void testSummarizeWithDepthBeyondStackTraceLength()
{
Exception exception = getException();
int numberOfStackFrames = exception.getStackTrace().length;
int depth = numberOfStackFrames + 1;
Throwable summary = ExceptionHelper.summarise(exception, depth);
assertNotNull(summary);
}
private Exception getException()
{
return new DefaultMuleException(MessageFactory.createStaticMessage("foo"), new DefaultMuleException(
MessageFactory.createStaticMessage("bar"), new Exception("blah")));
}
}