001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.datadictionary.validation.charlevel;
017:
018: import org.junit.Test;
019: import org.kuali.test.KNSTestBase;
020:
021: public class CharsetValidationPatternTest extends KNSTestBase {
022: private CharsetValidationPattern charsetPattern;
023:
024: @Override
025: public void setUp() throws Exception {
026: super .setUp();
027:
028: charsetPattern = new CharsetValidationPattern();
029: }
030:
031: @Test
032: public final void testSetBoth_AB() {
033: boolean failedAsExpected = false;
034:
035: try {
036: charsetPattern.setMaxLength(5);
037: charsetPattern.setExactLength(5);
038: } catch (IllegalStateException e) {
039: failedAsExpected = true;
040: }
041:
042: assertTrue(failedAsExpected);
043: }
044:
045: @Test
046: public final void testSetBoth_BA() {
047: boolean failedAsExpected = false;
048:
049: try {
050: charsetPattern.setExactLength(5);
051: charsetPattern.setMaxLength(5);
052: } catch (IllegalStateException e) {
053: failedAsExpected = true;
054: }
055:
056: assertTrue(failedAsExpected);
057: }
058:
059: @Test
060: public final void testMatch_exactLength1() {
061: charsetPattern.setExactLength(3);
062: charsetPattern.setValidChars("abc");
063:
064: assertFalse(charsetPattern.matches("aaaa"));
065: }
066:
067: @Test
068: public final void testMatch_exactLength2() {
069: charsetPattern.setExactLength(3);
070: charsetPattern.setValidChars("abc");
071:
072: assertFalse(charsetPattern.matches("aa"));
073: }
074:
075: @Test
076: public final void testMatch_exactLength3() {
077: charsetPattern.setExactLength(3);
078: charsetPattern.setValidChars("abc");
079:
080: assertTrue(charsetPattern.matches("aaa"));
081: }
082:
083: @Test
084: public final void testMatch_maxLength1() {
085: charsetPattern.setMaxLength(3);
086: charsetPattern.setValidChars("abc");
087:
088: assertFalse(charsetPattern.matches("aaaa"));
089: }
090:
091: @Test
092: public final void testMatch_maxLength2() {
093: charsetPattern.setMaxLength(3);
094: charsetPattern.setValidChars("abc");
095:
096: assertTrue(charsetPattern.matches("aa"));
097: }
098:
099: @Test
100: public final void testMatch_maxLength3() {
101: charsetPattern.setMaxLength(3);
102: charsetPattern.setValidChars("abc");
103:
104: assertTrue(charsetPattern.matches("aaa"));
105: }
106:
107: @Test
108: public final void testSetValidChars_emptyString() {
109: boolean failedAsExpected = false;
110:
111: try {
112: charsetPattern.setValidChars("");
113: } catch (IllegalArgumentException e) {
114: failedAsExpected = true;
115: }
116:
117: assertTrue(failedAsExpected);
118: }
119:
120: @Test
121: public final void testMatch_trailingSlash1() {
122: charsetPattern.setValidChars("abcd\\");
123:
124: assertTrue(charsetPattern.matches("a"));
125: }
126:
127: @Test
128: public final void testMatch_trailingSlash2() {
129: charsetPattern.setValidChars("abcd\\");
130:
131: assertTrue(charsetPattern.matches("c"));
132: }
133:
134: @Test
135: public final void testMatch_trailingSlash3() {
136: charsetPattern.setValidChars("abcd\\");
137:
138: assertTrue(charsetPattern.matches("\\"));
139: }
140:
141: @Test
142: public final void testMatch_pseudoSet1() {
143: charsetPattern.setValidChars("[A-Z]");
144:
145: assertTrue(charsetPattern.matches("A"));
146: }
147:
148: @Test
149: public final void testMatch_pseudoSet2() {
150: charsetPattern.setValidChars("[A-Z]");
151:
152: assertTrue(charsetPattern.matches("Z"));
153: }
154:
155: @Test
156: public final void testMatch_pseudoSet3() {
157: charsetPattern.setValidChars("[A-Z]");
158:
159: assertTrue(charsetPattern.matches("-"));
160: }
161:
162: @Test
163: public final void testMatch_pseudoSet4() {
164: charsetPattern.setValidChars("[A-Z]");
165:
166: assertTrue(charsetPattern.matches("["));
167: }
168:
169: @Test
170: public final void testMatch_pseudoSet5() {
171: charsetPattern.setValidChars("[A-Z]");
172:
173: assertFalse(charsetPattern.matches("C"));
174: }
175:
176: @Test
177: public final void testMatch_partialPseudoSet1() {
178: charsetPattern.setValidChars("[ABC");
179:
180: assertTrue(charsetPattern.matches("A"));
181: }
182:
183: @Test
184: public final void testMatch_partialPseudoSet2() {
185: charsetPattern.setValidChars("[ABC");
186:
187: assertFalse(charsetPattern.matches("Z"));
188: }
189:
190: @Test
191: public final void testMatch_pseudoSetTrailingSlash1() {
192: charsetPattern.setValidChars("[A-Z]\\");
193:
194: assertTrue(charsetPattern.matches("A"));
195: }
196:
197: @Test
198: public final void testMatch_pseudoSetTrailingSlash2() {
199: charsetPattern.setValidChars("[A-Z]\\");
200:
201: assertTrue(charsetPattern.matches("Z"));
202: }
203:
204: @Test
205: public final void testMatch_pseudoSetTrailingSlash3() {
206: charsetPattern.setValidChars("[A-Z]\\");
207:
208: assertTrue(charsetPattern.matches("-"));
209: }
210:
211: @Test
212: public final void testMatch_pseudoSetTrailingSlash4() {
213: charsetPattern.setValidChars("[A-Z]\\");
214:
215: assertTrue(charsetPattern.matches("["));
216: }
217:
218: @Test
219: public final void testMatch_pseudoSetTrailingSlash5() {
220: charsetPattern.setValidChars("[A-Z]\\");
221:
222: assertFalse(charsetPattern.matches("C"));
223: }
224:
225: @Test
226: public final void testMatch_pseudoCapture1() {
227: charsetPattern.setValidChars("(ABC)");
228:
229: assertTrue(charsetPattern.matches("("));
230: }
231:
232: @Test
233: public final void testMatch_pseudoCapture2() {
234: charsetPattern.setValidChars("(ABC)");
235:
236: assertTrue(charsetPattern.matches(")"));
237: }
238:
239: @Test
240: public final void testMatch_pseudoCapture3() {
241: charsetPattern.setValidChars("(ABC)");
242:
243: assertTrue(charsetPattern.matches("B"));
244: }
245:
246: @Test
247: public final void testMatch_pseudoRange1() {
248: charsetPattern.setValidChars("A-Z");
249:
250: assertTrue(charsetPattern.matches("A"));
251: }
252:
253: @Test
254: public final void testMatch_pseudoRange2() {
255: charsetPattern.setValidChars("A-Z");
256:
257: assertTrue(charsetPattern.matches("-"));
258: }
259:
260: @Test
261: public final void testMatch_pseudoRange3() {
262: charsetPattern.setValidChars("A-Z");
263:
264: assertFalse(charsetPattern.matches("B"));
265: }
266:
267: @Test
268: public final void testMatch_pseudoIntersection1() {
269: charsetPattern.setValidChars("A&&Z");
270:
271: assertTrue(charsetPattern.matches("A"));
272: }
273:
274: @Test
275: public final void testMatch_pseudoIntersection2() {
276: charsetPattern.setValidChars("A&&Z");
277:
278: assertTrue(charsetPattern.matches("&"));
279: }
280:
281: @Test
282: public final void testMatch_pseudoIntersection3() {
283: charsetPattern.setValidChars("A&&Z");
284:
285: assertTrue(charsetPattern.matches("Z"));
286: }
287: }
|