1
2
3
4
5
6
7
8
9
10
11
12
13
14
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%",
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 }