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