View Javadoc

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