Search in sources :

Example 26 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class DefaultActionInvocationTester method testInvokingExistingExecuteMethod.

public void testInvokingExistingExecuteMethod() throws Exception {
    // given
    DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
    container.inject(dai);
    SimpleAction action = new SimpleAction() {

        @Override
        public String execute() throws Exception {
            return SUCCESS;
        }
    };
    MockActionProxy proxy = new MockActionProxy();
    proxy.setMethod("execute");
    dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
    dai.proxy = proxy;
    dai.ognlUtil = new OgnlUtil();
    // when
    String result = dai.invokeAction(action, null);
    // then
    assertEquals("success", result);
}
Also used : OgnlUtil(com.opensymphony.xwork2.ognl.OgnlUtil) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 27 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class DefaultActionInvocationTester method testUnknownHandlerManagerThatReturnsNull.

public void testUnknownHandlerManagerThatReturnsNull() throws Exception {
    // given
    DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
    container.inject(dai);
    UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {

        @Override
        public boolean hasUnknownHandlers() {
            return true;
        }

        @Override
        public Object handleUnknownMethod(Object action, String methodName) throws NoSuchMethodException {
            return null;
        }
    };
    MockActionProxy proxy = new MockActionProxy();
    proxy.setMethod("notExists");
    dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
    dai.proxy = proxy;
    dai.ognlUtil = new OgnlUtil();
    dai.unknownHandlerManager = uhm;
    // when
    Throwable actual = null;
    try {
        dai.invokeAction(new SimpleAction(), null);
    } catch (Exception e) {
        actual = e;
    }
    // then
    assertNotNull(actual);
    assertTrue(actual instanceof NoSuchMethodException);
}
Also used : OgnlUtil(com.opensymphony.xwork2.ognl.OgnlUtil) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 28 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class SpringObjectFactoryTest method testShouldAutowireObjectsObtainedFromTheObjectFactoryByFullClassName.

public void testShouldAutowireObjectsObtainedFromTheObjectFactoryByFullClassName() throws Exception {
    sac.getBeanFactory().registerSingleton("bean", new TestBean());
    TestBean bean = (TestBean) sac.getBean("bean");
    SimpleAction action = (SimpleAction) objectFactory.buildBean(SimpleAction.class.getName(), null);
    assertEquals(bean, action.getBean());
}
Also used : TestBean(com.opensymphony.xwork2.TestBean) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 29 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class SpringObjectFactoryTest method testShouldAutowireObjectsObtainedFromTheObjectFactoryByClass.

public void testShouldAutowireObjectsObtainedFromTheObjectFactoryByClass() throws Exception {
    sac.getBeanFactory().registerSingleton("bean", new TestBean());
    TestBean bean = (TestBean) sac.getBean("bean");
    SimpleAction action = (SimpleAction) objectFactory.buildBean(SimpleAction.class, null);
    assertEquals(bean, action.getBean());
}
Also used : TestBean(com.opensymphony.xwork2.TestBean) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 30 with SimpleAction

use of com.opensymphony.xwork2.SimpleAction in project struts by apache.

the class ActionAutowiringInterceptorTest method testLoadsApplicationContextUsingWebApplicationContextUtils.

public void testLoadsApplicationContextUsingWebApplicationContextUtils() throws Exception {
    StaticWebApplicationContext appContext = new StaticWebApplicationContext();
    loadSpringApplicationContextIntoApplication(appContext);
    ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor();
    interceptor.init();
    SimpleAction action = new SimpleAction();
    ActionInvocation invocation = new TestActionInvocation(action);
    interceptor.intercept(invocation);
    ApplicationContext loadedContext = interceptor.getApplicationContext();
    assertEquals(appContext, loadedContext);
}
Also used : WebApplicationContext(org.springframework.web.context.WebApplicationContext) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Aggregations

SimpleAction (com.opensymphony.xwork2.SimpleAction)32 ActionProxy (com.opensymphony.xwork2.ActionProxy)24 HashMap (java.util.HashMap)23 LinkedHashMap (java.util.LinkedHashMap)17 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)14 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)8 XmlConfigurationProvider (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider)7 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)7 OgnlUtil (com.opensymphony.xwork2.ognl.OgnlUtil)6 Action (com.opensymphony.xwork2.Action)5 TestBean (com.opensymphony.xwork2.TestBean)5 OgnlValueStack (com.opensymphony.xwork2.ognl.OgnlValueStack)5 ValueStack (com.opensymphony.xwork2.util.ValueStack)5 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)4 ModelDrivenAction (com.opensymphony.xwork2.ModelDrivenAction)3 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)3 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)3 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)3 MockConfigurationProvider (com.opensymphony.xwork2.config.providers.MockConfigurationProvider)2 MockResult (com.opensymphony.xwork2.mock.MockResult)2