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