View Javadoc
1   /**
2    * Copyright 2005-2014 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.UTF8AnyCharacterValidationPattern;
20  import org.kuali.rice.krad.datadictionary.validation.UTF8ValidationTestUtils;
21  import org.kuali.rice.test.BaseRiceTestCase;
22  
23  /**
24   * UTF8AnyCharacterValidationPatternTest tests {@link UTF8AnyCharacterValidationPattern}
25   *
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class UTF8AnyCharacterValidationPatternTest extends BaseRiceTestCase {
29      private UTF8AnyCharacterValidationPattern pattern;
30  
31      @Override
32      public void setUp() throws Exception {
33          super.setUp();
34  
35          pattern = new UTF8AnyCharacterValidationPattern();
36      }
37  
38      @Test public final void testMatch_allUTF8ExceptWhiteSpace() {
39          boolean[] expected = { true, // ""
40                  true, // "!!!"
41                  true, // "[a-9]"
42                  true, // "^A-Z"
43                  true, // "abc"
44                  false, // "12a 3bc"
45                  true, // "12a_3bc"
46                  true, // "123"
47                  false, // "12 3"
48                  true, // "12_3"
49                  true, // "a1b2c3"
50                  true, // "a1b2_c3"
51                  false, // "a 1b2c3"
52                  false, // "a 1b2_c3"
53                  true, //"foo.bar"
54                  true, //"foo.bar_baz"
55                  false, //".bar_foo baz"
56                  true, //"!\"#abs$%&'()*+,./:;<=abs>?@\\^_abs`{|}~-"
57                  true,
58                  false, //"\t"
59                  false,
60                  
61          };
62          
63          UTF8ValidationTestUtils.assertPatternMatches(pattern, expected);
64      }
65      
66      @Test public final void testMatch_allowALLUTF8() {
67          boolean[] expected = { true, // ""
68                  true, // "!!!"
69                  true, // "[a-9]"
70                  true, // "^A-Z"
71                  true, // "abc"
72                  true, // "a bc"
73                  true, // "a_bc"
74                  true, // "123"
75                  true, // "12 3"
76                  true, // "12_3"
77                  true, // "a1b2c3"
78                  true, // "a1b2_c3"
79                  true, // "a 1b2c3"
80                  true, // "a 1b2_c3"
81                  true, //"foo.bar"
82                  true, //"foo.bar_baz"
83                  true, //".bar_foo baz"
84                  true, //"!\"#abs$%&'()*+,./:;<=abs>?@\\^_abs`{|}~-"
85                  true,
86                  true, //"\t"
87                  true, 
88          };
89          
90          pattern.setAllowWhitespace(true);
91          UTF8ValidationTestUtils.assertPatternMatches(pattern, expected);
92      }
93  }