001/**
002 * Copyright 2005-2013 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.AnyCharacterValidationPattern;
020import org.kuali.rice.krad.datadictionary.validation.ValidationTestUtils;
021import org.kuali.rice.test.BaseRiceTestCase;
022
023/**
024 *  AnyCharacterValidationPatternTest tests {@link AnyCharacterValidationPattern}
025 *
026 *  @author Kuali Rice Team (rice.collab@kuali.org)
027 */
028public class AnyCharacterValidationPatternTest extends BaseRiceTestCase {
029    private AnyCharacterValidationPattern pattern;
030
031    @Override
032    public void setUp() throws Exception {
033        super.setUp();
034
035        pattern = new AnyCharacterValidationPattern();
036    }
037
038    /**
039     * tests that any sequence not containing white space matches
040     */
041    @Test public final void testMatch_allowDefault() {
042        boolean[] expected = { true, // ""
043                true, // "!!!"
044                true, // "[a-9]"
045                true, // "^A-Z"
046                true, // "abc"
047                false, // "a bc"
048                true, // "a_bc"
049                true, // "123"
050                false, // "12 3"
051                true, // "12_3"
052                true, // "a1b2c3"
053                true, // "a1b2_c3"
054                false, // "a 1b2c3"
055                false, // "a 1b2_c3"
056                true, //"foo.bar"
057                true, //"foo.bar_baz"
058                false, //".bar_foo baz"
059        };
060
061        ValidationTestUtils.assertPatternMatches(pattern, expected);
062    }
063
064    /**
065     * tests that sequences containing white space are allowed
066     */
067    @Test public final void testMatch_allowWhitespace() {
068        boolean[] expected = { true, // ""
069                true, // "!!!"
070                true, // "[a-9]"
071                true, // "^A-Z"
072                true, // "abc"
073                true, // "a bc"
074                true, // "a_bc"
075                true, // "123"
076                true, // "12 3"
077                true, // "12_3"
078                true, // "a1b2c3"
079                true, // "a1b2_c3"
080                true, // "a 1b2c3"
081                true, // "a 1b2_c3"
082                true, //"foo.bar"
083                true, //"foo.bar_baz"
084                true, //".bar_foo baz"
085        };
086
087        pattern.setAllowWhitespace(true);
088        ValidationTestUtils.assertPatternMatches(pattern, expected);
089    }
090}