Short story, use StrutsSpringTestCase (from the junit plugin) instead
of the StrutsTestCase.

Long story - your unit tests aren't running inside of the web-app
context. The web.xml listener configuration instantiates the
applicationContext and puts it in the application scope where other
spring components know where to find it. Since a unit test runs in the
unit test context, it's not going to find the application context
where it expects to. The StrutsSpringTestCase adds some extra
bootstrap plumbing to make it work.

-Wes

On Fri, Apr 30, 2010 at 6:07 AM, rameshbabu
<rameshbab...@interlaceindia.com> wrote:
>
> Hi,
>
> I am getting error when i am running my junit test case for struts2 action
> class. Here is the code.
>
>
> ------------------------------------------------------------------------------------------------------------
> public class RoleMasterNewActionTest extends StrutsTestCase {
>
>        public void setUp() throws Exception {
>        super.setUp();
>        ObjectFactory.setObjectFactory( new ObjectFactory() );
>
> }
>        public void testDoSomeThing()throws Exception {
>
>
>                RoleMasterNewAction action = new RoleMasterNewAction();
>                assertTrue(action.doSomeThing());
>
>
>        }
>
> }
>
> ------------------------------------------------------------------------------------------------------------------------
>
> I am getting error at testDoSomeThing(). the error is
>
>
> ------------------------------------------------------------------------------------------------------------------
> 2010-04-30 15:07:12,263 INFO
> [com.opensymphony.xwork2.config.providers.XmlConfigurationProvider] -
> Parsing configuration file [struts-default.xml]
> 2010-04-30 15:07:12,325 INFO
> [com.opensymphony.xwork2.config.providers.XmlConfigurationProvider] -
> Parsing configuration file [struts-plugin.xml]
> 2010-04-30 15:07:12,388 INFO
> [com.opensymphony.xwork2.config.providers.XmlConfigurationProvider] -
> Parsing configuration file [struts.xml]
> 2010-04-30 15:07:12,388 WARN [org.apache.struts2.config.Settings] -
> Settings: Could not parse struts.locale setting, substituting default VM
> locale
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.comm.resources.comman-Lookup
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.comm.resources.comman-label
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.comm.resources.comman-headings
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.comm.resources.comman-messages
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.comm.resources.comman-setup
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.comm.resources.common-errors
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.admin.resources.admin-label
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.admin.resources.admin-lookup
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.admin.resources.admin-headings
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.admin.resources.admin-jndinames
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.birthCertificate.resources.birth-jndinames
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.birthCertificate.resources.birth-labels
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.birthCertificate.resources.birth-headings
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.admin.resources.admin-alert
> 2010-04-30 15:07:12,388 INFO
> [org.apache.struts2.config.BeanSelectionProvider] - Loading global messages
> from ipl.comm.resources.form
> 2010-04-30 15:07:12,419 INFO
> [org.apache.struts2.spring.StrutsSpringObjectFactory] - Initializing
> Struts-Spring integration...
> 2010-04-30 15:07:12,419 FATAL
> [org.apache.struts2.spring.StrutsSpringObjectFactory] - ********** FATAL
> ERROR STARTING UP STRUTS-SPRING INTEGRATION **********
> Looks like the Spring listener was not configured for your web app!
> Nothing will work until WebApplicationContextUtils returns a valid
> ApplicationContext.
> You might need to add the following to web.xml:
>    <listener>
>
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
>    </listener>
>
> ----------------------------------------------------------------------------------------------------------
>
> but already i have the listener configuration in my web.xml.
>
> Thanks in advance..
> --
> View this message in context: 
> http://old.nabble.com/Error-in-running-juit-test-case-for-struts2-action-class-tp28410616p28410616.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to