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]);
}
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();
}
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")));
}
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);
}
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);
}
Aggregations