Search in sources :

Example 6 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class ExceptionMappingInterceptorTest method testThrownExceptionNoMatchLoggingCategoryLevelFatal.

public void testThrownExceptionNoMatchLoggingCategoryLevelFatal() {
    this.setupWithoutExceptionMappings();
    Mock action = new Mock(Action.class);
    Exception exception = new Exception("test");
    mockInvocation.expectAndThrow("invoke", exception);
    mockInvocation.matchAndReturn("getAction", action.proxy());
    try {
        interceptor.setLogEnabled(true);
        interceptor.setLogCategory("showcase.unhandled");
        interceptor.setLogLevel("fatal");
        interceptor.intercept(invocation);
        fail("Should not have reached this point.");
    } catch (Exception e) {
        assertEquals(e, exception);
    }
    assertEquals("fatal", interceptor.getLogLevel());
    assertTrue(interceptor.isLogEnabled());
    assertEquals("showcase.unhandled", interceptor.getLogCategory());
}
Also used : Mock(com.mockobjects.dynamic.Mock) StrutsException(org.apache.struts2.StrutsException) ValidationException(com.opensymphony.xwork2.validator.ValidationException)

Example 7 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class ModelDrivenInterceptorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mockActionInvocation = new Mock(ActionInvocation.class);
    modelDrivenInterceptor = new ModelDrivenInterceptor();
    stack = ActionContext.getContext().getValueStack();
    // any object will do
    model = new Date();
}
Also used : Mock(com.mockobjects.dynamic.Mock) Date(java.util.Date)

Example 8 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class ParameterFilterInterceptorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    stack = ActionContext.getContext().getValueStack();
    mockInvocation = new Mock(ActionInvocation.class);
    mockInvocation.expectAndReturn("getInvocationContext", ActionContext.getContext());
    mockInvocation.expectAndReturn("getStack", stack);
    mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
    mockInvocation.expectAndReturn("getInvocationContext", ActionContext.getContext());
    mockInvocation.matchAndReturn("getAction", new SimpleAction());
    invocation = (ActionInvocation) mockInvocation.proxy();
    interceptor = new ParameterFilterInterceptor();
    interceptor.init();
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Example 9 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class PreResultListenerTest method testPreResultListenersAreCalled.

public void testPreResultListenersAreCalled() throws Exception {
    ActionProxy proxy = actionProxyFactory.createActionProxy("package", "action", null, new HashMap<String, Object>(), false, true);
    ActionInvocation invocation = proxy.getInvocation();
    Mock preResultListenerMock1 = new Mock(PreResultListener.class);
    preResultListenerMock1.expect("beforeResult", C.args(C.eq(invocation), C.eq(Action.SUCCESS)));
    invocation.addPreResultListener((PreResultListener) preResultListenerMock1.proxy());
    proxy.execute();
    preResultListenerMock1.verify();
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Example 10 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class PrepareInterceptorTest method setUp.

@Override
protected void setUp() throws Exception {
    mock = new Mock(ActionInterface.class);
    interceptor = new PrepareInterceptor();
    mockAction = (ActionInterface) createMock(ActionInterface.class);
}
Also used : Mock(com.mockobjects.dynamic.Mock) EasyMock(org.easymock.EasyMock)

Aggregations

Mock (com.mockobjects.dynamic.Mock)91 HashMap (java.util.HashMap)14 ValidationException (com.opensymphony.xwork2.validator.ValidationException)12 StrutsException (org.apache.struts2.StrutsException)12 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 ActionContext (com.opensymphony.xwork2.ActionContext)8 TreeMap (java.util.TreeMap)8 ActionProxy (com.opensymphony.xwork2.ActionProxy)6 HttpParameters (org.apache.struts2.dispatcher.HttpParameters)6 MockHttpSession (org.springframework.mock.web.MockHttpSession)6 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)4 Container (com.opensymphony.xwork2.inject.Container)4 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)4 ModelDrivenAction2 (com.opensymphony.xwork2.test.ModelDrivenAction2)4 LinkedHashMap (java.util.LinkedHashMap)4 Action (com.opensymphony.xwork2.Action)3