Hello all!
First of all i gonna describe my situation and developer environment:
(i tried to follow the setup descriped at
http://www-128.ibm.com/developerworks/java/library/j-stc/ - but using the newest versions of the jars)
i'm using rational application developer v6 with built in
test environment (so local server is running) and want to use cactusstrutstestcase for testing some
struts actions..
so i have a relatively complex package structure called at.****.actions, at.****.struts etc
first of all i did a very simple test with servlets...so without strutstest.jar only using the needed cactus jars
i added them to /Web-inf/lib
created a test
servlet:
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
public class SampleServlet extends HttpServlet
{
public void saveToSession(HttpServletRequest request)
{
String testparam = request.getParameter("testparam");
request.getSession().setAttribute("testAttribute", testparam);
}
}
created the testcase:
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
public class TestSampleServlet extends ServletTestCase
{
public TestSampleServlet(String theName)
{
super(theName);
}
public static Test suite()
{
return new TestSuite(TestSampleServlet.class);
}
public void beginSaveToSessionOK(WebRequest webRequest)
{
webRequest.addParameter("testparam", "it works!");
}
public void testSaveToSessionOK()
{
SampleServlet servlet = new SampleServlet();
servlet.saveToSession(request);
assertEquals("it works!", session.getAttribute("testAttribute"));
}
}
i build and publish my web application...calling the ServletRedirector and all works fine...
now the extension...
i copied strutstest-2.1.3.jar to web-inf/lib
and wrote a new test for one of the struts actions deriving from Cactusstrutstestcase:
import javax.servlet.http.HttpSession;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.configuration.CompositeConfiguration;
import at.*****.masters.forms.struts.LoginForm;
import servletunit.struts.CactusStrutsTestCase;
/*
* Created on 07.08.2006 08:22:48
*
* TODO To change the template for this generated file go to
* Window - Preferences -
Java - Code Style - Code Templates
*
* $Date$ (UTC)
* $Author$
* $Revision$
*
*/
/**
* TODO write a documentation for file CactusTestLoginAction.java
*
*/
public class CactusTestLoginAction extends CactusStrutsTestCase {
// Constructor
public CactusTestLoginAction(String testName) {
super(testName);
}
// Set up Method
public void setUp() {
// call super
try{
super.setUp();
}
catch(Exception e){
e.printStackTrace();
}
setConfigFile("/WEB-INF/struts-config.xml");
}
// Tear down method
public void tearDown() {
try{
super.tearDown();
}
catch(Exception e){
e.printStackTrace();
}
}
public void testLoginActionFormError()throws Exception{
setRequestPathInfo("/login.do");
// Login Form parameters
this.addRequestParameter("login","test");
this.addRequestParameter("lang_id","de");
this.addRequestParameter("username","test");
this.addRequestParameter("password","test");
this.addRequestParameter("mand_id","auto");
// Get Configuration File from form
LoginForm test = (LoginForm)this.getActionForm();
CompositeConfiguration zwi=test.getConfig();
System.out.println("Test Read from Composite Configuration:"+zwi.getInt(("application.timeout")));
System.out.flush();
// Get Session
HttpSession test2=this.getSession();
String testi = (String)test2.getAttribute("testlang");
System.out.println("Lang ID from Session: "+testi);
System.out.flush();
//this.verifyNoActionErrors();
//this.verifyNoActionMessages();
assertEquals("en",testi);
}
public static Test suite()
{
return new TestSuite(CactusTestLoginAction.class);
}
}
executing this testcase gives me the following error stacktrace:
java.lang.NoClassDefFoundError: org/apache/cactus/ServletTestCase
at java.lang.ClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code))
at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code))
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java(Compiled Code))
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java(Compiled Code))
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java(Compiled Code))
at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code))
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java(Compiled Code))
at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code))
at com.ibm.ws.classloader.ReloadableClassLoader.loadClass(ReloadableClassLoader.java(Compiled Code))
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java(Compiled Code))
at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code))
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java(Compiled Code))
at org.apache.cactus.internal.util.ClassLoaderUtils.loadClassFromContextClassLoader_aroundBody2(ClassLoaderUtils.java:78)
at org.apache.cactus.internal.util.ClassLoaderUtils.loadClassFromContextClassLoader_aroundBody3$advice(ClassLoaderUtils.java:264)
at org.apache.cactus.internal.util.ClassLoaderUtils.loadClassFromContextClassLoader(ClassLoaderUtils.java)
at org.apache.cactus.internal.util.ClassLoaderUtils.loadClass_aroundBody0(ClassLoaderUtils.java:61)
at org.apache.cactus.internal.util.ClassLoaderUtils.loadClass_aroundBody1$advice(ClassLoaderUtils.java:264)
at org.apache.cactus.internal.util.ClassLoaderUtils.loadClass(ClassLoaderUtils.java)
at org.apache.cactus.internal.server.AbstractWebTestCaller.getTestClassClass(AbstractWebTestCaller.java:485)
at org.apache.cactus.internal.server.AbstractWebTestCaller.getTestClassInstance(AbstractWebTestCaller.java:384)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:109)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:61)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1010)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:592)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:204)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:125)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:286)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:615)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:912)
and i dont understand why that is happening...
i would be appreciated about any advice
regards,
daniel