I think the documentation should highlight
"For MockStrutsTest to work at runtime it should be able to find the applications struts-config.xml which is in the WEB-INF folder.
So the folder containing the WEB-INF/ folder should be in the classpath."
I discovered this by adding the source code of MockStrutsCase to my project and going thru line by line.
g1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2004-07-23
Hi there
You can also specify the location of the struts-config.xml file using:
setConfigFile("enter the path/file name here");
You can call that method inside your setUp method:
public void setup()
{
super.setUp();
setConfigFile("c:/myapp/WEB-INF/struts-config.xml")
}
Hope it helps,
Leo.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am using MockStrutsTest (of StrutsTest2.0.jar).
My test class works perfect when executed thru a ANT script : <junittask task/target
But the same class in eclipse gives a NullPointerException in MockStrutsTestCase.getActionServlet()
I know I am missing something in my configuartion but what. The stack trace is:
INFO com.fiserv.cm.common.CodeGroup - loadCodeGroupCache called
WARN com.fiserv.cm.dao.DAOFactory - DAOs should be located using an interface class instead of a VO class
DEBUG servletunit.struts.MockStrutsTestCase - Entering setUp()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting setUp()
DEBUG servletunit.struts.MockStrutsTestCase - Entering getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Entering getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Entering getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Entering getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Entering getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Entering getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Entering getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Entering getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting getSession()
g1 - THE START
INFO com.fiserv.cm.dao.LookupCache - cacheAlertTypes called
INFO com.fiserv.cm.dao.LookupCache - cacheAlertSeverities called
INFO com.fiserv.cm.dao.LookupCache - buildAlertTypeXML called
INFO com.fiserv.cm.dao.LookupCache - cacheInstitutionCodes called
INFO com.fiserv.cm.dao.LookupCache - cacheApplicationCodes called
INFO com.fiserv.cm.dao.LookupCache - cacheProductCodes called
INFO com.fiserv.cm.dao.LookupCache - cacheReasonCodes called
INFO com.fiserv.cm.dao.LookupCache - cacheWorkgroups called
g1 - product.getProducts().size() =55
DEBUG servletunit.struts.MockStrutsTestCase - Entering getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Entering getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting getSession()
DEBUG servletunit.struts.MockStrutsTestCase - Entering setRequestPathInfo() : pathInfo = /deleteProductsAction
DEBUG servletunit.struts.MockStrutsTestCase - Entering setRequestPathInfo() : moduleName = , pathInfo = /deleteProductsAction
DEBUG servletunit.struts.Common - Entering stripActionPath() : path = /deleteProductsAction
DEBUG servletunit.struts.Common - Exiting stripActionPath() - returning path = /deleteProductsAction
DEBUG servletunit.struts.MockStrutsTestCase - setRequestPathInfo() : setting request attribute - name = javax.servlet.include.servlet_path, value =
DEBUG servletunit.struts.MockStrutsTestCase - Exiting setRequestPathInfo()
DEBUG servletunit.struts.MockStrutsTestCase - Exiting setRequestPathInfo()
DEBUG servletunit.struts.MockStrutsTestCase - Entering actionPerform()
DEBUG servletunit.struts.MockStrutsTestCase - Entering getActionServlet()
DEBUG servletunit.struts.MockStrutsTestCase - getActionServlet() : intializing actionServlet
INFO org.apache.struts.util.PropertyMessageResources - Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
INFO org.apache.struts.util.PropertyMessageResources - Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
DEBUG servletunit.struts.MockStrutsTestCase - Error in getActionServlet()
java.lang.NullPointerException
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:524)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.apache.commons.digester.Digester.parse(Digester.java:1299)
at org.apache.struts.action.ActionServlet.initServlet(ActionServlet.java:1433)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:466)
at javax.servlet.GenericServlet.init(GenericServlet.java:256)
at servletunit.struts.MockStrutsTestCase.getActionServlet(MockStrutsTestCase.java:179)
at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:228)
at com.fiserv.cm.presentation.action.DeleteProductsAction$Tester.testDeleteProductsAction(DeleteProductsAction.java:174)
at java.lang.reflect.Method.invoke(Native Method)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Problem SOLVED.
I think the documentation should highlight
"For MockStrutsTest to work at runtime it should be able to find the applications struts-config.xml which is in the WEB-INF folder.
So the folder containing the WEB-INF/ folder should be in the classpath."
I discovered this by adding the source code of MockStrutsCase to my project and going thru line by line.
g1
Hi there
You can also specify the location of the struts-config.xml file using:
setConfigFile("enter the path/file name here");
You can call that method inside your setUp method:
public void setup()
{
super.setUp();
setConfigFile("c:/myapp/WEB-INF/struts-config.xml")
}
Hope it helps,
Leo.