Search in sources :

Example 1 with AnyConstraintMatcher

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

the class RestWorkflowInterceptorTest method testCustomValidationFailureStatusCode.

public void testCustomValidationFailureStatusCode() throws Exception {
    RestWorkflowInterceptor wf = new RestWorkflowInterceptor();
    ActionSupport action = new ActionSupport();
    action.addActionError("some error");
    wf.setValidationFailureStatusCode("666");
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    Mock mockActionProxy = new Mock(ActionProxy.class);
    mockActionProxy.expectAndReturn("getConfig", null);
    mockActionInvocation.expectAndReturn("getAction", action);
    Mock mockContentTypeHandlerManager = new Mock(ContentTypeHandlerManager.class);
    mockContentTypeHandlerManager.expectAndReturn("handleResult", new AnyConstraintMatcher() {

        public boolean matches(Object[] args) {
            DefaultHttpHeaders headers = (DefaultHttpHeaders) args[1];
            return 666 == headers.getStatus();
        }
    }, null);
    wf.setContentTypeHandlerManager((ContentTypeHandlerManager) mockContentTypeHandlerManager.proxy());
    ActionContext.of(new HashMap<>()).withActionMapping(new ActionMapping()).bind();
    wf.doIntercept((ActionInvocation) mockActionInvocation.proxy());
    mockContentTypeHandlerManager.verify();
    mockActionInvocation.verify();
}
Also used : ActionMapping(org.apache.struts2.dispatcher.mapper.ActionMapping) ActionSupport(com.opensymphony.xwork2.ActionSupport) Mock(com.mockobjects.dynamic.Mock) AnyConstraintMatcher(com.mockobjects.dynamic.AnyConstraintMatcher)

Aggregations

AnyConstraintMatcher (com.mockobjects.dynamic.AnyConstraintMatcher)1 Mock (com.mockobjects.dynamic.Mock)1 ActionSupport (com.opensymphony.xwork2.ActionSupport)1 ActionMapping (org.apache.struts2.dispatcher.mapper.ActionMapping)1