File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes An uncaught exception was thrown during actionExecute() -JUNIT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "An uncaught exception was thrown during actionExecute() -JUNIT" Watch "An uncaught exception was thrown during actionExecute() -JUNIT" New topic
Author

An uncaught exception was thrown during actionExecute() -JUNIT

thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
I am getting an error while testing Action Class using JUNIT(WSAD 5.1.2)
Details of error are as given below :

servletunit.struts.ExceptionDuringTestError: An uncaught exception was thrown during actionExecute()
at servletunit.struts.CactusStrutsTestCase.actionPerform(CactusStrutsTestCase.java:546)




JUNIT TEST CLASS cose is as given below :

public class PAActionTest extends CactusStrutsTestCase
{

public PAActionTest(String name)
{
super(name);
}

public void setUp() throws Exception
{
super.setUp();
setConfigFile("/WEB-INF/struts-config-pricing.xml");
UserProfile up=new UserProfile();
up.setUserId(1);
up.setUserName("ngd_user");
up.setOrgId(35);
up.setOrgName("TEST BORG Performance");
UserContainer userContainer=new UserContainer();
userContainer.setUserProfile(up);
session.setAttribute(UserContainer.USER_CONTAINER_KEY, userContainer);
}

public void tearDown() throws Exception
{
super.tearDown();
}



public void testSession()
{

UserProfile profile=SessionDAOFactory.getUserProfile(request);
setRequestPathInfo("/pricingMain");
actionPerform();
/verifyNoActionErrors();
verifyNoActionMessages();
verifyForward("success");


}

public static void main(String[] args)
{
junit.swingui.TestRunner.run(PAActionTest.class);
}

}


Code snippets from STRUTS CONFIG FILE(struts-config-pricing.xml):


<action
path="/pricingMain"
name="pAActionForm"
type="com.sbc.dcomm.ui.cart.pa.actions.PAAction"
parameter="method">
<forward name="success" path="/cart/pa/paMain.jsp"/>
</action>


Could you please look into this and explain to me the solution ?
Fletcher Estes
Ranch Hand

Joined: Jul 01, 2004
Posts: 108
First things first: run your server in debug mode, and place a breakpoint at the start of your test case. Step through/into the code until you find the exact line that is throwing an exception. Then we'll talk
thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
It's throwing an error at the line where actionPerform() is executed.

A few lines of stack trace from application console are as given below :

[12/20/04 20:10:00:719 IST] cab426 WebGroup I SRVE0180I: [dcomm-ui] [/dcomm-ui] [Servlet.LOG]: ServletRedirector: init
[12/20/04 20:10:00:719 IST] cab426 PropertyMessa I org.apache.struts.util.PropertyMessageResources Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
[12/20/04 20:10:00:766 IST] cab426 RequestProces W org.apache.struts.action.RequestProcessor Unhandled Exception thrown: class javax.servlet.ServletException

JUNIT ERROR STACK TRACE :

servletunit.struts.ExceptionDuringTestError: An uncaught exception was thrown during actionExecute()
at servletunit.struts.CactusStrutsTestCase.actionPerform(CactusStrutsTestCase.java:546)
at com.sbc.dcomm.ui.cart.pa.actions.PAActionTest.testSession(PAActionTest.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:41)
at java.lang.reflect.Method.invoke(Method.java:386)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)

If you need any more info ,please feel to write ...
Fletcher Estes
Ranch Hand

Joined: Jul 01, 2004
Posts: 108
It says the exception was thrown during actionExecute() - but it is possible to step into this method to see exactly what line of code caused the exception. If you don't want to step into all these methods, put a breakpoint at the start of your PAAction (I presume this is the action being called by your test case).

If you get to that breakpoint, then you'll be able to step through to the underlying problem. If you never get to that breakpoint, then you know you have a configuration issue with StrutsTestCase.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: An uncaught exception was thrown during actionExecute() -JUNIT