Search in sources :

Example 1 with MockActionInvocation

use of com.opensymphony.xwork2.mock.MockActionInvocation in project struts by apache.

the class FreemarkerResultMockedTest method init.

private void init() {
    stringWriter = new StringWriter();
    writer = new PrintWriter(stringWriter);
    response = new StrutsMockHttpServletResponse();
    response.setWriter(writer);
    request = new MockHttpServletRequest();
    stack = ActionContext.getContext().getValueStack();
    context = ActionContext.of(stack.getContext()).withServletResponse(response).withServletRequest(request).withServletContext(servletContext).bind();
    servletContext.setAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY, null);
    invocation = new MockActionInvocation();
    invocation.setStack(stack);
    invocation.setInvocationContext(context);
    // get fm config to use it in mock servlet context
    FreemarkerManager freemarkerManager = container.getInstance(FreemarkerManager.class);
    freemarkerConfig = freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
    freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    freemarkerConfig.setServletContextForTemplateLoading(servletContext, null);
}
Also used : StringWriter(java.io.StringWriter) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) StrutsMockHttpServletResponse(org.apache.struts2.views.jsp.StrutsMockHttpServletResponse) PrintWriter(java.io.PrintWriter)

Example 2 with MockActionInvocation

use of com.opensymphony.xwork2.mock.MockActionInvocation in project struts by apache.

the class ValidateAction method testNoParametersAction.

public void testNoParametersAction() throws Exception {
    ParametersInterceptor interceptor = new ParametersInterceptor();
    interceptor.init();
    MockActionInvocation mai = new MockActionInvocation();
    Action action = new NoParametersAction();
    mai.setAction(action);
    interceptor.doIntercept(mai);
    interceptor.destroy();
}
Also used : SimpleAction(com.opensymphony.xwork2.SimpleAction) ModelDrivenAction(com.opensymphony.xwork2.ModelDrivenAction) Action(com.opensymphony.xwork2.Action) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation)

Example 3 with MockActionInvocation

use of com.opensymphony.xwork2.mock.MockActionInvocation 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 4 with MockActionInvocation

use of com.opensymphony.xwork2.mock.MockActionInvocation 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 5 with MockActionInvocation

use of com.opensymphony.xwork2.mock.MockActionInvocation 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)

Aggregations

MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)84 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)32 HashMap (java.util.HashMap)29 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)22 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)22 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)20 ActionContext (com.opensymphony.xwork2.ActionContext)16 Mock (com.mockobjects.dynamic.Mock)11 ActionSupport (com.opensymphony.xwork2.ActionSupport)11 ServletActionContext (org.apache.struts2.ServletActionContext)11 SimpleFooAction (com.opensymphony.xwork2.SimpleFooAction)10 LinkedHashMap (java.util.LinkedHashMap)10 ActionProxy (com.opensymphony.xwork2.ActionProxy)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 Action (com.opensymphony.xwork2.Action)7 SimpleAction (com.opensymphony.xwork2.SimpleAction)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 MockServletContext (org.springframework.mock.web.MockServletContext)7 ValueStack (com.opensymphony.xwork2.util.ValueStack)6 StringWriter (java.io.StringWriter)6