1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.validation.charlevel;
17
18 import org.junit.Test;
19 import org.kuali.rice.kns.datadictionary.validation.charlevel.AlphaNumericValidationPattern;
20 import org.kuali.rice.krad.datadictionary.validation.ValidationTestUtils;
21 import org.kuali.rice.test.BaseRiceTestCase;
22
23
24
25
26
27
28 public class AlphaNumericValidationPatternTest extends BaseRiceTestCase {
29 private AlphaNumericValidationPattern pattern;
30
31 @Override
32 public void setUp() throws Exception {
33 super.setUp();
34 pattern = new AlphaNumericValidationPattern();
35 }
36
37
38
39
40 @Test public final void testMatch_allowDefault() {
41 boolean[] expected = { true,
42 false,
43 false,
44 false,
45 true,
46 false,
47 false,
48 true,
49 false,
50 false,
51 true,
52 false,
53 false,
54 false,
55 false,
56 false,
57 false,
58 };
59
60 ValidationTestUtils.assertPatternMatches(pattern, expected);
61 }
62
63
64
65
66 @Test public final void testMatch_allowUnderscore() {
67 boolean[] expected = { true,
68 false,
69 false,
70 false,
71 true,
72 false,
73 true,
74 true,
75 false,
76 true,
77 true,
78 true,
79 false,
80 false,
81 false,
82 false,
83 false,
84 };
85
86 pattern.setAllowUnderscore(true);
87 ValidationTestUtils.assertPatternMatches(pattern, expected);
88 }
89
90
91
92
93 @Test public final void testMatch_allowWhitespace() {
94 boolean[] expected = { true,
95 false,
96 false,
97 false,
98 true,
99 true,
100 false,
101 true,
102 true,
103 false,
104 true,
105 false,
106 true,
107 false,
108 false,
109 false,
110 false,
111 };
112
113 pattern.setAllowWhitespace(true);
114 ValidationTestUtils.assertPatternMatches(pattern, expected);
115 }
116
117
118
119
120 @Test public final void testMatch_allowUnderScoreAndWhiteSpace() {
121 boolean[] expected = { true,
122 false,
123 false,
124 false,
125 true,
126 true,
127 true,
128 true,
129 true,
130 true,
131 true,
132 true,
133 true,
134 true,
135 false,
136 false,
137 false,
138 };
139
140 pattern.setAllowUnderscore(true);
141 pattern.setAllowWhitespace(true);
142
143 ValidationTestUtils.assertPatternMatches(pattern, expected);
144 }
145
146
147
148
149 @Test public final void testMatch_allowPeriod() {
150 boolean[] expected = { true,
151 false,
152 false,
153 false,
154 true,
155 false,
156 false,
157 true,
158 false,
159 false,
160 true,
161 false,
162 false,
163 false,
164 true,
165 false,
166 false,
167 };
168
169 pattern.setAllowPeriod(true);
170
171 ValidationTestUtils.assertPatternMatches(pattern, expected);
172 }
173
174
175
176
177 @Test public final void testMatch_allowPeriodAndUnderscore() {
178 boolean[] expected = { true,
179 false,
180 false,
181 false,
182 true,
183 false,
184 true,
185 true,
186 false,
187 true,
188 true,
189 true,
190 false,
191 false,
192 true,
193 true,
194 false,
195 };
196
197 pattern.setAllowPeriod(true);
198 pattern.setAllowUnderscore(true);
199
200 ValidationTestUtils.assertPatternMatches(pattern, expected);
201 }
202
203
204
205
206 @Test public final void testMatch_allowPeriodAndUnderscoreAndSpace() {
207 boolean[] expected = { true,
208 false,
209 false,
210 false,
211 true,
212 true,
213 true,
214 true,
215 true,
216 true,
217 true,
218 true,
219 true,
220 true,
221 true,
222 true,
223 true,
224 };
225
226 pattern.setAllowPeriod(true);
227 pattern.setAllowUnderscore(true);
228 pattern.setAllowWhitespace(true);
229
230 ValidationTestUtils.assertPatternMatches(pattern, expected);
231 }
232 }