Search in sources :

Example 86 with Mock

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

the class ExceptionMappingInterceptorTest method setupWithoutExceptionMappings.

private void setupWithoutExceptionMappings() {
    ActionConfig actionConfig = new ActionConfig.Builder("", "", "").build();
    Mock actionProxy = new Mock(ActionProxy.class);
    actionProxy.expectAndReturn("getConfig", actionConfig);
    mockInvocation.expectAndReturn("getProxy", actionProxy.proxy());
    invocation = (ActionInvocation) mockInvocation.proxy();
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) Mock(com.mockobjects.dynamic.Mock)

Example 87 with Mock

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

the class ExceptionMappingInterceptorTest method testThrownExceptionNoMatchLoggingCategoryLevelDebug.

public void testThrownExceptionNoMatchLoggingCategoryLevelDebug() {
    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("debug");
        interceptor.intercept(invocation);
        fail("Should not have reached this point.");
    } catch (Exception e) {
        assertEquals(e, exception);
    }
}
Also used : Mock(com.mockobjects.dynamic.Mock) StrutsException(org.apache.struts2.StrutsException) ValidationException(com.opensymphony.xwork2.validator.ValidationException)

Example 88 with Mock

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

the class ExceptionMappingInterceptorTest method testThrownExceptionNoMatchLoggingCategoryLevelWarn.

public void testThrownExceptionNoMatchLoggingCategoryLevelWarn() {
    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("warn");
        interceptor.intercept(invocation);
        fail("Should not have reached this point.");
    } catch (Exception e) {
        assertEquals(e, exception);
    }
}
Also used : Mock(com.mockobjects.dynamic.Mock) StrutsException(org.apache.struts2.StrutsException) ValidationException(com.opensymphony.xwork2.validator.ValidationException)

Example 89 with Mock

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

the class ExceptionMappingInterceptorTest method testThrownExceptionMatching2.

public void testThrownExceptionMatching2() throws Exception {
    this.setUpWithExceptionMappings();
    Mock action = new Mock(Action.class);
    Exception exception = new ValidationException("test");
    mockInvocation.expectAndThrow("invoke", exception);
    mockInvocation.matchAndReturn("getAction", action.proxy());
    String result = interceptor.intercept(invocation);
    assertNotNull(stack.findValue("exception"));
    assertEquals(stack.findValue("exception"), exception);
    assertEquals(result, "throwable");
}
Also used : ValidationException(com.opensymphony.xwork2.validator.ValidationException) Mock(com.mockobjects.dynamic.Mock) StrutsException(org.apache.struts2.StrutsException) ValidationException(com.opensymphony.xwork2.validator.ValidationException)

Example 90 with Mock

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

the class ExceptionMappingInterceptorTest method testThrownExceptionNoMatch.

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

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