01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.dispatcher;
06:
07: import java.util.Locale;
08:
09: import javax.servlet.http.HttpServletRequest;
10: import javax.servlet.http.HttpServletResponse;
11:
12: import org.springframework.mock.web.MockHttpServletRequest;
13: import org.springframework.mock.web.MockHttpServletResponse;
14: import org.springframework.mock.web.MockServletContext;
15:
16: import com.opensymphony.webwork.WebWorkConstants;
17: import com.opensymphony.webwork.WebWorkTestCase;
18: import com.opensymphony.webwork.config.Configuration;
19: import com.opensymphony.xwork.util.LocalizedTextUtil;
20:
21: /**
22: * Test case for DispatcherUtils.
23: *
24: * @author tm_jee
25: * @version $Date: 2006-08-06 19:06:11 +0200 (Sun, 06 Aug 2006) $ $Id: DispatcherUtilsTest.java 2671 2006-08-06 17:06:11Z tmjee $
26: */
27: public class DispatcherUtilsTest extends WebWorkTestCase {
28:
29: public void testDefaultResurceBundlePropertyLoaded()
30: throws Exception {
31: Locale.setDefault(Locale.US); // force to US locale as we also have _de and _da properties
32: DispatcherUtils.setInstance(null);
33: DispatcherUtils.initialize(new MockServletContext());
34:
35: // some i18n messages from xwork-messages.properties
36: assertEquals(LocalizedTextUtil.findDefaultText(
37: "xwork.error.action.execution", Locale.US),
38: "Error during Action invocation");
39:
40: // some i18n messages from webwork-messages.properties
41: assertEquals(LocalizedTextUtil.findDefaultText(
42: "webwork.messages.error.uploading", Locale.US,
43: new Object[] { "some error messages" }),
44: "Error uploading: some error messages");
45: }
46:
47: public void testPrepareSetEncodingProperly() throws Exception {
48: HttpServletRequest req = new MockHttpServletRequest();
49: HttpServletResponse res = new MockHttpServletResponse();
50:
51: Configuration.set(WebWorkConstants.WEBWORK_I18N_ENCODING,
52: "utf-8");
53:
54: DispatcherUtils.setInstance(null);
55: DispatcherUtils.initialize(new MockServletContext());
56: DispatcherUtils du = DispatcherUtils.getInstance();
57: du.prepare(req, res);
58:
59: assertEquals(req.getCharacterEncoding(), "utf-8");
60: }
61:
62: public void testPrepareSetEncodingPropertyWithMultipartRequest()
63: throws Exception {
64: MockHttpServletRequest req = new MockHttpServletRequest();
65: MockHttpServletResponse res = new MockHttpServletResponse();
66:
67: req.setContentType("multipart/form-data");
68: Configuration.set(WebWorkConstants.WEBWORK_I18N_ENCODING,
69: "utf-8");
70:
71: DispatcherUtils.setInstance(null);
72: DispatcherUtils.initialize(new MockServletContext());
73: DispatcherUtils du = DispatcherUtils.getInstance();
74: du.prepare(req, res);
75:
76: assertEquals(req.getCharacterEncoding(), "utf-8");
77: }
78: }
|