1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.dispatcher;
19
20 import java.util.Locale;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import org.apache.struts2.StrutsConstants;
26 import org.apache.struts2.StrutsTestCase;
27 import org.apache.struts2.config.Settings;
28 import org.springframework.mock.web.MockHttpServletRequest;
29 import org.springframework.mock.web.MockHttpServletResponse;
30
31 import com.opensymphony.xwork2.util.LocalizedTextUtil;
32
33 /***
34 * Test case for Dispatcher.
35 *
36 */
37 public class DispatcherTest extends StrutsTestCase {
38
39 public void testDefaultResurceBundlePropertyLoaded() throws Exception {
40 Locale.setDefault(Locale.US);
41
42
43 assertEquals(
44 LocalizedTextUtil.findDefaultText("xwork.error.action.execution", Locale.US),
45 "Error during Action invocation");
46
47
48 assertEquals(
49 LocalizedTextUtil.findDefaultText("struts.messages.error.uploading", Locale.US,
50 new Object[] { "some error messages" }),
51 "Error uploading: some error messages");
52 }
53
54 public void testPrepareSetEncodingProperly() throws Exception {
55 HttpServletRequest req = new MockHttpServletRequest();
56 HttpServletResponse res = new MockHttpServletResponse();
57
58 Settings.set(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8");
59
60
61 Dispatcher du = Dispatcher.getInstance();
62 du.prepare(req, res);
63
64 assertEquals(req.getCharacterEncoding(), "utf-8");
65 }
66
67 public void testPrepareSetEncodingPropertyWithMultipartRequest() throws Exception {
68 MockHttpServletRequest req = new MockHttpServletRequest();
69 MockHttpServletResponse res = new MockHttpServletResponse();
70
71 req.setContentType("multipart/form-data");
72 Settings.set(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8");
73
74
75 Dispatcher du = Dispatcher.getInstance();
76 du.prepare(req, res);
77
78 assertEquals(req.getCharacterEncoding(), "utf-8");
79 }
80 }