View Javadoc

1   /**
2    * Copyright 2005-2013 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   * RegexValidationPatternTest tests {@link RegexValidationPattern}
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      /**
39       * tests a numeric regex pattern
40       */
41      @Test public final void testNumericPattern() {
42          regexValidationPattern.setPattern("[0-9]");
43          
44          assertTrue(regexValidationPattern.matches("123456789"));
45          assertFalse(regexValidationPattern.matches("abc"));
46      }
47  
48      /**
49       * tests an alphabetic (lowercase and uppercase) pattern
50       */
51      @Test public final void testAlphaPattern() {
52          regexValidationPattern.setPattern("[a-zA-Z]");
53          
54          assertTrue(regexValidationPattern.matches("abc"));
55          assertFalse(regexValidationPattern.matches("a12345"));
56      }
57  
58      /**
59       * tests an alphanumeric regex pattern
60       */
61      @Test public final void testAlphaNumericPattern() {
62          regexValidationPattern.setPattern("[a-zA-Z0-9]");
63          
64          assertTrue(regexValidationPattern.matches("ab12345c"));
65          assertFalse(regexValidationPattern.matches("a1*234?"));
66      }
67  
68  }