Problem in wiring in Sturts test case?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Santosh_Shetkar
Posted On:   Tuesday, January 6, 2009 07:04 AM

I have one applcation which uses Spring,Struts ,Tiles. Now I want to write junit test cases to test struts action class. I have created BaseMockStrutsTestCase class which extends MockStrutsTestCase. /* * Created on Jan 2, 2009 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package com.americanexpress.merchsub.submitter.action; import java.io.File; import javax.servlet.ServletContext; import org.springframework.mock.web.MockServletContext; import org.springframework.web.context.support.XmlWebApplicationContext;    More>>

I have one applcation which uses Spring,Struts ,Tiles.
Now I want to write junit test cases to test struts action class.


I have created BaseMockStrutsTestCase class which extends MockStrutsTestCase.


/*
* Created on Jan 2, 2009
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/


package com.americanexpress.merchsub.submitter.action;


import java.io.File;


import javax.servlet.ServletContext;


import org.springframework.mock.web.MockServletContext;

import org.springframework.web.context.support.XmlWebApplicationContext;

import org.springframework.web.struts.ContextLoaderPlugIn;

import servletunit.struts.MockStrutsTestCase;


/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/

public class BaseMockStrutsTestCase extends MockStrutsTestCase {


private ServletContext servletContext = null;


protected void setUp() throws Exception {
super.setUp();

//String path[] = {"submissions-application.xml"};
//XmlWebApplicationContext ctx = new XmlWebApplicationContext();
//ctx.setConfigLocations(path);
//ctx.setServletContext(new MockServletContext(""));
//ctx.refresh();

// initialize some struts test case stuff
setContextDirectory(new File("WebContent/"));
setServletConfigFile("/WEB-INF/web.xml");
this.setConfigFile(this.getSession().getServletContext().getRealPath("/WEB-INF/struts-config.xml"));

}


/**
* Call this at the end of your testCase.setUp()
*/
public void finalizeSetUp() {

// this starts the StrutsTestCase action servlet

this.servletContext = getActionServlet().getServletContext();
}


/**
* Call this after calling finalizeSetUp(). You can use this to get your action
* class bean from spring if you want to override some of the spring injected properties
* before invoking actionPerform().
*
* @param beanId
* @return
*/

public Object getSpringBean(String beanId) {

XmlWebApplicationContext applicationContext = (XmlWebApplicationContext) this.servletContext.getAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX);

return applicationContext.getBean(beanId);

}


protected void tearDown() throws Exception {

super.tearDown();

}

}


and Actual test class is


/*
* Created on Dec 24, 2008
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/

package com.americanexpress.merchsub.submitter.action;


/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/

public class TestWelcomeAction extends BaseMockStrutsTestCase {



protected void setUp() throws Exception {

//call parent setUp
super.setUp();

}

public void testSuccessfulLogin()
{

setRequestPathInfo("/authreg/welcome.do");

actionPerform();

verifyForward("success");

verifyNoActionErrors();


}

protected void tearDown() throws Exception {

super.tearDown();

}




}




When I try to run this junit through WASAD getting following cosole log

log4j:WARN No appenders could be found for logger (servletunit.struts.MockStrutsTestCase).

log4j:WARN Please initialize the log4j system properly.
ContextLoaderPlugIn for Struts
ActionServlet 'ActionServlet, module '': initialization started

Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-xml/submissions-actions.xml]
Bean factory for application context
[WebApplicationContext for namespace 'ActionServlet-servlet']:
org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [viewSubmSearchSubmitterResult,welcome,AuditTrail,viewSubmSearchSubmitterCriteria,updateSubmNewProfile,submProfile,updateSubmQueryProfile,updateSubmSaveNewProfile,updateSubmManageFileLayout,updateSubmManageFileAddenda,updateSubmManageCurrency,updateSubmReleaseProfile,viewSubmQueryProfile,viewSubmComments,viewSubmSaveComments,updateSubmDeleteProfile,viewSubmAuditTrail,updateSubmSaveUpdatedProfile,viewTmSubmitterFileSearchCriteria,viewTmSubmitterFileSearch,viewTmSubmitterIntermediateFileSearch,viewTmSubmitterFileDetail,updateTmSubmitterFileAcknowledgement,updateTmSubmitterFileHold,updateTmBackDateHistoryQuery,updateTmBackDateProcess,viewTmDistributionFileSearchCriteria,viewTmDistributionFileSearch,viewTmDistributionFileDetail,setTomeZone,createTimeZone]; root of BeanFactory hierarchy

31 beans defined in application context
[WebApplicationContext for namespace 'ActionServlet-servlet']

JDK 1.4+ collections available

Unable to locate MessageSource with name 'messageSource': using default
[org.springframework.context.support.DelegatingMessageSource@df1832]

Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@193c0cf]

Unable to locate ThemeSource with name 'themeSource': using default
[org.springframework.ui.context.support.ResourceBundleThemeSource@e3c624]

Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans
[viewSubmSearchSubmitterResult,welcome,AuditTrail,viewSubmSearchSubmitterCriteria,updateSubmNewProfile,submProfile,updateSubmQueryProfile,updateSubmSaveNewProfile,updateSubmManageFileLayout,updateSubmManageFileAddenda,updateSubmManageCurrency,updateSubmReleaseProfile,viewSubmQueryProfile,viewSubmComments,viewSubmSaveComments,updateSubmDeleteProfile,viewSubmAuditTrail,updateSubmSaveUpdatedProfile,viewTmSubmitterFileSearchCriteria,viewTmSubmitterFileSearch,viewTmSubmitterIntermediateFileSearch,viewTmSubmitterFileDetail,updateTmSubmitterFileAcknowledgement,updateTmSubmitterFileHold,updateTmBackDateHistoryQuery,updateTmBackDateProcess,viewTmDistributionFileSearchCriteria,viewTmDistributionFileSearch,viewTmDistributionFileDetail,setTomeZone,createTimeZone]; root of BeanFactory hierarchy]
Using context
class 'org.springframework.web.context.support.XmlWebApplicationContext' for servlet 'ActionServlet'

ContextLoaderPlugIn for Struts
ActionServlet 'ActionServlet', module '': initialization completed in 1078 ms

Tiles definition factory loaded for module ''.

Loading validation rules file from '/WEB-INF/validator-rules.xml'

Loading validation rules file from '/WEB-INF/validation.xml'

Tiles definition factory found for request processor ''.
********** AET Java Presentation Framework version:1.2.9 ************

********** Powered by Apache Struts version:1.2.9 ************

AET Java Presentation Framework: Throttling Information - ThrottleCount: 45 Throttle Error Page :

AET Java Presentation Framework: EEC Event Logging is not enabled

Closing application context [WebApplicationContext for namespace 'ActionServlet-servlet']

Destroying singletons in factory {org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans
[viewSubmSearchSubmitterResult,welcome,AuditTrail,viewSubmSearchSubmitterCriteria,updateSubmNewProfile,submProfile,updateSubmQueryProfile,updateSubmSaveNewProfile,updateSubmManageFileLayout,updateSubmManageFileAddenda,updateSubmManageCurrency,updateSubmReleaseProfile,viewSubmQueryProfile,viewSubmComments,viewSubmSaveComments,updateSubmDeleteProfile,viewSubmAuditTrail,updateSubmSaveUpdatedProfile,viewTmSubmitterFileSearchCriteria,viewTmSubmitterFileSearch,viewTmSubmitterIntermediateFileSearch,viewTmSubmitterFileDetail,updateTmSubmitterFileAcknowledgement,updateTmSubmitterFileHold,updateTmBackDateHistoryQuery,updateTmBackDateProcess,viewTmDistributionFileSearchCriteria,viewTmDistributionFileSearch,viewTmDistributionFileDetail,setTomeZone,createTimeZone]; root of BeanFactory hierarchy}




and Junit Failure trace
isservletunit.struts.ExceptionDuringTestError: An uncaught exception was thrown during actionExecute()
at
servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:409)
at
com.americanexpress.merchsub.submitter.action.TestWelcomeAction.testSuccessfulLogin(TestWelcomeAction.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)
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:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)

------------
Root Cause:
------------

org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/authreg/welcome' defined in ServletContext resource [/WEB-INF/spring-xml/submissions-actions.xml]: Can't resolve reference to bean 'loggingUtility' while setting
property 'loggingUtility'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'loggingUtility' is defined: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans
[viewSubmSearchSubmitterResult,welcome,AuditTrail,viewSubmSearchSubmitterCriteria,updateSubmNewProfile,submProfile,updateSubmQueryProfile,updateSubmSaveNewProfile,updateSubmManageFileLayout,updateSubmManageFileAddenda,updateSubmManageCurrency,updateSubmReleaseProfile,viewSubmQueryProfile,viewSubmComments,viewSubmSaveComments,updateSubmDeleteProfile,viewSubmAuditTrail,updateSubmSaveUpdatedProfile,viewTmSubmitterFileSearchCriteria,viewTmSubmitterFileSearch,viewTmSubmitterIntermediateFileSearch,viewTmSubmitterFileDetail,updateTmSubmitterFileAcknowledgement,updateTmSubmitterFileHold,updateTmBackDateHistoryQuery,updateTmBackDateProcess,viewTmDistributionFileSearchCriteria,viewTmDistributionFileSearch,viewTmDistributionFileDetail,setTomeZone,createTimeZone]; root of BeanFactory hierarchy

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'loggingUtility' is defined: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans
[viewSubmSearchSubmitterResult,welcome,AuditTrail,viewSubmSearchSubmitterCriteria,updateSubmNewProfile,submProfile,updateSubmQueryProfile,updateSubmSaveNewProfile,updateSubmManageFileLayout,updateSubmManageFileAddenda,updateSubmManageCurrency,updateSubmReleaseProfile,viewSubmQueryProfile,viewSubmComments,viewSubmSaveComments,updateSubmDeleteProfile,viewSubmAuditTrail,updateSubmSaveUpdatedProfile,viewTmSubmitterFileSearchCriteria,viewTmSubmitterFileSearch,viewTmSubmitterIntermediateFileSearch,viewTmSubmitterFileDetail,updateTmSubmitterFileAcknowledgement,updateTmSubmitterFileHold,updateTmBackDateHistoryQuery,updateTmBackDateProcess,viewTmDistributionFileSearchCriteria,viewTmDistributionFileSearch,viewTmDistributionFileDetail,setTomeZone,createTimeZone]; root of BeanFactory hierarchy

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition
(DefaultListableBeanFactory.java:349)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:671)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1012)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:823)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:239)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:151)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:557)
at
org.springframework.web.struts.DelegatingTilesRequestProcessor.getDelegateAction(DelegatingTilesRequestProcessor.java:117)
at org.springframework.web.struts.DelegatingTilesRequestProcessor.processActionCreate(DelegatingTilesRequestProcessor.java:98)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:230)
at com.americanexpress.util.spring.integration.AETSpringTilesRequestProcessor.process(AETSpringTilesRequestProcessor.java:56)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at
servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:394)
at com.americanexpress.merchsub.submitter.action.TestWelcomeAction.testSuccessfulLogin(TestWelcomeAction.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)




submissions-actions.xml entry is










in Struts_config.xml






in Web.xml



locatorFactorySelector
submissions-application.xml



please help me out in this issue.

   <<Less
About | Sitemap | Contact