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