1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.rest;
22
23 import com.mockobjects.dynamic.AnyConstraintMatcher;
24 import com.mockobjects.dynamic.Mock;
25 import com.opensymphony.xwork2.ActionContext;
26 import com.opensymphony.xwork2.ActionInvocation;
27 import com.opensymphony.xwork2.ActionProxy;
28 import com.opensymphony.xwork2.ActionSupport;
29 import junit.framework.TestCase;
30 import org.apache.struts2.ServletActionContext;
31 import org.apache.struts2.dispatcher.mapper.ActionMapping;
32
33 import java.util.HashMap;
34
35 public class RestWorkflowInterceptorTest extends TestCase {
36
37 public void testCustomValidationFailureStatusCode() throws Exception {
38 RestWorkflowInterceptor wf = new RestWorkflowInterceptor();
39
40 ActionSupport action = new ActionSupport();
41 action.addActionError("some error");
42
43 wf.setValidationFailureStatusCode("666");
44 Mock mockActionInvocation = new Mock(ActionInvocation.class);
45 Mock mockActionProxy = new Mock(ActionProxy.class);
46 mockActionProxy.expectAndReturn("getConfig", null);
47 mockActionInvocation.expectAndReturn("getProxy", mockActionProxy.proxy());
48 mockActionInvocation.expectAndReturn("getAction", action);
49 Mock mockContentTypeHandlerManager = new Mock(ContentTypeHandlerManager.class);
50 mockContentTypeHandlerManager.expectAndReturn("handleResult", new AnyConstraintMatcher() {
51 public boolean matches(Object[] args) {
52 DefaultHttpHeaders headers = (DefaultHttpHeaders) args[1];
53 return 666 == headers.status;
54 }
55 }, null);
56 wf.setContentTypeHandlerManager((ContentTypeHandlerManager) mockContentTypeHandlerManager.proxy());
57
58 ActionContext.setContext(new ActionContext(new HashMap() {{
59 put(ServletActionContext.ACTION_MAPPING, new ActionMapping());
60 }}));
61 wf.doIntercept((ActionInvocation) mockActionInvocation.proxy());
62 mockContentTypeHandlerManager.verify();
63 mockActionInvocation.verify();
64 }
65 }