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