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 public class AlphaNumericValidationPatternTest extends BaseRiceTestCase {
24 private AlphaNumericValidationPattern pattern;
25
26 @Override
27 public void setUp() throws Exception {
28 super.setUp();
29 pattern = new AlphaNumericValidationPattern();
30 }
31
32
33 @Test public final void testMatch_allowDefault() {
34 boolean[] expected = { true,
35 false,
36 false,
37 false,
38 true,
39 false,
40 false,
41 true,
42 false,
43 false,
44 true,
45 false,
46 false,
47 false,
48 false,
49 false,
50 false,
51 };
52
53 ValidationTestUtils.assertPatternMatches(pattern, expected);
54 }
55
56 @Test public final void testMatch_allowUnderscore() {
57 boolean[] expected = { true,
58 false,
59 false,
60 false,
61 true,
62 false,
63 true,
64 true,
65 false,
66 true,
67 true,
68 true,
69 false,
70 false,
71 false,
72 false,
73 false,
74 };
75
76 pattern.setAllowUnderscore(true);
77 ValidationTestUtils.assertPatternMatches(pattern, expected);
78 }
79
80 @Test public final void testMatch_allowWhitespace() {
81 boolean[] expected = { true,
82 false,
83 false,
84 false,
85 true,
86 true,
87 false,
88 true,
89 true,
90 false,
91 true,
92 false,
93 true,
94 false,
95 false,
96 false,
97 false,
98 };
99
100 pattern.setAllowWhitespace(true);
101 ValidationTestUtils.assertPatternMatches(pattern, expected);
102 }
103
104 @Test public final void testMatch_allowUnderScoreAndWhiteSpace() {
105 boolean[] expected = { true,
106 false,
107 false,
108 false,
109 true,
110 true,
111 true,
112 true,
113 true,
114 true,
115 true,
116 true,
117 true,
118 true,
119 false,
120 false,
121 false,
122 };
123
124 pattern.setAllowUnderscore(true);
125 pattern.setAllowWhitespace(true);
126
127 ValidationTestUtils.assertPatternMatches(pattern, expected);
128 }
129
130 @Test public final void testMatch_allowPeriod() {
131 boolean[] expected = { true,
132 false,
133 false,
134 false,
135 true,
136 false,
137 false,
138 true,
139 false,
140 false,
141 true,
142 false,
143 false,
144 false,
145 true,
146 false,
147 false,
148 };
149
150 pattern.setAllowPeriod(true);
151
152 ValidationTestUtils.assertPatternMatches(pattern, expected);
153 }
154
155 @Test public final void testMatch_allowPeriodAndUnderscore() {
156 boolean[] expected = { true,
157 false,
158 false,
159 false,
160 true,
161 false,
162 true,
163 true,
164 false,
165 true,
166 true,
167 true,
168 false,
169 false,
170 true,
171 true,
172 false,
173 };
174
175 pattern.setAllowPeriod(true);
176 pattern.setAllowUnderscore(true);
177
178 ValidationTestUtils.assertPatternMatches(pattern, expected);
179 }
180
181 @Test public final void testMatch_allowPeriodAndUnderscoreAndSpace() {
182 boolean[] expected = { true,
183 false,
184 false,
185 false,
186 true,
187 true,
188 true,
189 true,
190 true,
191 true,
192 true,
193 true,
194 true,
195 true,
196 true,
197 true,
198 true,
199 };
200
201 pattern.setAllowPeriod(true);
202 pattern.setAllowUnderscore(true);
203 pattern.setAllowWhitespace(true);
204
205 ValidationTestUtils.assertPatternMatches(pattern, expected);
206 }
207 }