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 * This is a description of what this class does - ctdang don't forget to fill this in. 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 @Test public final void testNumericPattern() { 039 regexValidationPattern.setPattern("[0-9]"); 040 041 assertTrue(regexValidationPattern.matches("123456789")); 042 assertFalse(regexValidationPattern.matches("abc")); 043 } 044 045 @Test public final void testAlphaPattern() { 046 regexValidationPattern.setPattern("[a-zA-Z]"); 047 048 assertTrue(regexValidationPattern.matches("abc")); 049 assertFalse(regexValidationPattern.matches("a12345")); 050 } 051 052 @Test public final void testAlphaNumericPattern() { 053 regexValidationPattern.setPattern("[a-zA-Z0-9]"); 054 055 assertTrue(regexValidationPattern.matches("ab12345c")); 056 assertFalse(regexValidationPattern.matches("a1*234?")); 057 } 058 059 }