Search in sources :

Example 81 with Mock

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

the class ChainingInterceptorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    stack = ActionContext.getContext().getValueStack();
    mockInvocation = new Mock(ActionInvocation.class);
    mockInvocation.expectAndReturn("getStack", stack);
    mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
    mockInvocation.expectAndReturn("getInvocationContext", ActionContext.of(new HashMap<>()).bind());
    mockInvocation.expectAndReturn("getResult", new ActionChainResult());
    invocation = (ActionInvocation) mockInvocation.proxy();
    interceptor = new ChainingInterceptor();
    container.inject(interceptor);
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Example 82 with Mock

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

the class ConversionErrorInterceptorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    interceptor = new ConversionErrorInterceptor();
    mockInvocation = new Mock(ActionInvocation.class);
    invocation = (ActionInvocation) mockInvocation.proxy();
    stack = ActionContext.getContext().getValueStack();
    conversionErrors = new HashMap<>();
    context = ActionContext.of(stack.getContext()).withConversionErrors(conversionErrors).bind();
    mockInvocation.matchAndReturn("getInvocationContext", context);
    mockInvocation.expect("addPreResultListener", C.isA(PreResultListener.class));
    mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
}
Also used : MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) Mock(com.mockobjects.dynamic.Mock)

Example 83 with Mock

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

the class ExceptionMappingInterceptorTest method testThrownExceptionNoMatchLogging.

public void testThrownExceptionNoMatchLogging() {
    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.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 84 with Mock

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

the class ExceptionMappingInterceptorTest method testThrownExceptionNoMatchLoggingUnknownLevel.

public void testThrownExceptionNoMatchLoggingUnknownLevel() throws Exception {
    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.setLogLevel("xxx");
        interceptor.intercept(invocation);
        fail("Should not have reached this point.");
    } catch (IllegalArgumentException e) {
    // success
    }
}
Also used : Mock(com.mockobjects.dynamic.Mock) StrutsException(org.apache.struts2.StrutsException) ValidationException(com.opensymphony.xwork2.validator.ValidationException)

Example 85 with Mock

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

the class ExceptionMappingInterceptorTest method testThrownExceptionNoMatchLoggingCategoryLevelTrace.

public void testThrownExceptionNoMatchLoggingCategoryLevelTrace() {
    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("trace");
        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