1 /**
2 * Copyright 2005-2011 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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.AnyCharacterValidationPattern;
20 import org.kuali.rice.krad.datadictionary.validation.ValidationTestUtils;
21 import org.kuali.rice.test.BaseRiceTestCase;
22
23 /**
24 * AnyCharacterValidationPatternTest tests {@link AnyCharacterValidationPattern}
25 *
26 * @author Kuali Rice Team (rice.collab@kuali.org)
27 */
28 public class AnyCharacterValidationPatternTest extends BaseRiceTestCase {
29 private AnyCharacterValidationPattern pattern;
30
31 @Override
32 public void setUp() throws Exception {
33 super.setUp();
34
35 pattern = new AnyCharacterValidationPattern();
36 }
37
38 /**
39 * tests that any sequence not containing white space matches
40 */
41 @Test public final void testMatch_allowDefault() {
42 boolean[] expected = { true, // ""
43 true, // "!!!"
44 true, // "[a-9]"
45 true, // "^A-Z"
46 true, // "abc"
47 false, // "a bc"
48 true, // "a_bc"
49 true, // "123"
50 false, // "12 3"
51 true, // "12_3"
52 true, // "a1b2c3"
53 true, // "a1b2_c3"
54 false, // "a 1b2c3"
55 false, // "a 1b2_c3"
56 true, //"foo.bar"
57 true, //"foo.bar_baz"
58 false, //".bar_foo baz"
59 };
60
61 ValidationTestUtils.assertPatternMatches(pattern, expected);
62 }
63
64 /**
65 * tests that sequences containing white space are allowed
66 */
67 @Test public final void testMatch_allowWhitespace() {
68 boolean[] expected = { true, // ""
69 true, // "!!!"
70 true, // "[a-9]"
71 true, // "^A-Z"
72 true, // "abc"
73 true, // "a bc"
74 true, // "a_bc"
75 true, // "123"
76 true, // "12 3"
77 true, // "12_3"
78 true, // "a1b2c3"
79 true, // "a1b2_c3"
80 true, // "a 1b2c3"
81 true, // "a 1b2_c3"
82 true, //"foo.bar"
83 true, //"foo.bar_baz"
84 true, //".bar_foo baz"
85 };
86
87 pattern.setAllowWhitespace(true);
88 ValidationTestUtils.assertPatternMatches(pattern, expected);
89 }
90 }