use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.
the class PrefixMethodInvocationUtilTest method testInvokePrefixMethod1.
// === invokePrefixMethod ===
public void testInvokePrefixMethod1() throws Exception {
PrefixMethodInvocationUtilTest.Action1 action = new PrefixMethodInvocationUtilTest.Action1();
// ActionProxy
ActionProxy mockActionProxy = (ActionProxy) createMock(ActionProxy.class);
expect(mockActionProxy.getMethod()).andStubReturn("save");
// ActionInvocation
ActionInvocation mockActionInvocation = (ActionInvocation) createMock(ActionInvocation.class);
expect(mockActionInvocation.getAction()).andStubReturn(action);
expect(mockActionInvocation.getProxy()).andStubReturn(mockActionProxy);
replay(mockActionProxy, mockActionInvocation);
PrefixMethodInvocationUtil.invokePrefixMethod(mockActionInvocation, new String[] { "prepare", "prepareDo" });
assertTrue(action.prepareSaveInvoked);
assertFalse(action.prepareDoSaveInvoked);
assertFalse(action.prepareSubmitInvoked);
assertFalse(action.prepareDoCancelInvoked);
verify(mockActionProxy, mockActionInvocation);
}
use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.
the class PrefixMethodInvocationUtilTest method testInvokePrefixMethod3.
public void testInvokePrefixMethod3() throws Exception {
PrefixMethodInvocationUtilTest.Action1 action = new PrefixMethodInvocationUtilTest.Action1();
// ActionProxy
ActionProxy mockActionProxy = (ActionProxy) createMock(ActionProxy.class);
expect(mockActionProxy.getMethod()).andStubReturn("cancel");
// ActionInvocation
ActionInvocation mockActionInvocation = (ActionInvocation) createMock(ActionInvocation.class);
expect(mockActionInvocation.getAction()).andStubReturn(action);
expect(mockActionInvocation.getProxy()).andStubReturn(mockActionProxy);
replay(mockActionProxy, mockActionInvocation);
PrefixMethodInvocationUtil.invokePrefixMethod(mockActionInvocation, new String[] { "prepare", "prepareDo" });
assertFalse(action.prepareSaveInvoked);
assertFalse(action.prepareDoSaveInvoked);
assertFalse(action.prepareSubmitInvoked);
assertTrue(action.prepareDoCancelInvoked);
verify(mockActionProxy, mockActionInvocation);
}
use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.
the class PrefixMethodInvocationUtilTest method testInvokePrefixMethod4.
public void testInvokePrefixMethod4() throws Exception {
PrefixMethodInvocationUtilTest.Action1 action = new PrefixMethodInvocationUtilTest.Action1();
// ActionProxy
ActionProxy mockActionProxy = (ActionProxy) createMock(ActionProxy.class);
expect(mockActionProxy.getMethod()).andStubReturn("noSuchMethod");
// ActionInvocation
ActionInvocation mockActionInvocation = (ActionInvocation) createMock(ActionInvocation.class);
expect(mockActionInvocation.getAction()).andStubReturn(action);
expect(mockActionInvocation.getProxy()).andStubReturn(mockActionProxy);
replay(mockActionProxy, mockActionInvocation);
PrefixMethodInvocationUtil.invokePrefixMethod(mockActionInvocation, new String[] { "prepare", "prepareDo" });
assertFalse(action.prepareSaveInvoked);
assertFalse(action.prepareDoSaveInvoked);
assertFalse(action.prepareSubmitInvoked);
assertFalse(action.prepareDoCancelInvoked);
verify(mockActionProxy, mockActionInvocation);
}
use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.
the class PrepareInterceptorTest method testPrepareCalledFalse.
public void testPrepareCalledFalse() throws Exception {
MockActionInvocation mai = new MockActionInvocation();
MockActionProxy mockActionProxy = new MockActionProxy();
mockActionProxy.setMethod("execute");
mai.setProxy(mockActionProxy);
mai.setAction(mock.proxy());
interceptor.setAlwaysInvokePrepare("false");
interceptor.intercept(mai);
}
use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.
the class PrepareInterceptorTest method testPrepareThrowException.
public void testPrepareThrowException() throws Exception {
MockActionInvocation mai = new MockActionInvocation();
MockActionProxy mockActionProxy = new MockActionProxy();
mockActionProxy.setMethod("submit");
mai.setProxy(mockActionProxy);
mai.setAction(mock.proxy());
IllegalAccessException illegalAccessException = new IllegalAccessException();
mock.expectAndThrow("prepareSubmit", illegalAccessException);
mock.matchAndThrow("prepare", new RuntimeException());
try {
interceptor.intercept(mai);
fail("Should not have reached this point.");
} catch (Throwable t) {
assertSame(illegalAccessException, t);
}
}
Aggregations