Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

namespace '/'No Scope registered for scope 'request' in JUNIT

I am writing Unit Tests for Struts Action classes integrated with Spring.

Struts.xml

<action name = "displaySearchCertiSchedulerAction" 
       class = "certificationSchedulerAction" 
      method = "displaySearchCertiScheduler">

    <result name = "success">/jsp/admin/SearchCertiScheduler.jsp</result>
</action>

applicationContext.xml

<bean name = "certificationSchedulerAction"
     class = "com.admin.action.CertificationSchedulerAction"
     scope = "request">

    <property name = "certificationSchedulerServices" 
               ref = "certificationSchedulerServices" />
</bean>

JUnit

@SuppressWarnings("rawtypes")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class BrokerActionTest extends StrutsSpringJUnit4TestCase {

    @Test
    public void testGetActionProxy() throws Exception {
        ActionProxy proxy   =  getActionProxy("/getEventCategoryAction");
        CertificationSchedulerAction schedulerAction = 
                                (CertificationSchedulerAction) proxy.getAction();

        assertNotNull(proxy);            
     }
}

Error:

Tests in error: testGetActionProxy(com.admin.action.BrokerActionTest): Unable to instantiate Action, certificationSchedulerAction, defined for 'getEventCategoryAction' in namespace '/' No Scope registered for scope 'request'

This works fine if I don't explicitly specify the scope, but it gives error if I specify the scope.

like image 761
user3381610 Avatar asked Dec 01 '25 06:12

user3381610


1 Answers

The request scope (and its handlers) is registered by a WebApplicationContext implementation. If you're going to test in a web environment, you'll need @WebAppConfiguration.

like image 97
Sotirios Delimanolis Avatar answered Dec 03 '25 20:12

Sotirios Delimanolis