Search in sources :

Example 21 with SimpleAction

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

the class ConfigurationTest method testWildcardName.

public void testWildcardName() {
    RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
    ActionConfig config = configuration.getActionConfig("", "WildCard/Simple/input");
    assertNotNull(config);
    assertTrue("Wrong class name, " + config.getClassName(), "com.opensymphony.xwork2.SimpleAction".equals(config.getClassName()));
    assertTrue("Wrong method name", "input".equals(config.getMethodName()));
    Map<String, String> p = config.getParams();
    assertTrue("Wrong parameter, " + p.get("foo"), "Simple".equals(p.get("foo")));
    assertTrue("Wrong parameter, " + p.get("bar"), "input".equals(p.get("bar")));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig)

Example 22 with SimpleAction

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

the class ChainResultTest method testNamespaceChain.

public void testNamespaceChain() throws Exception {
    ActionProxy proxy = actionProxyFactory.createActionProxy(null, "chain_with_namespace", null, null);
    ((SimpleAction) proxy.getAction()).setBlah("%{foo}");
    proxy.execute();
    assertTrue(proxy.getInvocation().getResult() instanceof MockResult);
    MockResult result = (MockResult) proxy.getInvocation().getResult();
    assertEquals("%{foo}", result.getInvocation().getProxy().getNamespace());
}
Also used : MockResult(com.opensymphony.xwork2.mock.MockResult)

Example 23 with SimpleAction

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

the class DefaultActionInvocationTester method testActionChainResult.

public void testActionChainResult() throws Exception {
    ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "Foo", null, new HashMap<String, Object>());
    DefaultActionInvocation defaultActionInvocation = (DefaultActionInvocation) actionProxy.getInvocation();
    defaultActionInvocation.init(actionProxy);
    SimpleAction action = (SimpleAction) defaultActionInvocation.getAction();
    action.setFoo(1);
    action.setBar(2);
    defaultActionInvocation.invoke();
    // then
    assertTrue(defaultActionInvocation.result instanceof ActionChainResult);
    Result result = defaultActionInvocation.getResult();
    assertTrue(result instanceof MockResult);
}
Also used : MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy) MockResult(com.opensymphony.xwork2.mock.MockResult) MockResult(com.opensymphony.xwork2.mock.MockResult)

Example 24 with SimpleAction

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

the class DefaultActionInvocationTester method testActionEventListener.

public void testActionEventListener() throws Exception {
    ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "ExceptionFoo", "exceptionMethod", new HashMap<String, Object>());
    DefaultActionInvocation defaultActionInvocation = (DefaultActionInvocation) actionProxy.getInvocation();
    SimpleActionEventListener actionEventListener = new SimpleActionEventListener("prepared", "exceptionHandled");
    defaultActionInvocation.setActionEventListener(actionEventListener);
    defaultActionInvocation.init(actionProxy);
    SimpleAction action = (SimpleAction) defaultActionInvocation.getAction();
    action.setThrowException(true);
    defaultActionInvocation.unknownHandlerManager = new DefaultUnknownHandlerManager() {

        @Override
        public boolean hasUnknownHandlers() {
            return false;
        }
    };
    String result = defaultActionInvocation.invoke();
    // then
    assertEquals("prepared", action.getName());
    assertEquals("exceptionHandled", result);
}
Also used : MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 25 with SimpleAction

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

the class DefaultActionInvocationTester method testInvokingMissingMethod.

public void testInvokingMissingMethod() 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 ERROR;
        }
    };
    MockActionProxy proxy = new MockActionProxy();
    proxy.setMethod("notExists");
    UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {

        @Override
        public boolean hasUnknownHandlers() {
            return false;
        }
    };
    dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
    dai.proxy = proxy;
    dai.ognlUtil = new OgnlUtil();
    dai.unknownHandlerManager = uhm;
    // when
    Throwable actual = null;
    try {
        dai.invokeAction(action, 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)

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