james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ieu...@apache.org
Subject svn commit: r1299463 - in /james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library: ./ inetnetwork/ inetnetwork/model/ netmatcher/
Date Sun, 11 Mar 2012 22:16:02 GMT
Author: ieugen
Date: Sun Mar 11 22:16:02 2012
New Revision: 1299463

URL: http://svn.apache.org/viewvc?rev=1299463&view=rev
Log:
JAMES-1393

- updated tests to juni 4.x style
- added @Override and reformated code
Issue #JAMES-1393 - Upgrate all test suites to junit 4.10

Modified:
    james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java
    james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/inetnetwork/InetNetworkBuilderTest.java
    james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/inetnetwork/model/InetNetworkTest.java
    james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/netmatcher/NetMatcherTest.java

Modified: james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java?rev=1299463&r1=1299462&r2=1299463&view=diff
==============================================================================
--- james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java
(original)
+++ james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/MXHostAddressIteratorTest.java
Sun Mar 11 22:16:02 2012
@@ -22,100 +22,113 @@ import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.Arrays;
 import java.util.Collection;
-
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.dnsservice.api.TemporaryResolutionException;
+import static org.junit.Assert.*;
+import org.junit.Test;
 import org.slf4j.LoggerFactory;
 
-import junit.framework.TestCase;
-
-public class MXHostAddressIteratorTest extends TestCase{
+public class MXHostAddressIteratorTest {
 
     /**
      * Test case for JAMES-1251
      */
+    @Test
     public void testIteratorContainMultipleMX() {
-        DNSService dns = new DNSService() {
-            
-            public InetAddress getLocalHost() throws UnknownHostException {
-                throw new UnsupportedOperationException();
-            }
-            
-            public String getHostName(InetAddress addr) {
-                throw new UnsupportedOperationException();
-            }
-            
-            public InetAddress getByName(String host) throws UnknownHostException {
-                return InetAddress.getLocalHost();
-            }
-            
-            /**
-             * Every time this method is called it will return two InetAddress instances
-             */
-            public InetAddress[] getAllByName(String host) throws UnknownHostException {
-                InetAddress addr = InetAddress.getLocalHost();
-                return new InetAddress[] {addr, addr};
-            }
-            
-            public Collection<String> findTXTRecords(String hostname) {
-                throw new UnsupportedOperationException();
-            }
-            
-            public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException
{
-                throw new UnsupportedOperationException();
-            }
-        };
-        MXHostAddressIterator it = new MXHostAddressIterator(Arrays.asList("localhost", "localhost2").iterator(),
dns, false, LoggerFactory.getLogger(this.getClass()));
-        for (int i  = 0; i < 4; i++) {
-            assertTrue(it.hasNext());
-            assertNotNull(it.next());
-        }
-        assertFalse(it.hasNext());
-        
-        it = new MXHostAddressIterator(Arrays.asList("localhost", "localhost2").iterator(),
dns, true, LoggerFactory.getLogger(this.getClass()));
-        for (int i  = 0; i < 2; i++) {
-            assertTrue(it.hasNext());
-            assertNotNull(it.next());
-        }
-        assertFalse(it.hasNext());
+	DNSService dns = new DNSService() {
+
+	    @Override
+	    public InetAddress getLocalHost() throws UnknownHostException {
+		throw new UnsupportedOperationException();
+	    }
+
+	    @Override
+	    public String getHostName(InetAddress addr) {
+		throw new UnsupportedOperationException();
+	    }
+
+	    @Override
+	    public InetAddress getByName(String host) throws UnknownHostException {
+		return InetAddress.getLocalHost();
+	    }
+
+	    /**
+	     * Every time this method is called it will return two InetAddress instances
+	     */
+	    @Override
+	    public InetAddress[] getAllByName(String host) throws UnknownHostException {
+		InetAddress addr = InetAddress.getLocalHost();
+		return new InetAddress[]{addr, addr};
+	    }
+
+	    @Override
+	    public Collection<String> findTXTRecords(String hostname) {
+		throw new UnsupportedOperationException();
+	    }
+
+	    @Override
+	    public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException
{
+		throw new UnsupportedOperationException();
+	    }
+	};
+	MXHostAddressIterator it = new MXHostAddressIterator(Arrays.asList("localhost", "localhost2").iterator(),
dns,
+		false, LoggerFactory.getLogger(this.getClass()));
+	for (int i = 0; i < 4; i++) {
+	    assertTrue(it.hasNext());
+	    assertNotNull(it.next());
+	}
+	assertFalse(it.hasNext());
+
+	it = new MXHostAddressIterator(Arrays.asList("localhost", "localhost2").iterator(), dns,
true, LoggerFactory.
+		getLogger(this.getClass()));
+	for (int i = 0; i < 2; i++) {
+	    assertTrue(it.hasNext());
+	    assertNotNull(it.next());
+	}
+	assertFalse(it.hasNext());
     }
-    
-    
+
+    @Test
     public void testIteratorWithInvalidMX() {
-        DNSService dns = new DNSService() {
-            
-            public InetAddress getLocalHost() throws UnknownHostException {
-                throw new UnsupportedOperationException();
-            }
-            
-            public String getHostName(InetAddress addr) {
-                throw new UnsupportedOperationException();
-            }
-            
-            public InetAddress getByName(String host) throws UnknownHostException {
-                throw new UnknownHostException();
-            }
-            
-            /**
-             * Every time this method is called it will return two InetAddress instances
-             */
-            public InetAddress[] getAllByName(String host) throws UnknownHostException {
-                throw new UnknownHostException();
-            }
-            
-            public Collection<String> findTXTRecords(String hostname) {
-                throw new UnsupportedOperationException();
-            }
-            
-            public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException
{
-                throw new UnsupportedOperationException();
-            }
-        };
-        
-        // See JAMES-1271
-        MXHostAddressIterator it = new MXHostAddressIterator(Arrays.asList("localhost").iterator(),
dns, false, LoggerFactory.getLogger(this.getClass()));
-        assertFalse(it.hasNext());
-       
-    }
+	DNSService dns = new DNSService() {
+
+	    @Override
+	    public InetAddress getLocalHost() throws UnknownHostException {
+		throw new UnsupportedOperationException();
+	    }
+
+	    @Override
+	    public String getHostName(InetAddress addr) {
+		throw new UnsupportedOperationException();
+	    }
+
+	    @Override
+	    public InetAddress getByName(String host) throws UnknownHostException {
+		throw new UnknownHostException();
+	    }
 
+	    /**
+	     * Every time this method is called it will return two InetAddress instances
+	     */
+	    @Override
+	    public InetAddress[] getAllByName(String host) throws UnknownHostException {
+		throw new UnknownHostException();
+	    }
+
+	    @Override
+	    public Collection<String> findTXTRecords(String hostname) {
+		throw new UnsupportedOperationException();
+	    }
+
+	    @Override
+	    public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException
{
+		throw new UnsupportedOperationException();
+	    }
+	};
+
+	// See JAMES-1271
+	MXHostAddressIterator it = new MXHostAddressIterator(Arrays.asList("localhost").iterator(),
dns, false,
+		LoggerFactory.getLogger(this.getClass()));
+	assertFalse(it.hasNext());
+    }
 }

Modified: james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/inetnetwork/InetNetworkBuilderTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/inetnetwork/InetNetworkBuilderTest.java?rev=1299463&r1=1299462&r2=1299463&view=diff
==============================================================================
--- james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/inetnetwork/InetNetworkBuilderTest.java
(original)
+++ james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/inetnetwork/InetNetworkBuilderTest.java
Sun Mar 11 22:16:02 2012
@@ -19,17 +19,15 @@
 package org.apache.james.dnsservice.library.inetnetwork;
 
 import java.net.UnknownHostException;
-
-import junit.framework.TestCase;
-
 import org.apache.james.dnsservice.api.mock.DNSFixture;
-import org.apache.james.dnsservice.library.inetnetwork.InetNetworkBuilder;
 import org.apache.james.dnsservice.library.inetnetwork.model.InetNetwork;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
 
 /**
  * Test the InetNetworkBuilder.
  */
-public class InetNetworkBuilderTest extends TestCase {
+public class InetNetworkBuilderTest {
 
     private InetNetworkBuilder inetNetworkBuilder;
     private InetNetwork inetNetwork;
@@ -39,15 +37,16 @@ public class InetNetworkBuilderTest exte
      * 
      * @throws UnknownHostException
      */
+    @Test
     public void testInetNetworkBuilderDnsV4() throws UnknownHostException {
 
-        inetNetworkBuilder = new InetNetworkBuilder(DNSFixture.DNS_SERVER_IPV4_MOCK);
+	inetNetworkBuilder = new InetNetworkBuilder(DNSFixture.DNS_SERVER_IPV4_MOCK);
 
-        inetNetwork = inetNetworkBuilder.getFromString(DNSFixture.LOCALHOST_IP_V4_ADDRESS_0);
-        assertEquals("127.0.0.0/255.255.0.0", inetNetwork.toString());
+	inetNetwork = inetNetworkBuilder.getFromString(DNSFixture.LOCALHOST_IP_V4_ADDRESS_0);
+	assertEquals("127.0.0.0/255.255.0.0", inetNetwork.toString());
 
-        inetNetwork = inetNetworkBuilder.getFromString(DNSFixture.LOCALHOST_IP_V4_ADDRESS_1);
-        assertEquals("172.16.0.0/255.255.0.0", inetNetwork.toString());
+	inetNetwork = inetNetworkBuilder.getFromString(DNSFixture.LOCALHOST_IP_V4_ADDRESS_1);
+	assertEquals("172.16.0.0/255.255.0.0", inetNetwork.toString());
 
     }
 
@@ -56,16 +55,16 @@ public class InetNetworkBuilderTest exte
      * 
      * @throws UnknownHostException
      */
+    @Test
     public void testInetNetworkBuilderDnsV6() throws UnknownHostException {
 
-        inetNetworkBuilder = new InetNetworkBuilder(DNSFixture.DNS_SERVER_IPV6_MOCK);
+	inetNetworkBuilder = new InetNetworkBuilder(DNSFixture.DNS_SERVER_IPV6_MOCK);
 
-        inetNetwork = inetNetworkBuilder.getFromString(DNSFixture.LOCALHOST_IP_V6_ADDRESS_0);
-        assertEquals("0:0:0:0:0:0:0:1/32768", inetNetwork.toString());
+	inetNetwork = inetNetworkBuilder.getFromString(DNSFixture.LOCALHOST_IP_V6_ADDRESS_0);
+	assertEquals("0:0:0:0:0:0:0:1/32768", inetNetwork.toString());
 
-        inetNetwork = inetNetworkBuilder.getFromString(DNSFixture.LOCALHOST_IP_V6_ADDRESS_1);
-        assertEquals("2781:db8:1234:0:0:0:0:0/48", inetNetwork.toString());
+	inetNetwork = inetNetworkBuilder.getFromString(DNSFixture.LOCALHOST_IP_V6_ADDRESS_1);
+	assertEquals("2781:db8:1234:0:0:0:0:0/48", inetNetwork.toString());
 
     }
-
 }

Modified: james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/inetnetwork/model/InetNetworkTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/inetnetwork/model/InetNetworkTest.java?rev=1299463&r1=1299462&r2=1299463&view=diff
==============================================================================
--- james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/inetnetwork/model/InetNetworkTest.java
(original)
+++ james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/inetnetwork/model/InetNetworkTest.java
Sun Mar 11 22:16:02 2012
@@ -23,22 +23,18 @@ import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.StringTokenizer;
-
-import org.apache.james.dnsservice.library.inetnetwork.model.Inet4Network;
-import org.apache.james.dnsservice.library.inetnetwork.model.Inet6Network;
-
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
 
 /**
  * Test the InetNetwork class with various IPv4 and IPv6 network specification.
  */
-public class InetNetworkTest extends TestCase {
+public class InetNetworkTest {
 
     private static InetAddress address;
-
     private static InetAddress subnetmask4;
     private static Inet4Network network4;
-
     private static Integer subnetmask6;
     private static Inet6Network network6;
 
@@ -52,13 +48,14 @@ public class InetNetworkTest extends Tes
      * 
      * @throws UnknownHostException
      */
+    @Test
     public void testInetAddress() throws UnknownHostException {
 
-        // Test name alone (can be IPv4 or IPv6 depending on the OS plaform
-        // configuration).
-        address = InetAddress.getByName("localhost");
-        assertEquals(true, address instanceof InetAddress);
-        assertEquals(true, address.toString().contains("localhost"));
+	// Test name alone (can be IPv4 or IPv6 depending on the OS plaform
+	// configuration).
+	address = InetAddress.getByName("localhost");
+	assertEquals(true, address instanceof InetAddress);
+	assertEquals(true, address.toString().contains("localhost"));
 
     }
 
@@ -71,32 +68,32 @@ public class InetNetworkTest extends Tes
      * 
      * @throws UnknownHostException
      */
+    @Test
     public void testInet4Address() throws UnknownHostException {
 
-        // Test Bad IP V4 address.
-        try {
-            address = InetAddress.getByAddress(getBytesFromAddress("127.0.0.1.1"));
-            assertTrue(false);
-        } catch (UnknownHostException e) {
-            assertTrue(true);
-        }
-
-        // Test IP V4 address.
-        address = InetAddress.getByAddress(getBytesFromAddress("127.0.0.1"));
-        assertEquals(true, address instanceof Inet4Address);
-        assertEquals(true, address.toString().contains("/127.0.0.1"));
-
-        // Test IP V4 with 255 values (just 'like' a subnet mask).
-        address = InetAddress.getByAddress(getBytesFromAddress("255.255.225.0"));
-        assertEquals(true, address instanceof Inet4Address);
-        assertEquals(true, address.toString().contains("/255.255.225.0"));
-
-        // Test IP V4 Address with name and IP address.
-        address = InetAddress.getByAddress("localhost", getBytesFromAddress("127.0.0.1"));
-        assertEquals(true, address instanceof Inet4Address);
-        assertEquals(true, address.toString().contains("localhost"));
-        assertEquals(true, address.toString().contains("/127.0.0.1"));
-
+	// Test Bad IP V4 address.
+	try {
+	    address = InetAddress.getByAddress(getBytesFromAddress("127.0.0.1.1"));
+	    assertTrue(false);
+	} catch (UnknownHostException e) {
+	    assertTrue(true);
+	}
+
+	// Test IP V4 address.
+	address = InetAddress.getByAddress(getBytesFromAddress("127.0.0.1"));
+	assertEquals(true, address instanceof Inet4Address);
+	assertEquals(true, address.toString().contains("/127.0.0.1"));
+
+	// Test IP V4 with 255 values (just 'like' a subnet mask).
+	address = InetAddress.getByAddress(getBytesFromAddress("255.255.225.0"));
+	assertEquals(true, address instanceof Inet4Address);
+	assertEquals(true, address.toString().contains("/255.255.225.0"));
+
+	// Test IP V4 Address with name and IP address.
+	address = InetAddress.getByAddress("localhost", getBytesFromAddress("127.0.0.1"));
+	assertEquals(true, address instanceof Inet4Address);
+	assertEquals(true, address.toString().contains("localhost"));
+	assertEquals(true, address.toString().contains("/127.0.0.1"));
     }
 
     /**
@@ -108,26 +105,27 @@ public class InetNetworkTest extends Tes
      * 
      * @throws UnknownHostException
      */
+    @Test
     public void testInet6Address() throws UnknownHostException {
 
-        // Test Bad IP V6 address.
-        try {
-            address = InetAddress.getByAddress(getBytesFromAddress("0000:0000:0000:0000:0000:0000:0000:0001:00001"));
-            assertTrue(false);
-        } catch (UnknownHostException e) {
-            assertTrue(true);
-        }
-
-        // Test IP V6 address.
-        address = InetAddress.getByAddress(getBytesFromAddress("0000:0000:0000:0000:0000:0000:0000:0001"));
-        assertEquals(true, address instanceof Inet6Address);
-        assertEquals(true, address.toString().contains("/0:0:0:0:0:0:0:1"));
-
-        // Test IP V6 Address with name and IP address.
-        address = InetAddress.getByAddress("localhost", getBytesFromAddress("0000:0000:0000:0000:0000:0000:0000:0001"));
-        assertEquals(true, address instanceof Inet6Address);
-        assertEquals(true, address.toString().contains("localhost"));
-        assertEquals(true, address.toString().contains("/0:0:0:0:0:0:0:1"));
+	// Test Bad IP V6 address.
+	try {
+	    address = InetAddress.getByAddress(getBytesFromAddress("0000:0000:0000:0000:0000:0000:0000:0001:00001"));
+	    assertTrue(false);
+	} catch (UnknownHostException e) {
+	    assertTrue(true);
+	}
+
+	// Test IP V6 address.
+	address = InetAddress.getByAddress(getBytesFromAddress("0000:0000:0000:0000:0000:0000:0000:0001"));
+	assertEquals(true, address instanceof Inet6Address);
+	assertEquals(true, address.toString().contains("/0:0:0:0:0:0:0:1"));
+
+	// Test IP V6 Address with name and IP address.
+	address = InetAddress.getByAddress("localhost", getBytesFromAddress("0000:0000:0000:0000:0000:0000:0000:0001"));
+	assertEquals(true, address instanceof Inet6Address);
+	assertEquals(true, address.toString().contains("localhost"));
+	assertEquals(true, address.toString().contains("/0:0:0:0:0:0:0:1"));
 
     }
 
@@ -136,23 +134,23 @@ public class InetNetworkTest extends Tes
      * 
      * @throws UnknownHostException
      */
+    @Test
     public void testInet4Network() throws UnknownHostException {
 
-        // Test with null parameter.
-        address = InetAddress.getByAddress(getBytesFromAddress("127.0.0.1"));
-        try {
-            network4 = new Inet4Network(address, null);
-            assertTrue(false);
-        } catch (NullPointerException e) {
-            assertTrue(true);
-        }
-
-        // Test IP V4.
-        address = InetAddress.getByAddress(getBytesFromAddress("127.0.0.1"));
-        subnetmask4 = InetAddress.getByAddress(getBytesFromAddress("255.255.255.0"));
-        network4 = new Inet4Network(address, subnetmask4);
-        assertEquals("127.0.0.0/255.255.255.0", network4.toString());
-
+	// Test with null parameter.
+	address = InetAddress.getByAddress(getBytesFromAddress("127.0.0.1"));
+	try {
+	    network4 = new Inet4Network(address, null);
+	    assertTrue(false);
+	} catch (NullPointerException e) {
+	    assertTrue(true);
+	}
+
+	// Test IP V4.
+	address = InetAddress.getByAddress(getBytesFromAddress("127.0.0.1"));
+	subnetmask4 = InetAddress.getByAddress(getBytesFromAddress("255.255.255.0"));
+	network4 = new Inet4Network(address, subnetmask4);
+	assertEquals("127.0.0.0/255.255.255.0", network4.toString());
     }
 
     /**
@@ -160,59 +158,59 @@ public class InetNetworkTest extends Tes
      * 
      * @throws UnknownHostException
      */
+    @Test
     public void testInet6Network() throws UnknownHostException {
 
-        // Test with null parameter.
-        address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
-        try {
-            network6 = new Inet6Network(address, null);
-            assertTrue(false);
-        } catch (NullPointerException e) {
-            assertTrue(true);
-        }
-
-        // Test IP V6 with subnet mask 32768.
-        address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
-        subnetmask6 = 32768;
-        network6 = new Inet6Network(address, subnetmask6);
-        assertEquals("2781:db8:1234:8612:45ee:0:f05e:1/32768", network6.toString());
-
-        // Test IP V6 with subnet mask 128.
-        address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
-        subnetmask6 = 128;
-        network6 = new Inet6Network(address, subnetmask6);
-        assertEquals("2781:db8:1234:8612:0:0:0:0/128", network6.toString());
-
-        // Test IP V6 with subnet mask 48.
-        address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
-        subnetmask6 = 48;
-        network6 = new Inet6Network(address, subnetmask6);
-        assertEquals("2781:db8:1234:0:0:0:0:0/48", network6.toString());
-
-        // Test IP V6 with subnet mask 16.
-        address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
-        subnetmask6 = 16;
-        network6 = new Inet6Network(address, subnetmask6);
-        assertEquals("2781:db8:1200:0:0:0:0:0/16", network6.toString());
-
-        // Test IP V6 with subnet mask 2.
-        address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
-        subnetmask6 = 2;
-        network6 = new Inet6Network(address, subnetmask6);
-        assertEquals("2781:0:0:0:0:0:0:0/2", network6.toString());
-
-        // Test IP V6 with subnet mask 1.
-        address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
-        subnetmask6 = 1;
-        network6 = new Inet6Network(address, subnetmask6);
-        assertEquals("2700:0:0:0:0:0:0:0/1", network6.toString());
-
-        // Test IP V6 with subnet mask 0.
-        address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
-        subnetmask6 = 0;
-        network6 = new Inet6Network(address, subnetmask6);
-        assertEquals("0:0:0:0:0:0:0:0/0", network6.toString());
-
+	// Test with null parameter.
+	address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
+	try {
+	    network6 = new Inet6Network(address, null);
+	    assertTrue(false);
+	} catch (NullPointerException e) {
+	    assertTrue(true);
+	}
+
+	// Test IP V6 with subnet mask 32768.
+	address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
+	subnetmask6 = 32768;
+	network6 = new Inet6Network(address, subnetmask6);
+	assertEquals("2781:db8:1234:8612:45ee:0:f05e:1/32768", network6.toString());
+
+	// Test IP V6 with subnet mask 128.
+	address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
+	subnetmask6 = 128;
+	network6 = new Inet6Network(address, subnetmask6);
+	assertEquals("2781:db8:1234:8612:0:0:0:0/128", network6.toString());
+
+	// Test IP V6 with subnet mask 48.
+	address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
+	subnetmask6 = 48;
+	network6 = new Inet6Network(address, subnetmask6);
+	assertEquals("2781:db8:1234:0:0:0:0:0/48", network6.toString());
+
+	// Test IP V6 with subnet mask 16.
+	address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
+	subnetmask6 = 16;
+	network6 = new Inet6Network(address, subnetmask6);
+	assertEquals("2781:db8:1200:0:0:0:0:0/16", network6.toString());
+
+	// Test IP V6 with subnet mask 2.
+	address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
+	subnetmask6 = 2;
+	network6 = new Inet6Network(address, subnetmask6);
+	assertEquals("2781:0:0:0:0:0:0:0/2", network6.toString());
+
+	// Test IP V6 with subnet mask 1.
+	address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
+	subnetmask6 = 1;
+	network6 = new Inet6Network(address, subnetmask6);
+	assertEquals("2700:0:0:0:0:0:0:0/1", network6.toString());
+
+	// Test IP V6 with subnet mask 0.
+	address = InetAddress.getByAddress(getBytesFromAddress("2781:0db8:1234:8612:45ee:0000:f05e:0001"));
+	subnetmask6 = 0;
+	network6 = new Inet6Network(address, subnetmask6);
+	assertEquals("0:0:0:0:0:0:0:0/0", network6.toString());
     }
 
     /**
@@ -231,34 +229,31 @@ public class InetNetworkTest extends Tes
      */
     private byte[] getBytesFromAddress(String address) {
 
-        if (address.contains(".")) {
-            StringTokenizer st = new StringTokenizer(address, ".");
-            byte[] bytes = new byte[st.countTokens()];
-            int i = 0;
-            while (st.hasMoreTokens()) {
-                Integer inb = Integer.parseInt(st.nextToken());
-                bytes[i] = inb.byteValue();
-                i++;
-            }
-            return bytes;
-        }
-
-        else if (address.contains(":")) {
-            StringTokenizer st = new StringTokenizer(address, ":");
-            byte[] bytes = new byte[st.countTokens() * 2];
-            int i = 0;
-            while (st.hasMoreTokens()) {
-                String token = st.nextToken();
-                bytes[i] = (byte) Integer.parseInt(token.substring(0, 2), 16);
-                i++;
-                bytes[i] = (byte) Integer.parseInt(token.substring(2, 4), 16);
-                i++;
-            }
-            return bytes;
-        }
-
-        throw new IllegalArgumentException("The address [" + address + "] is not of the correct
format. It should at least contain a . or a :");
+	if (address.contains(".")) {
+	    StringTokenizer st = new StringTokenizer(address, ".");
+	    byte[] bytes = new byte[st.countTokens()];
+	    int i = 0;
+	    while (st.hasMoreTokens()) {
+		Integer inb = Integer.parseInt(st.nextToken());
+		bytes[i] = inb.byteValue();
+		i++;
+	    }
+	    return bytes;
+	} else if (address.contains(":")) {
+	    StringTokenizer st = new StringTokenizer(address, ":");
+	    byte[] bytes = new byte[st.countTokens() * 2];
+	    int i = 0;
+	    while (st.hasMoreTokens()) {
+		String token = st.nextToken();
+		bytes[i] = (byte) Integer.parseInt(token.substring(0, 2), 16);
+		i++;
+		bytes[i] = (byte) Integer.parseInt(token.substring(2, 4), 16);
+		i++;
+	    }
+	    return bytes;
+	}
 
+	throw new IllegalArgumentException(
+		"The address [" + address + "] is not of the correct format. It should at least contain
a . or a :");
     }
-
 }

Modified: james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/netmatcher/NetMatcherTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/netmatcher/NetMatcherTest.java?rev=1299463&r1=1299462&r2=1299463&view=diff
==============================================================================
--- james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/netmatcher/NetMatcherTest.java
(original)
+++ james/server/trunk/dnsservice-library/src/test/java/org/apache/james/dnsservice/library/netmatcher/NetMatcherTest.java
Sun Mar 11 22:16:02 2012
@@ -19,97 +19,94 @@
 package org.apache.james.dnsservice.library.netmatcher;
 
 import java.net.UnknownHostException;
-
-import junit.framework.TestCase;
-
 import org.apache.james.dnsservice.api.mock.DNSFixture;
-import org.apache.james.dnsservice.library.netmatcher.NetMatcher;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
 
 /**
  * Test the NetMatcher class with various IPv4 and IPv6 parameters.
  * 
  */
-public class NetMatcherTest extends TestCase {
+public class NetMatcherTest {
 
-    /**
-     * 
-     */
     private static NetMatcher netMatcher;
 
     /**
-     * 
+     * Test for IPV4 uniqueness.
      */
+    @Test
     public void testIpV4NetworksUniqueness() {
-        netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V4_ADDRESSES_DUPLICATE, DNSFixture.DNS_SERVER_IPV4_MOCK);
-        assertEquals("[172.16.0.0/255.255.0.0, 192.168.1.0/255.255.255.0]", netMatcher.toString());
+	netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V4_ADDRESSES_DUPLICATE, DNSFixture.DNS_SERVER_IPV4_MOCK);
+	assertEquals("[172.16.0.0/255.255.0.0, 192.168.1.0/255.255.255.0]", netMatcher.toString());
     }
 
     /**
-     * 
+     * Test for IPV6 uniqueness.
      */
+    @Test
     public void testIpV6NetworksUniqueness() {
-        netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V6_ADDRESSES_DUPLICATE, DNSFixture.DNS_SERVER_IPV6_MOCK);
-        assertEquals("[0:0:0:0:0:0:0:1/32768, 2781:db8:1234:0:0:0:0:0/48]", netMatcher.toString());
+	netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V6_ADDRESSES_DUPLICATE, DNSFixture.DNS_SERVER_IPV6_MOCK);
+	assertEquals("[0:0:0:0:0:0:0:1/32768, 2781:db8:1234:0:0:0:0:0/48]", netMatcher.toString());
     }
 
     /**
+     * Test for IPV4 matcher.
      * @throws UnknownHostException
      */
+    @Test
     public void testIpV4Matcher() throws UnknownHostException {
 
-        netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V4_ADDRESSES, DNSFixture.DNS_SERVER_IPV4_MOCK);
-
-        assertEquals(true, netMatcher.matchInetNetwork("127.0.0.1"));
-        assertEquals(true, netMatcher.matchInetNetwork("localhost"));
-        assertEquals(true, netMatcher.matchInetNetwork("172.16.15.254"));
-        assertEquals(true, netMatcher.matchInetNetwork("192.168.1.254"));
-        assertEquals(false, netMatcher.matchInetNetwork("192.169.1.254"));
+	netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V4_ADDRESSES, DNSFixture.DNS_SERVER_IPV4_MOCK);
 
+	assertEquals(true, netMatcher.matchInetNetwork("127.0.0.1"));
+	assertEquals(true, netMatcher.matchInetNetwork("localhost"));
+	assertEquals(true, netMatcher.matchInetNetwork("172.16.15.254"));
+	assertEquals(true, netMatcher.matchInetNetwork("192.168.1.254"));
+	assertEquals(false, netMatcher.matchInetNetwork("192.169.1.254"));
     }
 
     /**
      * @throws UnknownHostException
      */
+    @Test
     public void testIpV4MatcherWithIpV6() throws UnknownHostException {
 
-        netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V4_ADDRESSES, DNSFixture.DNS_SERVER_IPV4_MOCK);
-
-        assertEquals(false, netMatcher.matchInetNetwork("0:0:0:0:0:0:0:1%0"));
-        assertEquals(false, netMatcher.matchInetNetwork("00:00:00:00:00:00:00:1"));
-        assertEquals(false, netMatcher.matchInetNetwork("00:00:00:00:00:00:00:2"));
-        assertEquals(false, netMatcher.matchInetNetwork("2781:0db8:1234:8612:45ee:ffff:fffe:0001"));
-        assertEquals(false, netMatcher.matchInetNetwork("2781:0db8:1235:8612:45ee:ffff:fffe:0001"));
+	netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V4_ADDRESSES, DNSFixture.DNS_SERVER_IPV4_MOCK);
 
+	assertEquals(false, netMatcher.matchInetNetwork("0:0:0:0:0:0:0:1%0"));
+	assertEquals(false, netMatcher.matchInetNetwork("00:00:00:00:00:00:00:1"));
+	assertEquals(false, netMatcher.matchInetNetwork("00:00:00:00:00:00:00:2"));
+	assertEquals(false, netMatcher.matchInetNetwork("2781:0db8:1234:8612:45ee:ffff:fffe:0001"));
+	assertEquals(false, netMatcher.matchInetNetwork("2781:0db8:1235:8612:45ee:ffff:fffe:0001"));
     }
 
     /**
      * @throws UnknownHostException
      */
+    @Test
     public void testIpV6Matcher() throws UnknownHostException {
 
-        netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V6_ADDRESSES, DNSFixture.DNS_SERVER_IPV6_MOCK);
-
-        assertEquals(true, netMatcher.matchInetNetwork("0:0:0:0:0:0:0:1%0"));
-        assertEquals(true, netMatcher.matchInetNetwork("00:00:00:00:00:00:00:1"));
-        assertEquals(false, netMatcher.matchInetNetwork("00:00:00:00:00:00:00:2"));
-        assertEquals(true, netMatcher.matchInetNetwork("2781:0db8:1234:8612:45ee:ffff:fffe:0001"));
-        assertEquals(false, netMatcher.matchInetNetwork("2781:0db8:1235:8612:45ee:ffff:fffe:0001"));
+	netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V6_ADDRESSES, DNSFixture.DNS_SERVER_IPV6_MOCK);
 
+	assertEquals(true, netMatcher.matchInetNetwork("0:0:0:0:0:0:0:1%0"));
+	assertEquals(true, netMatcher.matchInetNetwork("00:00:00:00:00:00:00:1"));
+	assertEquals(false, netMatcher.matchInetNetwork("00:00:00:00:00:00:00:2"));
+	assertEquals(true, netMatcher.matchInetNetwork("2781:0db8:1234:8612:45ee:ffff:fffe:0001"));
+	assertEquals(false, netMatcher.matchInetNetwork("2781:0db8:1235:8612:45ee:ffff:fffe:0001"));
     }
 
     /**
      * @throws UnknownHostException
      */
+    @Test
     public void testIpV6MatcherWithIpV4() throws UnknownHostException {
 
-        netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V6_ADDRESSES, DNSFixture.DNS_SERVER_IPV6_MOCK);
-
-        assertEquals(false, netMatcher.matchInetNetwork("127.0.0.1"));
-        assertEquals(false, netMatcher.matchInetNetwork("localhost"));
-        assertEquals(false, netMatcher.matchInetNetwork("172.16.15.254"));
-        assertEquals(false, netMatcher.matchInetNetwork("192.168.1.254"));
-        assertEquals(false, netMatcher.matchInetNetwork("192.169.1.254"));
+	netMatcher = new NetMatcher(DNSFixture.LOCALHOST_IP_V6_ADDRESSES, DNSFixture.DNS_SERVER_IPV6_MOCK);
 
+	assertEquals(false, netMatcher.matchInetNetwork("127.0.0.1"));
+	assertEquals(false, netMatcher.matchInetNetwork("localhost"));
+	assertEquals(false, netMatcher.matchInetNetwork("172.16.15.254"));
+	assertEquals(false, netMatcher.matchInetNetwork("192.168.1.254"));
+	assertEquals(false, netMatcher.matchInetNetwork("192.169.1.254"));
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message