001    /**
002     * Copyright 2005-2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krad.datadictionary.validation.charlevel;
017    
018    import org.junit.Test;
019    import org.kuali.rice.kns.datadictionary.validation.charlevel.UTF8AnyCharacterValidationPattern;
020    import org.kuali.rice.krad.datadictionary.validation.UTF8ValidationTestUtils;
021    import org.kuali.rice.test.BaseRiceTestCase;
022    
023    /**
024     * UTF8AnyCharacterValidationPatternTest tests {@link UTF8AnyCharacterValidationPattern}
025     *
026     * @author Kuali Rice Team (rice.collab@kuali.org)
027     */
028    public class UTF8AnyCharacterValidationPatternTest extends BaseRiceTestCase {
029        private UTF8AnyCharacterValidationPattern pattern;
030    
031        @Override
032        public void setUp() throws Exception {
033            super.setUp();
034    
035            pattern = new UTF8AnyCharacterValidationPattern();
036        }
037    
038        @Test public final void testMatch_allUTF8ExceptWhiteSpace() {
039            boolean[] expected = { true, // ""
040                    true, // "!!!"
041                    true, // "[a-9]"
042                    true, // "^A-Z"
043                    true, // "abc"
044                    false, // "12a 3bc"
045                    true, // "12a_3bc"
046                    true, // "123"
047                    false, // "12 3"
048                    true, // "12_3"
049                    true, // "a1b2c3"
050                    true, // "a1b2_c3"
051                    false, // "a 1b2c3"
052                    false, // "a 1b2_c3"
053                    true, //"foo.bar"
054                    true, //"foo.bar_baz"
055                    false, //".bar_foo baz"
056                    true, //"!\"#abs$%&'()*+,./:;<=abs>?@\\^_abs`{|}~-"
057                    true,
058                    false, //"\t"
059                    false,
060                    
061            };
062            
063            UTF8ValidationTestUtils.assertPatternMatches(pattern, expected);
064        }
065        
066        @Test public final void testMatch_allowALLUTF8() {
067            boolean[] expected = { true, // ""
068                    true, // "!!!"
069                    true, // "[a-9]"
070                    true, // "^A-Z"
071                    true, // "abc"
072                    true, // "a bc"
073                    true, // "a_bc"
074                    true, // "123"
075                    true, // "12 3"
076                    true, // "12_3"
077                    true, // "a1b2c3"
078                    true, // "a1b2_c3"
079                    true, // "a 1b2c3"
080                    true, // "a 1b2_c3"
081                    true, //"foo.bar"
082                    true, //"foo.bar_baz"
083                    true, //".bar_foo baz"
084                    true, //"!\"#abs$%&'()*+,./:;<=abs>?@\\^_abs`{|}~-"
085                    true,
086                    true, //"\t"
087                    true, 
088            };
089            
090            pattern.setAllowWhitespace(true);
091            UTF8ValidationTestUtils.assertPatternMatches(pattern, expected);
092        }
093    }