001/**
002 * Copyright 2005-2014 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 */
016package org.kuali.rice.krad.datadictionary.validation.charlevel;
017
018import org.junit.Test;
019import org.kuali.rice.kns.datadictionary.validation.charlevel.AlphaValidationPattern;
020import org.kuali.rice.krad.datadictionary.validation.ValidationTestUtils;
021import org.kuali.rice.test.BaseRiceTestCase;
022
023public class AlphaValidationPatternTest extends BaseRiceTestCase {
024    private AlphaValidationPattern pattern;
025
026    @Override
027    public void setUp() throws Exception {
028        super.setUp();
029        pattern = new AlphaValidationPattern();
030    }
031
032
033    @Test public final void testMatch_allowDefault() {
034        boolean[] expected = { true, // ""
035                false, // "!!!"
036                false, // "[a-9]"
037                false, // "^A-Z"
038                true, // "abc"
039                false, // "a bc"
040                false, // "a_bc"
041                false, // "123"
042                false, // "12 3"
043                false, // "12_3"
044                false, // "a1b2c3"
045                false, // "a1b2_c3"
046                false, // "a 1b2c3"
047                false, // "a 1b2_c3"
048                false, //"foo.bar"
049                false, //"foo.bar_baz"
050                false, //".bar_foo baz"
051        };
052
053        ValidationTestUtils.assertPatternMatches(pattern, expected);
054    }
055
056    @Test public final void testMatch_allowWhitespace() {
057        boolean[] expected = { true, // ""
058                false, // "!!!"
059                false, // "[a-9]"
060                false, // "^A-Z"
061                true, // "abc"
062                true, // "a bc"
063                false, // "a_bc"
064                false, // "123"
065                false, // "12 3"
066                false, // "12_3"
067                false, // "a1b2c3"
068                false, // "a1b2_c3"
069                false, // "a 1b2c3"
070                false, // "a 1b2_c3"
071                false, //"foo.bar"
072                false, //"foo.bar_baz"
073                false, //".bar_foo baz"
074        };
075
076        pattern.setAllowWhitespace(true);
077        ValidationTestUtils.assertPatternMatches(pattern, expected);
078    }
079
080}