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