View Javadoc

1   /**
2    * Copyright 2004-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.hr.time.clock.location.validation;
17  
18  import org.junit.Assert;
19  import org.junit.Test;
20  
21  public class ClockLocationRuleRuleTest extends Assert {
22  
23      static String[] validIpAddresses;
24      static String[] invalidIpAddresses;
25  
26      static {
27  	validIpAddresses = new String[] {
28  		"1.1.1.1",
29  		"%.2.3.4",
30  		"1.%.3.4",
31  		"1.2.%.4",
32  		"1.2.3.%",
33  		"%.%.3.4",
34  		"1.%.%.4",
35  		"1.2.%.%",
36  		"%.%.%.4",
37  		"1.%.%.%",
38  		"255.255.255.255",
39  		"%.%.%.%",
40  		"1.2.%",
41  		"%",
42  		"127.%"
43  	};
44  
45  	invalidIpAddresses = new String[] {
46  		"-1.0.0.0",
47  		"1.2.3.256",
48  		"256.2.3.1",
49  		"1.2.3",
50  		"random text",
51  		" 1.2.3.4 ",
52  		"1.2.3.4.5",
53  		"%1.2.3.4%",      // TODO: We may want this to be valid.
54  		"999.999.999.999",
55  		"",
56  		".123.2.4"
57  	};
58      }
59  
60      @Test
61      public void testValidateIpAddress() throws Exception {
62  	ClockLocationRuleRule clrr = new ClockLocationRuleRule();
63  
64  	for (String ip : validIpAddresses) {
65  	    assertTrue("IP address " + ip + " should be valid.", clrr.validateIpAddress(ip));
66  	}
67  
68  	for (String ip : invalidIpAddresses) {
69  	    assertFalse("IP address " + ip + " should be invalid.", clrr.validateIpAddress(ip));
70  	}
71      }
72  }