Dear all,

I've create an AppFuse Struts 2 Application, but it fails when I run tests.
The test code is generated by AppFuse:

public class QuoteMasterActionTest extends BaseActionTestCase {
    private QuoteMasterAction action;

    public void setQuoteMasterAction(QuoteMasterAction action) {
        this.action = action;
    }

    @Override @SuppressWarnings("unchecked")
    protected void onSetUpBeforeTransaction() throws Exception {
        super.onSetUpBeforeTransaction();
        GenericManager quoteMasterManager = (GenericManager)
applicationContext.getBean("quoteMasterManager");

        // add a test quoteMaster to the database
        QuoteMaster quoteMaster = new QuoteMaster();

        // enter all required fields

        quoteMasterManager.save(quoteMaster);
    }

    public void testEdit() throws Exception {
        log.debug("testing edit...");
        action.setId(1L);
        assertNull(action.getQuoteMaster());
        assertEquals("success", action.edit());
        assertNotNull(action.getQuoteMaster());
        assertFalse(action.hasActionErrors());
    }
}

And the error log is the following:

-------------------------------------------------------------------------------
Test set: cn.net.cogent.summer.webapp.action.QuoteMasterActionTest
-------------------------------------------------------------------------------
Tests run: 4, Failures: 0, Errors: 4, Skipped: 0, Time elapsed: 0.141 sec
<<< FAILURE!
testEdit(cn.net.cogent.summer.webapp.action.QuoteMasterActionTest)  Time
elapsed: 0.11 sec  <<< ERROR!
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'quoteMasterAction' defined in file
[E:\USR\summer\target\test-classes\WEB-INF\applicationContext.xml]:
Initialization of bean failed; nested exception is
java.lang.IllegalStateException: No Scope registered for scope 'session'
Caused by: java.lang.IllegalStateException: No Scope registered for scope
'session'
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:282)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
        at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:261)
        at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1099)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:861)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:270)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:880)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:828)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:273)
        at
org.springframework.test.AbstractDependencyInjectionSpringContextTests.injectDependencies(AbstractDependencyInjectionSpringContextTests.java:179)
        at
org.springframework.test.AbstractDependencyInjectionSpringContextTests.prepareTestInstance(AbstractDependencyInjectionSpringContextTests.java:158)
        at
org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:88)
        at junit.framework.TestCase.runBare(TestCase.java:132)
        at
org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
        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:81)
        at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)
        at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818)

Actually, action quoteMasterAction's scope is the default one - prototype,
but it relies on another bean inquiryCart whose scope is set to 'session'.
The following is related configuration in applicationContext.xml:

    <bean id="quoteMasterAction"
class="cn.net.cogent.summer.webapp.action.QuoteMasterAction"
scope="prototype">
        <property name="cart" ref="inquiryCart" />
    </bean>

    <bean id="inquiryCart" class="cn.net.cogent.summer.model.InquiryCart"
scope="session" />

If I ignore the test and run "mvn war:war" to package my application &
deploy it onto the web server, it works OK without any errors. So what
should I do to avoid the test failure? Thanks for any clues.

Regards,
George
-- 
View this message in context: 
http://www.nabble.com/Test-failed%3A-No-Scope-registered-for-scope-%27session%27-tf4625813s2369.html#a13209587
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to