KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > util > LocalhostTest


1 /*
2  * LocalhostTest.java
3  * JUnit based test
4  *
5  * Created on August 18, 2005, 9:13 AM
6  */

7
8 package org.sapia.ubik.util;
9
10 import java.util.regex.Pattern JavaDoc;
11 import junit.framework.TestCase;
12 import org.sapia.ubik.rmi.Consts;
13
14 /**
15  *
16  * @author yduchesne
17  */

18 public class LocalhostTest extends TestCase {
19   
20   public LocalhostTest(String JavaDoc testName) {
21     super(testName);
22   }
23
24   /**
25    * Test of getLocalAddress method, of class org.sapia.ubik.util.Localhost.
26    */

27   public void testGetLocalAddress() throws Exception JavaDoc{
28     String JavaDoc addr = Localhost.getLocalAddress().getHostAddress();
29     super.assertTrue(!addr.equals("localhost"));
30     super.assertTrue(!addr.equals("127.0.0.1"));
31     super.assertTrue(!addr.equals("0.0.0.0"));
32   }
33   
34   public void testIsLocalAddress(){
35     Pattern JavaDoc p = Pattern.compile("\\d{3}\\.\\d{3}\\.\\d+\\.\\d+");
36     super.assertTrue(!Localhost.isLocalAddress(p, "127.0.0.1"));
37     super.assertTrue(!Localhost.isLocalAddress(p, "10.10.10.1"));
38     super.assertTrue(!Localhost.isLocalAddress(p, "localhost"));
39     super.assertTrue(Localhost.isLocalAddress(p, "192.168.0.10"));
40   }
41
42   
43 }
44
Popular Tags