Search in sources :

Example 11 with SimpleAction

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

the class SimpleActionValidationTest method testMessageKeyIsReturnedIfNoOtherDefault.

public void testMessageKeyIsReturnedIfNoOtherDefault() throws ValidationException {
    Validator validator = new ValidatorSupport() {

        public void validate(Object object) throws ValidationException {
            addActionError(object);
        }
    };
    validator.setValueStack(ActionContext.getContext().getValueStack());
    String messageKey = "does.not.exist";
    validator.setMessageKey(messageKey);
    SimpleAction action = new SimpleAction();
    container.inject(action);
    ValidatorContext validatorContext = new DelegatingValidatorContext(action, container.getInstance(TextProviderFactory.class));
    validator.setValidatorContext(validatorContext);
    validator.validate(this);
    assertTrue(validatorContext.hasActionErrors());
    Collection<String> errors = validatorContext.getActionErrors();
    assertEquals(1, errors.size());
    assertEquals(messageKey, errors.toArray()[0]);
}
Also used : TextProviderFactory(com.opensymphony.xwork2.TextProviderFactory) SimpleAction(com.opensymphony.xwork2.SimpleAction) ValidatorSupport(com.opensymphony.xwork2.validator.validators.ValidatorSupport)

Example 12 with SimpleAction

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

the class StrutsLocalizedTextProviderTest method testAddDefaultResourceBundle2.

public void testAddDefaultResourceBundle2() throws Exception {
    localizedTextProvider.addDefaultResourceBundle("com/opensymphony/xwork2/SimpleAction");
    ActionProxy proxy = actionProxyFactory.createActionProxy("/", "packagelessAction", null, new HashMap<String, Object>(), false, true);
    proxy.execute();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy)

Example 13 with SimpleAction

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

the class ConfigurationTest method testWildcardNamespace.

public void testWildcardNamespace() {
    RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
    ActionConfig config = configuration.getActionConfig("/animals/dog", "commandTest");
    assertNotNull(config);
    assertTrue("Wrong class name, " + config.getClassName(), "com.opensymphony.xwork2.SimpleAction".equals(config.getClassName()));
    Map<String, String> p = config.getParams();
    assertTrue("Wrong parameter, " + p.get("0"), "/animals/dog".equals(p.get("0")));
    assertTrue("Wrong parameter, " + p.get("1"), "dog".equals(p.get("1")));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig)

Example 14 with SimpleAction

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

the class DefaultActionInvocationTester method testUnknownHandlerManagerThatThrowsException.

public void testUnknownHandlerManagerThatThrowsException() 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 {
            throw new NoSuchMethodException();
        }
    };
    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
    // 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 15 with SimpleAction

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

the class DefaultActionInvocationTester method testInvokingExistingMethodThatThrowsException.

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

        @Override
        public String execute() throws Exception {
            throw new IllegalArgumentException();
        }
    };
    MockActionProxy proxy = new MockActionProxy();
    proxy.setMethod("execute");
    dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
    dai.proxy = proxy;
    dai.ognlUtil = new OgnlUtil();
    // when
    Throwable actual = null;
    try {
        dai.invokeAction(action, null);
    } catch (Exception e) {
        actual = e;
    }
    // then
    assertNotNull(actual);
    assertTrue(actual instanceof IllegalArgumentException);
}
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