use of com.opensymphony.xwork2.SimpleAction in project struts by apache.
the class DefaultActionInvocationTester method testInvokingExistingExecuteMethod.
public void testInvokingExistingExecuteMethod() 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 SUCCESS;
}
};
MockActionProxy proxy = new MockActionProxy();
proxy.setMethod("execute");
dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
dai.proxy = proxy;
dai.ognlUtil = new OgnlUtil();
// when
String result = dai.invokeAction(action, null);
// then
assertEquals("success", result);
}
use of com.opensymphony.xwork2.SimpleAction in project struts by apache.
the class DefaultActionInvocationTester method testUnknownHandlerManagerThatReturnsNull.
public void testUnknownHandlerManagerThatReturnsNull() 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 null;
}
};
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
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 SpringObjectFactoryTest method testShouldAutowireObjectsObtainedFromTheObjectFactoryByFullClassName.
public void testShouldAutowireObjectsObtainedFromTheObjectFactoryByFullClassName() throws Exception {
sac.getBeanFactory().registerSingleton("bean", new TestBean());
TestBean bean = (TestBean) sac.getBean("bean");
SimpleAction action = (SimpleAction) objectFactory.buildBean(SimpleAction.class.getName(), null);
assertEquals(bean, action.getBean());
}
use of com.opensymphony.xwork2.SimpleAction in project struts by apache.
the class SpringObjectFactoryTest method testShouldAutowireObjectsObtainedFromTheObjectFactoryByClass.
public void testShouldAutowireObjectsObtainedFromTheObjectFactoryByClass() throws Exception {
sac.getBeanFactory().registerSingleton("bean", new TestBean());
TestBean bean = (TestBean) sac.getBean("bean");
SimpleAction action = (SimpleAction) objectFactory.buildBean(SimpleAction.class, null);
assertEquals(bean, action.getBean());
}
use of com.opensymphony.xwork2.SimpleAction in project struts by apache.
the class ActionAutowiringInterceptorTest method testLoadsApplicationContextUsingWebApplicationContextUtils.
public void testLoadsApplicationContextUsingWebApplicationContextUtils() throws Exception {
StaticWebApplicationContext appContext = new StaticWebApplicationContext();
loadSpringApplicationContextIntoApplication(appContext);
ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor();
interceptor.init();
SimpleAction action = new SimpleAction();
ActionInvocation invocation = new TestActionInvocation(action);
interceptor.intercept(invocation);
ApplicationContext loadedContext = interceptor.getApplicationContext();
assertEquals(appContext, loadedContext);
}
Aggregations