1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.chain.web.portlet;
17
18
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22 import org.apache.commons.chain.Context;
23
24 import javax.portlet.PortletContext;
25 import javax.portlet.PortletRequest;
26 import javax.portlet.PortletResponse;
27 import javax.portlet.PortletSession;
28 import java.util.Locale;
29
30
31
32
33 public class PortletGetLocaleCommandTestCase extends TestCase {
34
35
36
37
38 /***
39 * Construct a new instance of this test case.
40 *
41 * @param name Name of the test case
42 */
43 public PortletGetLocaleCommandTestCase(String name) {
44 super(name);
45 }
46
47
48
49
50
51 protected Locale locale = null;
52
53
54 protected PortletContext pcontext = null;
55 protected PortletRequest request = null;
56 protected PortletResponse response = null;
57 protected PortletSession session = null;
58
59
60 protected Context context = null;
61 protected PortletGetLocaleCommand command = null;
62
63
64
65
66
67 /***
68 * Set up instance variables required by this test case.
69 */
70 public void setUp() {
71
72 locale = new Locale("en", "US");
73
74
75 pcontext = new MockPortletContext();
76 session = new MockPortletSession(pcontext);
77 request = new MockPortletRequest(null, pcontext, session);
78 ((MockPortletRequest) request).setLocale(locale);
79
80
81 context = new PortletWebContext(pcontext, request, response);
82 command = new PortletGetLocaleCommand();
83
84 }
85
86
87 /***
88 * Return the tests included in this test suite.
89 */
90 public static Test suite() {
91
92 return (new TestSuite(PortletGetLocaleCommandTestCase.class));
93
94 }
95
96
97 /***
98 * Tear down instance variables required by this test case.
99 */
100 public void tearDown() {
101
102 pcontext = null;
103 session = null;
104 request = null;
105 response = null;
106
107 context = null;
108 command = null;
109
110 }
111
112
113
114
115
116
117 public void testConfigured() throws Exception {
118
119 command.setLocaleKey("special");
120 assertEquals("special", command.getLocaleKey());
121 check(context, command);
122
123 }
124
125
126
127 public void testDefaut() throws Exception {
128
129 assertEquals("locale", command.getLocaleKey());
130 check(context, command);
131
132 }
133
134
135
136
137
138 protected void check(Context context, PortletGetLocaleCommand command)
139 throws Exception {
140
141 String localeKey = command.getLocaleKey();
142 assertNotNull(localeKey);
143 Object value = context.get(localeKey);
144 assertNull(value);
145 boolean result = command.execute(context);
146 assertFalse(result);
147 value = context.get(localeKey);
148 assertNotNull(value);
149 assertTrue(value instanceof Locale);
150 assertEquals(locale, (Locale) value);
151
152 }
153
154
155 }