View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.datadictionary.validation.charlevel;
17  
18  import org.junit.Test;
19  import org.kuali.rice.kns.datadictionary.validation.charlevel.RegexValidationPattern;
20  import org.kuali.rice.test.BaseRiceTestCase;
21  
22  import static org.junit.Assert.assertFalse;
23  import static org.junit.Assert.assertTrue;
24  
25  /**
26   * This is a description of what this class does - ctdang don't forget to fill this in. 
27   * 
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   *
30   */
31  public class RegexValidationPatternTest extends BaseRiceTestCase {
32      private RegexValidationPattern regexValidationPattern;
33  
34      public void setUp() throws Exception {      
35          regexValidationPattern=new RegexValidationPattern();
36      }
37      
38      @Test public final void testNumericPattern() {
39          regexValidationPattern.setPattern("[0-9]");
40          
41          assertTrue(regexValidationPattern.matches("123456789"));
42          assertFalse(regexValidationPattern.matches("abc"));
43      }
44  
45      @Test public final void testAlphaPattern() {
46          regexValidationPattern.setPattern("[a-zA-Z]");
47          
48          assertTrue(regexValidationPattern.matches("abc"));
49          assertFalse(regexValidationPattern.matches("a12345"));
50      }
51  
52      @Test public final void testAlphaNumericPattern() {
53          regexValidationPattern.setPattern("[a-zA-Z0-9]");
54          
55          assertTrue(regexValidationPattern.matches("ab12345c"));
56          assertFalse(regexValidationPattern.matches("a1*234?"));
57      }
58  
59  }