Hi Greg / all,

I've gone back to Greg's example and I'm getting the stack trace below.
From what I've read, it is because I'll need to define an object factory
for my test to run. My application is using a combination of Struts 2 and Spring 2. I've created a struts-test.xml that bypasses some of the interceptors I want to skip for my action test. In my tests, I'm creating my own mock DAOs, mock Services and then manually assigning them to my action. When I run it, it fails.

I noticed in Greg's blog, he set a "struts.objectFactory" and mapped it to guice. (Which is something I don't know too much about.)

Possible related article: http://www.nabble.com/Struts2-%2B-Spring2-ERROR---HELP!!!!-td17041898.html



Questions:

1.  Does anyone have an example of how I would proceed to fix my problem?

1.1 I'm not sure if I am supposed to map the object factory to a specific type of factory. Spring, struts, or just mock it up? What is this object factory used for? Keep in mind that I am manually assigning services to my action and mock daos to my service.
http://struts.apache.org/2.1.6/struts2-core/apidocs/com/opensymphony/xwork2/ObjectFactory.html

2.  How do people normally configure a struts.xml for testing?





struts-test.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
   "http://struts.apache.org/dtds/struts-2.0.dtd";>
<struts>
   <!--constant name="blah.module" value="test.mymodule" /-->
   <package name="configmanager" namespace="/configManager">
<!--Result Types -->
       <result-types>
           <result-type name="JSONResult"
               class="a.b.c.web.configmanager.results.GenericJSONResult" />
       </result-types>
<!--Setting Actions -->
       <action name="settingAction_getSettings" method="getSettings"
           class="a.b.c.web.configmanager.action.SettingAction">
           <result name="SUCCESS" type="JSONResult" />
       </action>
   </package>
</struts>



com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.ObjectFactory). at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:144) at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMethods(ContainerImpl.java:113) at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:90) at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:86) at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:71) at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:69) at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
   at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76) at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116) at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:483) at com.opensymphony.xwork2.inject.ContainerImpl$6.call(ContainerImpl.java:523) at com.opensymphony.xwork2.inject.ContainerImpl$6.call(ContainerImpl.java:522) at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574) at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:521) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:188) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
   at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
at com.caris.sfe.web.configmanager.action.BaseStrutsTestCase.setUp(BaseStrutsTestCase.java:185)
   at junit.framework.TestCase.runBare(TestCase.java:132)
   at junit.framework.TestResult$1.protect(TestResult.java:110)
   at junit.framework.TestResult.runProtected(TestResult.java:128)
   at junit.framework.TestResult.run(TestResult.java:113)
   at junit.framework.TestCase.run(TestCase.java:124)
   at junit.framework.TestSuite.runTest(TestSuite.java:232)
   at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.ObjectFactory). at com.opensymphony.xwork2.inject.ContainerImpl.createParameterInjector(ContainerImpl.java:235) at com.opensymphony.xwork2.inject.ContainerImpl.getParametersInjectors(ContainerImpl.java:225) at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.<init>(ContainerImpl.java:287) at com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:117) at com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:115) at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:141)
   ... 34 more





Greg Lindholm wrote:
You can take a look at this:

http://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/

I've used it to unit test actions all the way through interceptors,
validation, actions, and results including freemarker result types.


Timothy Astle wrote:
I had tried using proxy.execute(), which will use Struts. Maybe that's where I'm a bit lost. I don't implement execute() because of my CRUD approach.

Can someone point me to some appropriate struts 2 junit tests so I can figure this out?



Reply via email to