2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.validator.validator;
19
20 import java.util.Locale;
21 import java.util.ResourceBundle;
22
23 import javax.servlet.ServletContextEvent;
24
25 import org.apache.commons.validator.ValidatorAction;
26 import org.apache.commons.validator.ValidatorResources;
27 import org.apache.shale.test.base.AbstractJsfTestCase;
28 import org.apache.shale.validator.faces.ValidatorLifecycleListener;
29 import org.apache.shale.validator.util.AbstractUtilities;
30 import org.apache.shale.validator.util.ShaleValidatorAction;
31
32 /***
33 * <p>Test case for the utility methods provided by
34 * <code>AbstractValidator</code>. The protected <code>validate()</code>
35 * method is not tested here, as it is presumed that this will be exercised
36 * repeatedly by the test cases for the various concrete validators.</p>
37 */
38 public class AbstractValidatorTestCase extends AbstractJsfTestCase {
39
40
41
42
43
44
45 public AbstractValidatorTestCase(String name) {
46 super(name);
47 }
48
49
50
51
52
53
54 protected void setUp() throws Exception {
55
56 super.setUp();
57 application.setMessageBundle("org.apache.shale.validator.TestBundle");
58 facesContext.getViewRoot().setLocale(Locale.US);
59
60 listener = new ValidatorLifecycleListener();
61 listener.contextInitialized(new ServletContextEvent(servletContext));
62
63 validator = new ConcreteValidator();
64
65 }
66
67
68
69 protected void tearDown() throws Exception {
70
71 validator = null;
72
73 listener.contextDestroyed(new ServletContextEvent(servletContext));
74 listener = null;
75
76 super.tearDown();
77
78 }
79
80
81
82
83
84 /***
85 * <p>Default resource bundle for error message lookup
86 */
87 protected static final ResourceBundle defaultBundle =
88 ResourceBundle.getBundle(AbstractUtilities.DEFAULT_RESOURCE_BUNDLE, Locale.US);
89
90
91
92
93
94 /***
95 * <p>ValidatorLifecycleListener used to load configuration resources</p>
96 */
97 protected ValidatorLifecycleListener listener = null;
98
99
100 /***
101 * <p>Validator instance under test.</p>
102 */
103 protected ConcreteValidator validator = null;
104
105
106
107
108
109
110 public void testActions() {
111
112 ShaleValidatorAction actions[] = null;
113
114 actions = validator.actions(facesContext, "double");
115 assertNotNull(actions);
116 assertEquals(1, actions.length);
117
118 actions = validator.actions(facesContext, "doubleRange");
119 assertNotNull(actions);
120 assertEquals(2, actions.length);
121
122 actions = validator.actions(facesContext, "intRange");
123 assertNotNull(actions);
124 assertEquals(2, actions.length);
125 assertEquals("integer", actions[0].getAction().getName());
126 assertEquals("intRange", actions[1].getAction().getName());
127
128 actions = validator.actions(facesContext, "???undefined???");
129 assertNull(actions);
130
131 }
132
133
134
135 public void testConvert() {
136
137 ;
138
139 }
140
141
142
143 public void testMessage() {
144
145 String message = null;
146
147
148 message = validator.message(facesContext, "errors.long");
149 assertNotNull(message);
150 assertEquals("Custom Long Error Message", message);
151
152
153 message = validator.message(facesContext, "errors.integer");
154 assertNotNull(message);
155 assertEquals(defaultBundle.getString("errors.integer"), message);
156
157
158 message = validator.message(facesContext, "???undefined???");
159 assertNull(message);
160
161 }
162
163
164
165 public void testResources() {
166
167 ValidatorAction action = null;
168
169 ValidatorResources resources = validator.resources(facesContext);
170 assertNotNull(resources);
171
172 action = resources.getValidatorAction("integer");
173 assertNotNull(action);
174
175 action = resources.getValidatorAction("intRange");
176 assertNotNull(action);
177
178 action = resources.getValidatorAction("???undefined");
179 assertNull(action);
180
181 }
182
183
184 }