001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.core.datadictionary.validation.charlevel;
017:
018: import org.junit.Test;
019: import org.kuali.core.datadictionary.validation.ValidationTestUtils;
020: import org.kuali.test.KNSTestBase;
021:
022: public class AlphaNumericValidationPatternTest extends KNSTestBase {
023: private AlphaNumericValidationPattern pattern;
024:
025: @Override
026: public void setUp() throws Exception {
027: super .setUp();
028: pattern = new AlphaNumericValidationPattern();
029: }
030:
031: @Test
032: public final void testMatch_allowDefault() {
033: boolean[] expected = { true, // ""
034: false, // "!!!"
035: false, // "[a-9]"
036: false, // "^A-Z"
037: true, // "abc"
038: false, // "a bc"
039: false, // "a_bc"
040: true, // "123"
041: false, // "12 3"
042: false, // "12_3"
043: true, // "a1b2c3"
044: false, // "a1b2_c3"
045: false, // "a 1b2c3"
046: false, // "a 1b2_c3"
047: };
048:
049: ValidationTestUtils.assertPatternMatches(pattern, expected);
050: }
051:
052: @Test
053: public final void testMatch_allowUnderscore() {
054: boolean[] expected = { true, // ""
055: false, // "!!!"
056: false, // "[a-9]"
057: false, // "^A-Z"
058: true, // "abc"
059: false, // "a bc"
060: true, // "a_bc"
061: true, // "123"
062: false, // "12 3"
063: true, // "12_3"
064: true, // "a1b2c3"
065: true, // "a1b2_c3"
066: false, // "a 1b2c3"
067: false, // "a 1b2_c3"
068: };
069:
070: pattern.setAllowUnderscore(true);
071: ValidationTestUtils.assertPatternMatches(pattern, expected);
072: }
073:
074: @Test
075: public final void testMatch_allowWhitespace() {
076: boolean[] expected = { true, // ""
077: false, // "!!!"
078: false, // "[a-9]"
079: false, // "^A-Z"
080: true, // "abc"
081: true, // "a bc"
082: false, // "a_bc"
083: true, // "123"
084: true, // "12 3"
085: false, // "12_3"
086: true, // "a1b2c3"
087: false, // "a1b2_c3"
088: true, // "a 1b2c3"
089: false, // "a 1b2_c3"
090: };
091:
092: pattern.setAllowWhitespace(true);
093: ValidationTestUtils.assertPatternMatches(pattern, expected);
094: }
095:
096: @Test
097: public final void testMatch_allowBoth() {
098: boolean[] expected = { true, // ""
099: false, // "!!!"
100: false, // "[a-9]"
101: false, // "^A-Z"
102: true, // "abc"
103: true, // "a bc"
104: true, // "a_bc"
105: true, // "123"
106: true, // "12 3"
107: true, // "12_3"
108: true, // "a1b2c3"
109: true, // "a1b2_c3"
110: true, // "a 1b2c3"
111: true, // "a 1b2_c3"
112: };
113:
114: pattern.setAllowUnderscore(true);
115: pattern.setAllowWhitespace(true);
116:
117: ValidationTestUtils.assertPatternMatches(pattern, expected);
118: }
119: }
|