I was writing a cactus unit test to test the methods on a stateless
session bean. Everything was deployed on Jboss version 4.0.2. In a
test case where I would like to test an application exception
condition, the test code was not able to catch the application
exception, but jboss would throw an org.jboss.util.NestedError where
the nested error was my application exception.
The code looks like this:
public class MySessionBean implements javax.ejb.SessionBean {
... all the ejb lifecycle methods...
public void foo() throws MyException {
throw new MyException();
}
}
in the cactus test class:
public class MyCactusTest extends org.apache.cactus.ServletTestCase {
... all the methods required by cactus, e.g. constructor, setUp(),
tearDown()...
public void testFoo() {
try {
mySessionBean.foo();
fail("MyException should be thrown.");
} catch (MyException e) {
//ok
return;
}
}
}
when I ran the test, it would fail with output like:
2005-06-29 17:39:28,745 ERROR [org.jboss.ejb.plugins.LogInterceptor]
Unexpected Error in method: public abstract void MySession.foo()
throws MyException
org.jboss.util.NestedError: Unexpected Throwable; - nested throwable:
MyException: //error message and a stack trace
How can I catch MyException in the cactus test? I assume the same
behavior will happen in the web tier, ie. if I have code in the web
tier calling MySession ejb, the code won't be able to catch
application exception. Why is my application exception wrapped inside
a org.jboss.util.NestedError?
I want to be able to catch the application exception. |