Search in sources :

Example 1 with MockActionProxy

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);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ActionInvocation(com.opensymphony.xwork2.ActionInvocation)

Example 2 with MockActionProxy

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);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ActionInvocation(com.opensymphony.xwork2.ActionInvocation)

Example 3 with MockActionProxy

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);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ActionInvocation(com.opensymphony.xwork2.ActionInvocation)

Example 4 with MockActionProxy

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);
}
Also used : MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 5 with MockActionProxy

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);
    }
}
Also used : MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Aggregations

MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)43 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)34 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)29 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)19 ActionProxy (com.opensymphony.xwork2.ActionProxy)17 HashMap (java.util.HashMap)15 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)13 ActionContext (com.opensymphony.xwork2.ActionContext)12 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)11 SimpleFooAction (com.opensymphony.xwork2.SimpleFooAction)10 ServletActionContext (org.apache.struts2.ServletActionContext)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)10 OgnlUtil (com.opensymphony.xwork2.ognl.OgnlUtil)8 ActionMapper (org.apache.struts2.dispatcher.mapper.ActionMapper)7 IMocksControl (org.easymock.IMocksControl)7 ValueStack (com.opensymphony.xwork2.util.ValueStack)6 DefaultUrlHelper (org.apache.struts2.views.util.DefaultUrlHelper)6 Mock (com.mockobjects.dynamic.Mock)5 Action (com.opensymphony.xwork2.Action)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5