View Javadoc

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.AlphaValidationPattern;
20  import org.kuali.rice.krad.datadictionary.validation.ValidationTestUtils;
21  import org.kuali.rice.test.BaseRiceTestCase;
22  
23  public class AlphaValidationPatternTest extends BaseRiceTestCase {
24      private AlphaValidationPattern pattern;
25  
26      @Override
27      public void setUp() throws Exception {
28          super.setUp();
29          pattern = new AlphaValidationPattern();
30      }
31  
32  
33      @Test public final void testMatch_allowDefault() {
34          boolean[] expected = { true, // ""
35                  false, // "!!!"
36                  false, // "[a-9]"
37                  false, // "^A-Z"
38                  true, // "abc"
39                  false, // "a bc"
40                  false, // "a_bc"
41                  false, // "123"
42                  false, // "12 3"
43                  false, // "12_3"
44                  false, // "a1b2c3"
45                  false, // "a1b2_c3"
46                  false, // "a 1b2c3"
47                  false, // "a 1b2_c3"
48                  false, //"foo.bar"
49                  false, //"foo.bar_baz"
50                  false, //".bar_foo baz"
51          };
52  
53          ValidationTestUtils.assertPatternMatches(pattern, expected);
54      }
55  
56      @Test public final void testMatch_allowWhitespace() {
57          boolean[] expected = { true, // ""
58                  false, // "!!!"
59                  false, // "[a-9]"
60                  false, // "^A-Z"
61                  true, // "abc"
62                  true, // "a bc"
63                  false, // "a_bc"
64                  false, // "123"
65                  false, // "12 3"
66                  false, // "12_3"
67                  false, // "a1b2c3"
68                  false, // "a1b2_c3"
69                  false, // "a 1b2c3"
70                  false, // "a 1b2_c3"
71                  false, //"foo.bar"
72                  false, //"foo.bar_baz"
73                  false, //".bar_foo baz"
74          };
75  
76          pattern.setAllowWhitespace(true);
77          ValidationTestUtils.assertPatternMatches(pattern, expected);
78      }
79  
80  }