001 /** 002 * Copyright 2004-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.clock.location.validation; 017 018 import org.junit.Assert; 019 import org.junit.Test; 020 021 public class ClockLocationRuleRuleTest extends Assert { 022 023 static String[] validIpAddresses; 024 static String[] invalidIpAddresses; 025 026 static { 027 validIpAddresses = new String[] { 028 "1.1.1.1", 029 "%.2.3.4", 030 "1.%.3.4", 031 "1.2.%.4", 032 "1.2.3.%", 033 "%.%.3.4", 034 "1.%.%.4", 035 "1.2.%.%", 036 "%.%.%.4", 037 "1.%.%.%", 038 "255.255.255.255", 039 "%.%.%.%", 040 "1.2.%", 041 "%", 042 "127.%" 043 }; 044 045 invalidIpAddresses = new String[] { 046 "-1.0.0.0", 047 "1.2.3.256", 048 "256.2.3.1", 049 "1.2.3", 050 "random text", 051 " 1.2.3.4 ", 052 "1.2.3.4.5", 053 "%1.2.3.4%", // TODO: We may want this to be valid. 054 "999.999.999.999", 055 "", 056 ".123.2.4" 057 }; 058 } 059 060 @Test 061 public void testValidateIpAddress() throws Exception { 062 ClockLocationRuleRule clrr = new ClockLocationRuleRule(); 063 064 for (String ip : validIpAddresses) { 065 assertTrue("IP address " + ip + " should be valid.", clrr.validateIpAddress(ip)); 066 } 067 068 for (String ip : invalidIpAddresses) { 069 assertFalse("IP address " + ip + " should be invalid.", clrr.validateIpAddress(ip)); 070 } 071 } 072 }