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.RegexValidationPattern;
020 import org.kuali.rice.test.BaseRiceTestCase;
021
022 import static org.junit.Assert.assertFalse;
023 import static org.junit.Assert.assertTrue;
024
025 /**
026 * RegexValidationPatternTest tests {@link RegexValidationPattern}
027 *
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 *
030 */
031 public class RegexValidationPatternTest extends BaseRiceTestCase {
032 private RegexValidationPattern regexValidationPattern;
033
034 public void setUp() throws Exception {
035 regexValidationPattern=new RegexValidationPattern();
036 }
037
038 /**
039 * tests a numeric regex pattern
040 */
041 @Test public final void testNumericPattern() {
042 regexValidationPattern.setPattern("[0-9]");
043
044 assertTrue(regexValidationPattern.matches("123456789"));
045 assertFalse(regexValidationPattern.matches("abc"));
046 }
047
048 /**
049 * tests an alphabetic (lowercase and uppercase) pattern
050 */
051 @Test public final void testAlphaPattern() {
052 regexValidationPattern.setPattern("[a-zA-Z]");
053
054 assertTrue(regexValidationPattern.matches("abc"));
055 assertFalse(regexValidationPattern.matches("a12345"));
056 }
057
058 /**
059 * tests an alphanumeric regex pattern
060 */
061 @Test public final void testAlphaNumericPattern() {
062 regexValidationPattern.setPattern("[a-zA-Z0-9]");
063
064 assertTrue(regexValidationPattern.matches("ab12345c"));
065 assertFalse(regexValidationPattern.matches("a1*234?"));
066 }
067
068 }