Search in sources :

Example 16 with SimpleAction

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

the class DefaultActionInvocationTester method testInvokeWithLazyParams.

public void testInvokeWithLazyParams() throws Exception {
    HashMap<String, Object> params = new HashMap<>();
    params.put("blah", "this is blah");
    HashMap<String, Object> extraContext = new HashMap<>();
    extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
    DefaultActionInvocation defaultActionInvocation = new DefaultActionInvocation(extraContext, true);
    container.inject(defaultActionInvocation);
    ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "LazyFoo", null, extraContext);
    defaultActionInvocation.init(actionProxy);
    defaultActionInvocation.invoke();
    SimpleAction action = (SimpleAction) defaultActionInvocation.getAction();
    assertEquals("this is blah", action.getBlah());
    assertEquals("this is blah", action.getName());
}
Also used : MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy) HashMap(java.util.HashMap)

Example 17 with SimpleAction

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

the class DefaultActionInvocationTester method testUnknownHandlerManagerThatReturnsSuccess.

public void testUnknownHandlerManagerThatReturnsSuccess() 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 "success";
        }
    };
    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
    String result = dai.invokeAction(new SimpleAction(), null);
    // then
    assertNotNull(result);
    assertEquals("success", result);
}
Also used : OgnlUtil(com.opensymphony.xwork2.ognl.OgnlUtil) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 18 with SimpleAction

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

the class SpringObjectFactoryTest method testSetAutowireStrategy.

public void testSetAutowireStrategy() throws Exception {
    assertEquals(objectFactory.getAutowireStrategy(), AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
    objectFactory.setAutowireStrategy(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
    sac.getBeanFactory().registerSingleton("bean", new TestBean());
    TestBean bean = (TestBean) sac.getBean("bean");
    sac.registerPrototype("simple-action", SimpleAction.class, new MutablePropertyValues());
    ActionConfig actionConfig = new ActionConfig.Builder("jim", "bob", "simple-action").build();
    SimpleAction simpleAction = (SimpleAction) objectFactory.buildBean(actionConfig.getClassName(), null);
    objectFactory.autoWireBean(simpleAction);
    assertEquals(simpleAction.getBean(), bean);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) TestBean(com.opensymphony.xwork2.TestBean) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 19 with SimpleAction

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

the class ActionAutowiringInterceptorTest method testShouldAutowireAction.

public void testShouldAutowireAction() throws Exception {
    StaticWebApplicationContext context = new StaticWebApplicationContext();
    context.getBeanFactory().registerSingleton("bean", new TestBean());
    TestBean bean = (TestBean) context.getBean("bean");
    loadSpringApplicationContextIntoApplication(context);
    SimpleAction action = new SimpleAction();
    ActionInvocation invocation = new TestActionInvocation(action);
    ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor();
    interceptor.setApplicationContext(context);
    interceptor.init();
    interceptor.intercept(invocation);
    assertEquals(bean, action.getBean());
}
Also used : TestBean(com.opensymphony.xwork2.TestBean) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) SimpleAction(com.opensymphony.xwork2.SimpleAction)

Example 20 with SimpleAction

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

the class ActionsFromSpringTest method testProxiedActionIsNotStateful.

public void testProxiedActionIsNotStateful() throws Exception {
    ActionProxy proxy = actionProxyFactory.createActionProxy(null, "proxiedAction", null, null);
    SimpleAction action = (SimpleAction) proxy.getAction();
    action.setBlah("Hello World");
    proxy = actionProxyFactory.createActionProxy(null, "proxiedAction", null, null);
    action = (SimpleAction) proxy.getAction();
    // If the action is a singleton, this test will fail
    SimpleAction sa = new SimpleAction();
    assertEquals(sa.getBlah(), action.getBlah());
    // And if the advice is not being applied, this will be SUCCESS.
    String result = action.execute();
    assertEquals(Action.INPUT, result);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) 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