1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.unit;
17
18 import java.io.IOException;
19 import java.lang.reflect.Field;
20
21 import javax.servlet.FilterChain;
22 import javax.servlet.ServletException;
23 import javax.servlet.ServletRequest;
24 import javax.servlet.ServletResponse;
25
26 import org.seasar.cubby.action.ActionResult;
27 import org.seasar.cubby.action.Forward;
28 import org.seasar.cubby.action.Redirect;
29 import org.seasar.cubby.controller.ActionProcessor;
30 import org.seasar.cubby.filter.RequestRoutingFilter;
31 import org.seasar.framework.unit.S2TigerTestCase;
32 import org.seasar.framework.util.FieldUtil;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 public class CubbyTestCase extends S2TigerTestCase {
66
67
68 private RequestRoutingFilter.Router router = new RequestRoutingFilter.Router();
69
70 private MockFilterChain filterChain = new MockFilterChain();
71
72
73 private ActionProcessor actionProcessor;
74
75
76
77
78
79
80
81
82
83
84
85 public static void assertPathEquals(
86 Class<? extends ActionResult> resultClass, String expectedPath,
87 ActionResult actualResult) {
88 assertEquals("ActionResultの型をチェック", resultClass, actualResult
89 .getClass());
90 if (actualResult instanceof Forward) {
91 assertEquals("パスのチェック", expectedPath, ((Forward) actualResult)
92 .getPath());
93 } else if (actualResult instanceof Redirect) {
94 assertEquals("パスのチェック", expectedPath, ((Redirect) actualResult)
95 .getPath());
96 }
97 }
98
99
100
101
102
103
104
105
106
107 @SuppressWarnings( { "hiding", "unchecked" })
108 protected ActionResult processAction(String orginalPath) throws Exception {
109 routing(orginalPath);
110 return actionProcessor
111 .process(getRequest(), getResponse(), filterChain);
112 }
113
114
115
116
117
118
119
120
121
122 protected String routing(String orginalPath) throws NoSuchFieldException {
123 Field field = getRequest().getClass().getDeclaredField("servletPath");
124 field.setAccessible(true);
125 FieldUtil.set(field, getRequest(), orginalPath);
126 String forwardPath = router.routing(getRequest(), getResponse());
127 FieldUtil.set(field, getRequest(), forwardPath);
128 return forwardPath;
129 }
130
131
132
133
134
135
136 private static class MockFilterChain implements FilterChain {
137 public void doFilter(ServletRequest request, ServletResponse response)
138 throws IOException, ServletException {
139 }
140 }
141
142 }