james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ieu...@apache.org
Subject svn commit: r1452015 - in /james/server/trunk: ./ dns-service/dnsservice-dnsjava/ dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/ dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/ dns-se...
Date Sun, 03 Mar 2013 07:44:03 GMT
Author: ieugen
Date: Sun Mar  3 07:44:02 2013
New Revision: 1452015

URL: http://svn.apache.org/r1452015
Log:
DNS Service code cleaning

Added:
    james/server/trunk/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/ZoneCacheLookupRecordsAnswer.java
Modified:
    james/server/trunk/dns-service/dnsservice-dnsjava/pom.xml
    james/server/trunk/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java
    james/server/trunk/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java
    james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java
    james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/InetNetworkBuilder.java
    james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/model/Inet4Network.java
    james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/model/Inet6Network.java
    james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/netmatcher/NetMatcher.java
    james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/ProcessorUtil.java
    james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
    james/server/trunk/pom.xml

Modified: james/server/trunk/dns-service/dnsservice-dnsjava/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/dns-service/dnsservice-dnsjava/pom.xml?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/dns-service/dnsservice-dnsjava/pom.xml (original)
+++ james/server/trunk/dns-service/dnsservice-dnsjava/pom.xml Sun Mar  3 07:44:02 2013
@@ -66,6 +66,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
             <scope>test</scope>

Modified: james/server/trunk/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java (original)
+++ james/server/trunk/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java Sun Mar  3 07:44:02 2013
@@ -109,17 +109,12 @@ public class DNSJavaService implements D
 
     private Logger logger;
 
-    /**
-     * @see org.apache.james.lifecycle.api.LogEnabled#setLog(org.slf4j.Logger)
-     */
     public void setLog(Logger logger) {
         this.logger = logger;
     }
 
-    /**
-     * @see org.apache.james.lifecycle.api.Configurable#configure(org.apache.commons.configuration.HierarchicalConfiguration)
-     */
     @SuppressWarnings("unchecked")
+    @Override
     public void configure(HierarchicalConfiguration configuration) throws ConfigurationException {
 
         final boolean autodiscover = configuration.getBoolean("autodiscover", true);
@@ -233,6 +228,7 @@ public class DNSJavaService implements D
      *
      * @return an array of DNS server names
      */
+    @Override
     public String[] getDNSServers() {
         return dnsServers.toArray(new String[dnsServers.size()]);
     }
@@ -309,9 +305,7 @@ public class DNSJavaService implements D
         return servers;
     }
 
-    /**
-     * @see org.apache.james.dnsservice.api.DNSService#findMXRecords(String)
-     */
+    @Override
     public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException {
         List<String> servers = new ArrayList<String>();
         try {
@@ -429,9 +423,7 @@ public class DNSJavaService implements D
         return host;
     }
 
-    /**
-     * @see org.apache.james.dnsservice.api.DNSService#getByName(String)
-     */
+    @Override
     public InetAddress getByName(String host) throws UnknownHostException {
         String name = allowIPLiteral(host);
 
@@ -453,9 +445,7 @@ public class DNSJavaService implements D
         }
     }
 
-    /**
-     * @see org.apache.james.dnsservice.api.DNSService#getAllByName(String)
-     */
+    @Override
     public InetAddress[] getAllByName(String host) throws UnknownHostException {
         String name = allowIPLiteral(host);
         try {
@@ -481,9 +471,7 @@ public class DNSJavaService implements D
         }
     }
 
-    /**
-     * @see org.apache.james.dnsservice.api.DNSService#findTXTRecords(String)
-     */
+    @Override
     public Collection<String> findTXTRecords(String hostname) {
         List<String> txtR = new ArrayList<String>();
         Record[] records = lookupNoException(hostname, Type.TXT, "TXT");
@@ -498,9 +486,7 @@ public class DNSJavaService implements D
         return txtR;
     }
 
-    /**
-     * @see org.apache.james.dnsservice.api.DNSService#getHostName(java.net.InetAddress)
-     */
+    @Override
     public String getHostName(InetAddress addr) {
         String result;
         Name name = ReverseMap.fromAddress(addr);
@@ -515,30 +501,22 @@ public class DNSJavaService implements D
         return result;
     }
 
-    /**
-     * @see org.apache.james.dnsservice.api.DNSService#getLocalHost()
-     */
+    @Override
     public InetAddress getLocalHost() throws UnknownHostException {
         return InetAddress.getLocalHost();
     }
 
-    /**
-     * @see org.apache.james.dnsservice.api.DNSServiceMBean#getMaximumCacheSize()
-     */
+    @Override
     public int getMaximumCacheSize() {
         return maxCacheSize;
     }
 
-    /**
-     * @see org.apache.james.dnsservice.api.DNSServiceMBean#getCurrentCacheSize()
-     */
+    @Override
     public int getCurrentCacheSize() {
         return cache.getSize();
     }
 
-    /**
-     * @see org.apache.james.dnsservice.api.DNSServiceMBean#clearCache()
-     */
+    @Override
     public void clearCache() {
         cache.clearCache();
     }

Modified: james/server/trunk/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java (original)
+++ james/server/trunk/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java Sun Mar  3 07:44:02 2013
@@ -18,30 +18,84 @@
  ****************************************************************/
 package org.apache.james.dnsservice.dnsjava;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
+import com.google.common.io.Resources;
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.junit.After;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 import org.junit.Before;
 import org.junit.Test;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
 import org.slf4j.LoggerFactory;
-import org.xbill.DNS.*;
+import org.xbill.DNS.Cache;
+import org.xbill.DNS.DClass;
+import org.xbill.DNS.Lookup;
+import org.xbill.DNS.Name;
+import org.xbill.DNS.Resolver;
+import org.xbill.DNS.Zone;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
 
 public class DNSJavaServiceTest {
 
     private TestableDNSServer dnsServer;
+    private static byte[] DNS_SERVER_CONFIG = ("<dnsserver>" +
+            "<autodiscover>true</autodiscover>" +
+            "<authoritative>false</authoritative>" +
+            "</dnsserver>").getBytes();
+
     private Cache defaultCache;
     private Resolver defaultResolver;
     private Name[] defaultSearchPaths;
 
+    private Cache mockedCache;
+
+    @Before
+    public void setUp() throws Exception {
+        dnsServer = new TestableDNSServer();
+        DefaultConfigurationBuilder db = new DefaultConfigurationBuilder();
+
+        db.load(new ByteArrayInputStream(DNS_SERVER_CONFIG));
+
+        dnsServer.setLog(LoggerFactory.getLogger(DNSJavaServiceTest.class));
+        dnsServer.configure(db);
+        dnsServer.init();
+
+        defaultCache = Lookup.getDefaultCache(DClass.IN);
+        defaultResolver = Lookup.getDefaultResolver();
+        defaultSearchPaths = Lookup.getDefaultSearchPath();
+        Lookup.setDefaultCache(null, DClass.IN);
+        Lookup.setDefaultResolver(null);
+        Lookup.setDefaultSearchPath(new Name[]{});
+
+        dnsServer.setResolver(null);
+        mockedCache = mock(Cache.class);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        dnsServer.setCache(null);
+        dnsServer = null;
+        Lookup.setDefaultCache(defaultCache, DClass.IN);
+        Lookup.setDefaultResolver(defaultResolver);
+        Lookup.setDefaultSearchPath(defaultSearchPaths);
+    }
+
     @Test
     public void testNoMX() throws Exception {
-        dnsServer.setResolver(null);
-        dnsServer.setCache(new ZoneCache("dnstest.com."));
+        doAnswer(new ZoneCacheLookupRecordsAnswer(loadZone("dnstest.com.")))
+                .when(mockedCache).lookupRecords(any(Name.class), anyInt(), anyInt());
+        dnsServer.setCache(mockedCache);
+
         // a.setSearchPath(new String[] { "searchdomain.com." });
         Collection<String> records = dnsServer.findMXRecords("nomx.dnstest.com.");
         assertEquals(1, records.size());
@@ -50,8 +104,10 @@ public class DNSJavaServiceTest {
 
     @Test
     public void testBadMX() throws Exception {
-        dnsServer.setResolver(null);
-        dnsServer.setCache(new ZoneCache("dnstest.com."));
+        doAnswer(new ZoneCacheLookupRecordsAnswer(loadZone("dnstest.com.")))
+                .when(mockedCache).lookupRecords(any(Name.class), anyInt(), anyInt());
+        dnsServer.setCache(mockedCache);
+
         // a.setSearchPath(new String[] { "searchdomain.com." });
         Collection<String> records = dnsServer.findMXRecords("badmx.dnstest.com.");
         assertEquals(1, records.size());
@@ -63,9 +119,10 @@ public class DNSJavaServiceTest {
 
     @Test
     public void testINARecords() throws Exception {
-        // Zone z = loadZone("pippo.com.");
-        dnsServer.setResolver(null);
-        dnsServer.setCache(new ZoneCache("pippo.com."));
+        doAnswer(new ZoneCacheLookupRecordsAnswer(loadZone("pippo.com.")))
+                .when(mockedCache).lookupRecords(any(Name.class), anyInt(), anyInt());
+        dnsServer.setCache(mockedCache);
+
         // dnsServer.setLookupper(new ZoneLookupper(z));
         Collection<String> records = dnsServer.findMXRecords("www.pippo.com.");
         assertEquals(1, records.size());
@@ -74,9 +131,10 @@ public class DNSJavaServiceTest {
 
     @Test
     public void testMXCatches() throws Exception {
-        // Zone z = loadZone("test-zone.com.");
-        dnsServer.setResolver(null);
-        dnsServer.setCache(new ZoneCache("test-zone.com."));
+        doAnswer(new ZoneCacheLookupRecordsAnswer(loadZone("test-zone.com.")))
+                .when(mockedCache).lookupRecords(any(Name.class), anyInt(), anyInt());
+        dnsServer.setCache(mockedCache);
+
         // dnsServer.setLookupper(new ZoneLookupper(z));
         Collection<String> res = dnsServer.findMXRecords("test-zone.com.");
         try {
@@ -93,8 +151,10 @@ public class DNSJavaServiceTest {
      */
     @Test
     public void testTwoMXSamePrio() throws Exception {
-        dnsServer.setResolver(null);
-        dnsServer.setCache(new ZoneCache("two-mx.sameprio."));
+        doAnswer(new ZoneCacheLookupRecordsAnswer(loadZone("two-mx.sameprio.")))
+                .when(mockedCache).lookupRecords(any(Name.class), anyInt(), anyInt());
+        dnsServer.setCache(mockedCache);
+
         // a.setSearchPath(new String[] { "searchdomain.com." });
         Collection<String> records = dnsServer.findMXRecords("two-mx.sameprio.");
         assertEquals(2, records.size());
@@ -104,8 +164,10 @@ public class DNSJavaServiceTest {
 
     @Test
     public void testThreeMX() throws Exception {
-        dnsServer.setResolver(null);
-        dnsServer.setCache(new ZoneCache("three-mx.bar."));
+        doAnswer(new ZoneCacheLookupRecordsAnswer(loadZone("three-mx.bar.")))
+                .when(mockedCache).lookupRecords(any(Name.class), anyInt(), anyInt());
+        dnsServer.setCache(mockedCache);
+
         // a.setSearchPath(new String[] { "searchdomain.com." });
         ArrayList<String> records = new ArrayList<String>(dnsServer.findMXRecords("three-mx.bar."));
         assertEquals(3, records.size());
@@ -120,8 +182,9 @@ public class DNSJavaServiceTest {
      */
     @Test
     public void testTwoMXDifferentPrio() throws Exception {
-        dnsServer.setResolver(null);
-        dnsServer.setCache(new ZoneCache("two-mx.differentprio."));
+        doAnswer(new ZoneCacheLookupRecordsAnswer(loadZone("two-mx.differentprio.")))
+                .when(mockedCache).lookupRecords(any(Name.class), anyInt(), anyInt());
+        dnsServer.setCache(mockedCache);
         // a.setSearchPath(new String[] { "searchdomain.com." });
         Collection<String> records = dnsServer.findMXRecords("two-mx.differentprio.");
         assertEquals(2, records.size());
@@ -135,13 +198,14 @@ public class DNSJavaServiceTest {
      */
     @Test
     public void testOneMX() throws Exception {
-        dnsServer.setResolver(null);
-        dnsServer.setCache(new ZoneCache("one-mx.bar."));
+        doAnswer(new ZoneCacheLookupRecordsAnswer(loadZone("one-mx.bar.")))
+                .when(mockedCache).lookupRecords(any(Name.class), anyInt(), anyInt());
+        dnsServer.setCache(mockedCache);
+
         // a.setSearchPath(new String[] { "searchdomain.com." });
         Collection<String> records = dnsServer.findMXRecords("one-mx.bar.");
         assertEquals(1, records.size());
         assertTrue(records.contains("mx1.one-mx.bar."));
-
     }
     /*
      * public void testCNAMEasMXrecords() throws Exception { // Zone z =
@@ -152,147 +216,11 @@ public class DNSJavaServiceTest {
      * //assertEquals(true, records.hasNext()); }
      */
 
-    @Before
-    public void setUp() throws Exception {
-        dnsServer = new TestableDNSServer();
-        DefaultConfigurationBuilder db = new DefaultConfigurationBuilder();
-
-        db.load(new ByteArrayInputStream("<dnsserver><autodiscover>true</autodiscover><authoritative>false</authoritative></dnsserver>".
-                getBytes()));
-        dnsServer.setLog(LoggerFactory.getLogger("MockLog"));
-        dnsServer.configure(db);
-        dnsServer.init();
-
-        defaultCache = Lookup.getDefaultCache(DClass.IN);
-        defaultResolver = Lookup.getDefaultResolver();
-        defaultSearchPaths = Lookup.getDefaultSearchPath();
-        Lookup.setDefaultCache(null, DClass.IN);
-        Lookup.setDefaultResolver(null);
-        Lookup.setDefaultSearchPath(new Name[]{});
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        dnsServer.setCache(null);
-        dnsServer = null;
-        Lookup.setDefaultCache(defaultCache, DClass.IN);
-        Lookup.setDefaultResolver(defaultResolver);
-        Lookup.setDefaultSearchPath(defaultSearchPaths);
-    }
-
-    private Zone loadZone(String zoneName) throws IOException {
+    private static Zone loadZone(String zoneName) throws IOException {
         String zoneFilename = zoneName + "zone";
-        URL zoneResource = getClass().getResource(zoneFilename);
+        URL zoneResource = Resources.getResource(DNSJavaServiceTest.class, zoneFilename);
         assertNotNull("test resource for zone could not be loaded: " + zoneFilename, zoneResource);
-        String zoneFile = zoneResource.getFile();
-        Zone zone = new Zone(Name.fromString(zoneName), zoneFile);
-        return zone;
-    }
-
-    private final class ZoneCache extends Cache {
-
-        Zone z = null;
-
-        public ZoneCache(String string) throws IOException {
-            z = loadZone(string);
-        }
-
-        @Override
-        public SetResponse addMessage(Message arg0) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public synchronized void addNegative(Name arg0, int arg1, SOARecord arg2, int arg3) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public synchronized void addRecord(Record arg0, int arg1, Object arg2) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public synchronized void addRRset(RRset arg0, int arg1) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public synchronized void clearCache() {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public RRset[] findAnyRecords(Name arg0, int arg1) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public RRset[] findRecords(Name arg0, int arg1) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public void flushName(Name arg0) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public void flushSet(Name arg0, int arg1) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public int getDClass() {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public int getMaxCache() {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public int getMaxEntries() {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public int getMaxNCache() {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public int getSize() {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        protected synchronized SetResponse lookup(Name arg0, int arg1, int arg2) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public SetResponse lookupRecords(Name arg0, int arg1, int arg2) {
-            System.out.println("Cache.lookupRecords " + arg0 + "," + arg1 + "," + arg2);
-            return z.findRecords(arg0, arg1);
-            // return super.lookupRecords(arg0, arg1, arg2);
-        }
-
-        @Override
-        public void setMaxCache(int arg0) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public void setMaxEntries(int arg0) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
-
-        @Override
-        public void setMaxNCache(int arg0) {
-            throw new UnsupportedOperationException("ZoneCache is a mock used only for testing purpose");
-        }
+        return new Zone(Name.fromString(zoneName), zoneResource.getFile());
     }
 
     private final class TestableDNSServer extends DNSJavaService {

Added: james/server/trunk/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/ZoneCacheLookupRecordsAnswer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/ZoneCacheLookupRecordsAnswer.java?rev=1452015&view=auto
==============================================================================
--- james/server/trunk/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/ZoneCacheLookupRecordsAnswer.java (added)
+++ james/server/trunk/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/ZoneCacheLookupRecordsAnswer.java Sun Mar  3 07:44:02 2013
@@ -0,0 +1,29 @@
+package org.apache.james.dnsservice.dnsjava;
+
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xbill.DNS.Name;
+import org.xbill.DNS.SetResponse;
+import org.xbill.DNS.Zone;
+
+public class ZoneCacheLookupRecordsAnswer implements Answer<SetResponse> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ZoneCacheLookupRecordsAnswer.class);
+
+    private final Zone zone;
+
+    public ZoneCacheLookupRecordsAnswer(Zone zone) {
+        this.zone = zone;
+    }
+
+    @Override
+    public SetResponse answer(InvocationOnMock invocation) throws Throwable {
+        Object[] arguments = invocation.getArguments();
+        LOG.info("Cache.lookupRecords {}, {}, {}", arguments[0], arguments[1], arguments[2]);
+        assert arguments[0] instanceof Name;
+        assert arguments[1] instanceof Integer;
+        return zone.findRecords((Name) arguments[0], (Integer) arguments[1]);
+    }
+}

Modified: james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java (original)
+++ james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/MXHostAddressIterator.java Sun Mar  3 07:44:02 2013
@@ -18,23 +18,27 @@
  ****************************************************************/
 package org.apache.james.dnsservice.library;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.james.dnsservice.api.DNSService;
+import org.apache.mailet.HostAddress;
+import org.slf4j.Logger;
+
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-
-import org.apache.james.dnsservice.api.DNSService;
-import org.apache.mailet.HostAddress;
-import org.slf4j.Logger;
+import java.util.Map;
 
 /**
- * 
+ *
  *
  */
 public class MXHostAddressIterator implements Iterator<HostAddress> {
 
-    private Iterator<HostAddress> addresses = null;
+    private final Iterator<HostAddress> addresses;
     private final Iterator<String> hosts;
     private final DNSService dns;
     private final boolean useSingleIP;
@@ -46,64 +50,60 @@ public class MXHostAddressIterator imple
     }
 
     public MXHostAddressIterator(Iterator<String> hosts, int defaultPort, DNSService dns, boolean useSingleIP, Logger logger) {
-        this.hosts = hosts;
-        this.dns = dns;
+        this.hosts = checkNotNull(hosts, "Hosts is null");
+        this.dns = checkNotNull(dns, "Dns is null");
         this.useSingleIP = useSingleIP;
         this.logger = logger;
         this.defaultPort = defaultPort;
-        
-        init();
-    }
+        final List<HostAddress> hAddresses = Lists.newArrayList();
 
-    /**
-     * @see java.util.Iterator#hasNext()
-     */
-    public boolean hasNext() {
-     
-        return addresses.hasNext();
-    }
-
-    private void init() {
-        final List<HostAddress> hAddresses = new ArrayList<HostAddress>();
         while (hosts.hasNext()) {
             String nextHostname = hosts.next();
-            final String hostname;
-            final String port;
-
-            int idx = nextHostname.indexOf(':');
-            if (idx > 0) {
-                port = nextHostname.substring(idx + 1);
-                hostname = nextHostname.substring(0, idx);
-            } else {
-                hostname = nextHostname;
-                port = defaultPort + "";
-            }
+            Map.Entry<String, String> hostAndPort = extractHostAndPort(nextHostname, defaultPort);
 
-            InetAddress[] addrs;
             try {
+                final InetAddress[] addrs;
                 if (useSingleIP) {
-                    addrs = new InetAddress[] { dns.getByName(hostname) };
+                    addrs = new InetAddress[]{dns.getByName(hostAndPort.getKey())};
                 } else {
-                    addrs = dns.getAllByName(hostname);
+                    addrs = dns.getAllByName(hostAndPort.getKey());
                 }
                 for (InetAddress addr : addrs) {
-                    hAddresses.add(new HostAddress(hostname, "smtp://" + addr.getHostAddress() + ":" + port));
+                    hAddresses.add(new HostAddress(hostAndPort.getKey(),
+                            "smtp://" + addr.getHostAddress() + ":" + hostAndPort.getValue()));
                 }
             } catch (UnknownHostException uhe) {
                 // this should never happen, since we just got
                 // this host from mxHosts, which should have
                 // already done this check.
-                String logBuffer = "Couldn't resolve IP address for discovered host " + hostname + ".";
+                String logBuffer = "Couldn't resolve IP address for discovered host " + hostAndPort.getKey() + ".";
                 logger.error(logBuffer);
             }
-
         }
         addresses = hAddresses.iterator();
     }
 
-    /**
-     * @see java.util.Iterator#next()
-     */
+    private static ImmutableMap.Entry<String, String> extractHostAndPort(String nextHostname, int defaultPort) {
+        final String hostname;
+        final String port;
+
+        int idx = nextHostname.indexOf(':');
+        if (idx > 0) {
+            port = nextHostname.substring(idx + 1);
+            hostname = nextHostname.substring(0, idx);
+        } else {
+            hostname = nextHostname;
+            port = Integer.toString(defaultPort);
+        }
+        return Maps.immutableEntry(hostname, port);
+    }
+
+    @Override
+    public boolean hasNext() {
+        return addresses.hasNext();
+    }
+
+    @Override
     public HostAddress next() {
         return addresses.next();
     }
@@ -111,8 +111,8 @@ public class MXHostAddressIterator imple
     /**
      * Not supported.
      */
+    @Override
     public void remove() {
         throw new UnsupportedOperationException("remove not supported by this iterator");
     }
-
 }

Modified: james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/InetNetworkBuilder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/InetNetworkBuilder.java?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/InetNetworkBuilder.java (original)
+++ james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/InetNetworkBuilder.java Sun Mar  3 07:44:02 2013
@@ -219,7 +219,6 @@ public class InetNetworkBuilder {
         final int mask = (bits == 32) ? 0 : 0xFFFFFFFF - ((1 << bits) - 1);
 
         return netspec.substring(0, netspec.indexOf('/') + 1) + Integer.toString(mask >> 24 & 0xFF, 10) + "." + Integer.toString(mask >> 16 & 0xFF, 10) + "." + Integer.toString(mask >> 8 & 0xFF, 10) + "." + Integer.toString(mask & 0xFF, 10);
-
     }
 
 }

Modified: james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/model/Inet4Network.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/model/Inet4Network.java?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/model/Inet4Network.java (original)
+++ james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/model/Inet4Network.java Sun Mar  3 07:44:02 2013
@@ -24,10 +24,7 @@ import java.net.UnknownHostException;
 
 import org.apache.james.dnsservice.library.inetnetwork.InetNetworkBuilder;
 
-/**
- * 
- * 
- */
+
 public class Inet4Network implements InetNetwork {
 
     /**
@@ -54,9 +51,7 @@ public class Inet4Network implements Ine
         this.netmask = netmask;
     }
 
-    /**
-     * @see org.apache.james.dnsservice.library.inetnetwork.model.InetNetwork#contains(InetAddress)
-     */
+    @Override
     public boolean contains(final InetAddress ip) {
         if (InetNetworkBuilder.isV6(ip.getHostAddress())) {
             return false;
@@ -68,30 +63,21 @@ public class Inet4Network implements Ine
         }
     }
 
-    /**
-     * @see java.lang.Object#toString()
-     */
+    @Override
     public String toString() {
         return network.getHostAddress() + "/" + netmask.getHostAddress();
     }
 
-    /**
-     * @see java.lang.Object#hashCode()
-     */
+    @Override
     public int hashCode() {
         return maskIP(network, netmask).hashCode();
     }
 
-    /**
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
+    @Override
     public boolean equals(Object obj) {
         return (obj != null) && (obj instanceof InetNetwork) && ((((Inet4Network) obj).network.equals(network)) && (((Inet4Network) obj).netmask.equals(netmask)));
     }
 
-    /**
-     * @see #maskIP(byte[], byte[])
-     */
     private static InetAddress maskIP(final InetAddress ip, final InetAddress mask) {
         return maskIP(ip.getAddress(), mask.getAddress());
     }
@@ -143,7 +129,6 @@ public class Inet4Network implements Ine
         }
 
         return addr;
-
     }
 
 }

Modified: james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/model/Inet6Network.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/model/Inet6Network.java?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/model/Inet6Network.java (original)
+++ james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/inetnetwork/model/Inet6Network.java Sun Mar  3 07:44:02 2013
@@ -18,16 +18,13 @@
  ****************************************************************/
 package org.apache.james.dnsservice.library.inetnetwork.model;
 
+import org.apache.james.dnsservice.library.inetnetwork.InetNetworkBuilder;
+
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
-import org.apache.james.dnsservice.library.inetnetwork.InetNetworkBuilder;
 
-/**
- * 
- * 
- */
 public class Inet6Network implements InetNetwork {
 
     /**
@@ -43,20 +40,16 @@ public class Inet6Network implements Ine
     /**
      * You need a IP address (InetAddress) and an subnetmask (Integer) to
      * construct an Inet6Network.
-     * 
-     * @param ip
-     *            the InetAddress to init the class
-     * @param netmask
-     *            the InetAddress represent the netmask to init the class
+     *
+     * @param ip      the InetAddress to init the class
+     * @param netmask the InetAddress represent the netmask to init the class
      */
     public Inet6Network(InetAddress ip, Integer netmask) {
         network = maskIP(ip, netmask);
         this.netmask = netmask;
     }
 
-    /**
-     * @see org.apache.james.dnsservice.library.inetnetwork.model.InetNetwork#contains(InetAddress)
-     */
+    @Override
     public boolean contains(final InetAddress ip) {
         if (!InetNetworkBuilder.isV6(ip.getHostAddress())) {
             return false;
@@ -68,34 +61,21 @@ public class Inet6Network implements Ine
         }
     }
 
-    /**
-     * Return String representation of this class.
-     * 
-     * @return string String representation of this class
-     */
+    @Override
     public String toString() {
         return network.getHostAddress() + "/" + netmask;
     }
 
-    /**
-     * Return hashCode representation of this class
-     * 
-     * @return hashCode the hashCode representation of this class
-     */
+    @Override
     public int hashCode() {
         return maskIP(network, netmask).hashCode();
     }
 
-    /**
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
+    @Override
     public boolean equals(Object obj) {
         return (obj != null) && (obj instanceof InetNetwork) && ((((Inet6Network) obj).network.equals(network)) && (((Inet6Network) obj).netmask.equals(netmask)));
     }
 
-    /**
-     * @see #maskIP(byte[], byte[])
-     */
     private static InetAddress maskIP(final InetAddress ip, Integer mask) {
         byte[] maskBytes = new byte[16];
         int i = 0;
@@ -110,11 +90,9 @@ public class Inet6Network implements Ine
     /**
      * Return InetAddress generated of the passed arguments. Return Null if any
      * error occurs
-     * 
-     * @param ip
-     *            the byte[] represent the ip
-     * @param mask
-     *            the byte[] represent the netmask
+     *
+     * @param ip   the byte[] represent the ip
+     * @param mask the byte[] represent the netmask
      * @return inetAddress the InetAddress generated of the passed arguments.
      */
     private static InetAddress maskIP(final byte[] ip, final byte[] mask) {
@@ -137,9 +115,8 @@ public class Inet6Network implements Ine
 
     /**
      * Return InetAddress which represent the given byte[]
-     * 
-     * @param ip
-     *            the byte[] represent the ip
+     *
+     * @param ip the byte[] represent the ip
      * @return ip the InetAddress generated of the given byte[]
      * @throws java.net.UnknownHostException
      */
@@ -155,7 +132,6 @@ public class Inet6Network implements Ine
         }
 
         return addr;
-
     }
 
 }

Modified: james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/netmatcher/NetMatcher.java
URL: http://svn.apache.org/viewvc/james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/netmatcher/NetMatcher.java?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/netmatcher/NetMatcher.java (original)
+++ james/server/trunk/dns-service/dnsservice-library/src/main/java/org/apache/james/dnsservice/library/netmatcher/NetMatcher.java Sun Mar  3 07:44:02 2013
@@ -117,16 +117,14 @@ public class NetMatcher {
 
     }
 
-    /**
-     * Return a sorted representation of the inet networks.
-     */
+    @Override
     public String toString() {
         return networks.toString();
     }
 
     /**
      * Can be overwritten for logging
-     * 
+     *
      * @param s
      *            the String to log
      */

Modified: james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/ProcessorUtil.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/ProcessorUtil.java?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/ProcessorUtil.java (original)
+++ james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/ProcessorUtil.java Sun Mar  3 07:44:02 2013
@@ -44,7 +44,7 @@ public class ProcessorUtil {
      *            the matcher or mailet than generated the exception
      * @param nextState
      *            the next state to set
-     * 
+     *
      * @throws MessagingException
      *             thrown always, rethrowing the passed in exception
      */

Modified: james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java (original)
+++ james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java Sun Mar  3 07:44:02 2013
@@ -18,11 +18,6 @@
  ****************************************************************/
 package org.apache.james.mailetcontainer.lib;
 
-import java.io.ByteArrayInputStream;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.concurrent.CountDownLatch;
-import javax.mail.MessagingException;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.commons.configuration.HierarchicalConfiguration;
@@ -36,224 +31,234 @@ import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.Mailet;
 import org.apache.mailet.Matcher;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import org.junit.Test;
 
+import javax.mail.MessagingException;
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.concurrent.CountDownLatch;
+
 public abstract class AbstractStateMailetProcessorTest {
 
     protected abstract AbstractStateMailetProcessor createProcessor(HierarchicalConfiguration configuration) throws
             Exception;
 
     private HierarchicalConfiguration createConfig(Class<?> matcherClass, Class<?> mailetClass, int count) throws
-        ConfigurationException {
-    StringBuilder sb = new StringBuilder();
-    sb.append("<processor state=\"" + Mail.DEFAULT + "\">");
-    sb.append("<mailet match=\"").append(matcherClass.getName()).append("=").append(count).append("\"").append(
-        " class=\"").append(mailetClass.getName()).append("\">");
-    sb.append("<state>test</state>");
-    sb.append("</mailet>");
-
-    sb.append("</processor>");
-
-    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
-    builder.load(new ByteArrayInputStream(sb.toString().getBytes()));
-    return builder;
+            ConfigurationException {
+        StringBuilder sb = new StringBuilder();
+        sb.append("<processor state=\"" + Mail.DEFAULT + "\">");
+        sb.append("<mailet match=\"").append(matcherClass.getName()).append("=").append(count).append("\"").append(
+                " class=\"").append(mailetClass.getName()).append("\">");
+        sb.append("<state>test</state>");
+        sb.append("</mailet>");
+
+        sb.append("</processor>");
+
+        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+        builder.load(new ByteArrayInputStream(sb.toString().getBytes()));
+        return builder;
     }
 
     @Test
     public void testSimpleRouting() throws Exception {
-    final CountDownLatch latch = new CountDownLatch(2);
-    final MailImpl mail = new MailImpl();
-    mail.setName(MailImpl.getId());
-    mail.setSender(new MailAddress("test@localhost"));
-    mail.setRecipients(Arrays.asList(new MailAddress("test@localhost"), new MailAddress("test2@localhost")));
-
-    AbstractStateMailetProcessor processor = createProcessor(createConfig(MockMatcher.class, MockMailet.class, 1));
-    processor.addListener(new MailetProcessorListener() {
-
-        @Override
-        public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients,
-                     Collection<MailAddress> matches, long processTime, MessagingException e) {
-        if (MockMatcher.class.equals(m.getClass())) {
-            assertEquals(mail.getName(), mailName);
-            // match one recipient
-            assertEquals(1, matches.size());
-            assertNull(e);
-            latch.countDown();
-        }
-
-        }
-
-        @Override
-        public void afterMailet(Mailet m, String mailName, String state, long processTime, MessagingException e) {
-        // check for class name as the terminating  mailet will kick in too
-
-        if (MockMailet.class.equals(m.getClass())) {
-            //assertEquals(mail.getName(), mailName);
-            assertEquals("test", state);
-            assertNull(e);
-            latch.countDown();
-        }
-        }
-    });
+        final CountDownLatch latch = new CountDownLatch(2);
+        final MailImpl mail = new MailImpl();
+        mail.setName(MailImpl.getId());
+        mail.setSender(new MailAddress("test@localhost"));
+        mail.setRecipients(Arrays.asList(new MailAddress("test@localhost"), new MailAddress("test2@localhost")));
+
+        AbstractStateMailetProcessor processor = createProcessor(createConfig(MockMatcher.class, MockMailet.class, 1));
+        processor.addListener(new MailetProcessorListener() {
+
+            @Override
+            public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients,
+                                     Collection<MailAddress> matches, long processTime, MessagingException e) {
+                if (MockMatcher.class.equals(m.getClass())) {
+                    assertEquals(mail.getName(), mailName);
+                    // match one recipient
+                    assertEquals(1, matches.size());
+                    assertNull(e);
+                    latch.countDown();
+                }
+
+            }
+
+            @Override
+            public void afterMailet(Mailet m, String mailName, String state, long processTime, MessagingException e) {
+                // check for class name as the terminating  mailet will kick in too
+
+                if (MockMailet.class.equals(m.getClass())) {
+                    //assertEquals(mail.getName(), mailName);
+                    assertEquals("test", state);
+                    assertNull(e);
+                    latch.countDown();
+                }
+            }
+        });
 
-    assertEquals(Mail.DEFAULT, mail.getState());
-    processor.service(mail);
+        assertEquals(Mail.DEFAULT, mail.getState());
+        processor.service(mail);
 
 
-    // the source mail should be ghosted as it reached the end of processor as only one recipient matched
-    assertEquals(Mail.GHOST, mail.getState());
-    latch.await();
-    processor.destroy();
+        // the source mail should be ghosted as it reached the end of processor as only one recipient matched
+        assertEquals(Mail.GHOST, mail.getState());
+        latch.await();
+        processor.destroy();
 
     }
 
     @Test
     public void testSimpleRoutingMatchAll() throws Exception {
-    final CountDownLatch latch = new CountDownLatch(2);
-    final MailImpl mail = new MailImpl();
-    mail.setName(MailImpl.getId());
-    mail.setSender(new MailAddress("test@localhost"));
-    mail.setRecipients(Arrays.asList(new MailAddress("test@localhost"), new MailAddress("test2@localhost")));
-
-    AbstractStateMailetProcessor processor = createProcessor(createConfig(MockMatcher.class, MockMailet.class, 2));
-    processor.addListener(new MailetProcessorListener() {
-
-        @Override
-        public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients,
-                     Collection<MailAddress> matches, long processTime, MessagingException e) {
-        if (MockMatcher.class.equals(m.getClass())) {
-            assertEquals(mail.getName(), mailName);
-            // match all recipient
-            assertEquals(2, matches.size());
-            assertNull(e);
-            latch.countDown();
-        }
-
-        }
-
-        @Override
-        public void afterMailet(Mailet m, String mailName, String state, long processTime, MessagingException e) {
-        // check for class name as the terminating  mailet will kick in too
-
-        if (MockMailet.class.equals(m.getClass())) {
-            // the name should be the same as we have a full match
-            assertEquals(mail.getName(), mailName);
-            assertEquals("test", state);
-            assertNull(e);
-            latch.countDown();
-        }
-        }
-    });
+        final CountDownLatch latch = new CountDownLatch(2);
+        final MailImpl mail = new MailImpl();
+        mail.setName(MailImpl.getId());
+        mail.setSender(new MailAddress("test@localhost"));
+        mail.setRecipients(Arrays.asList(new MailAddress("test@localhost"), new MailAddress("test2@localhost")));
+
+        AbstractStateMailetProcessor processor = createProcessor(createConfig(MockMatcher.class, MockMailet.class, 2));
+        processor.addListener(new MailetProcessorListener() {
+
+            @Override
+            public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients,
+                                     Collection<MailAddress> matches, long processTime, MessagingException e) {
+                if (MockMatcher.class.equals(m.getClass())) {
+                    assertEquals(mail.getName(), mailName);
+                    // match all recipient
+                    assertEquals(2, matches.size());
+                    assertNull(e);
+                    latch.countDown();
+                }
+
+            }
+
+            @Override
+            public void afterMailet(Mailet m, String mailName, String state, long processTime, MessagingException e) {
+                // check for class name as the terminating  mailet will kick in too
+
+                if (MockMailet.class.equals(m.getClass())) {
+                    // the name should be the same as we have a full match
+                    assertEquals(mail.getName(), mailName);
+                    assertEquals("test", state);
+                    assertNull(e);
+                    latch.countDown();
+                }
+            }
+        });
 
-    assertEquals(Mail.DEFAULT, mail.getState());
-    processor.service(mail);
+        assertEquals(Mail.DEFAULT, mail.getState());
+        processor.service(mail);
 
 
-    // the source mail should have the new state as it was a full match
-    assertEquals("test", mail.getState());
-    latch.await();
-    processor.destroy();
+        // the source mail should have the new state as it was a full match
+        assertEquals("test", mail.getState());
+        latch.await();
+        processor.destroy();
 
     }
 
     @Test
     public void testMatcherThrowException() throws Exception {
-    final CountDownLatch latch = new CountDownLatch(1);
-    final MailImpl mail = new MailImpl();
-    mail.setName(MailImpl.getId());
-    mail.setSender(new MailAddress("test@localhost"));
-    mail.setRecipients(Arrays.asList(new MailAddress("test@localhost"), new MailAddress("test2@localhost")));
-
-    AbstractStateMailetProcessor processor = createProcessor(createConfig(ExceptionThrowingMatcher.class,
-        MockMailet.class, 0));
-    processor.addListener(new MailetProcessorListener() {
-
-        @Override
-        public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients,
-                     Collection<MailAddress> matches, long processTime, MessagingException e) {
-        if (ExceptionThrowingMatcher.class.equals(m.getClass())) {
-            assertEquals(mail.getName(), mailName);
-            // match no recipient because of the error
-            assertNull(matches);
-            assertNotNull(e);
-            latch.countDown();
-        }
-
-        }
-
-        @Override
-        public void afterMailet(Mailet m, String mailName, String state, long processTime, MessagingException e) {
-        throw new RuntimeException("Should not call any mailet!");
-        }
-    });
-
-    assertEquals(Mail.DEFAULT, mail.getState());
-
-    boolean catched = false;
-    try {
-        processor.service(mail);
-    } catch (MessagingException e) {
-        catched = true;
-    }
-    assertTrue(catched);
-
-    // the source mail should have state error as the exception was thrown
-    assertEquals(Mail.ERROR, mail.getState());
-    latch.await();
-    processor.destroy();
+        final CountDownLatch latch = new CountDownLatch(1);
+        final MailImpl mail = new MailImpl();
+        mail.setName(MailImpl.getId());
+        mail.setSender(new MailAddress("test@localhost"));
+        mail.setRecipients(Arrays.asList(new MailAddress("test@localhost"), new MailAddress("test2@localhost")));
+
+        AbstractStateMailetProcessor processor = createProcessor(createConfig(ExceptionThrowingMatcher.class,
+                MockMailet.class, 0));
+        processor.addListener(new MailetProcessorListener() {
+
+            @Override
+            public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients,
+                                     Collection<MailAddress> matches, long processTime, MessagingException e) {
+                if (ExceptionThrowingMatcher.class.equals(m.getClass())) {
+                    assertEquals(mail.getName(), mailName);
+                    // match no recipient because of the error
+                    assertNull(matches);
+                    assertNotNull(e);
+                    latch.countDown();
+                }
+
+            }
+
+            @Override
+            public void afterMailet(Mailet m, String mailName, String state, long processTime, MessagingException e) {
+                throw new RuntimeException("Should not call any mailet!");
+            }
+        });
+
+        assertEquals(Mail.DEFAULT, mail.getState());
+
+        boolean catched = false;
+        try {
+            processor.service(mail);
+        } catch (MessagingException e) {
+            catched = true;
+        }
+        assertTrue(catched);
+
+        // the source mail should have state error as the exception was thrown
+        assertEquals(Mail.ERROR, mail.getState());
+        latch.await();
+        processor.destroy();
 
     }
 
     @Test
     public void testMailetThrowException() throws Exception {
-    final CountDownLatch latch = new CountDownLatch(2);
-    final MailImpl mail = new MailImpl();
-    mail.setName(MailImpl.getId());
-    mail.setSender(new MailAddress("test@localhost"));
-    mail.setRecipients(Arrays.asList(new MailAddress("test@localhost"), new MailAddress("test2@localhost")));
-
-    AbstractStateMailetProcessor processor = createProcessor(createConfig(MockMatcher.class,
-        ExceptionThrowingMailet.class, 1));
-    processor.addListener(new MailetProcessorListener() {
-
-        @Override
-        public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients,
-                     Collection<MailAddress> matches, long processTime, MessagingException e) {
-        if (MockMatcher.class.equals(m.getClass())) {
-            assertEquals(mail.getName(), mailName);
-            // match one recipient
-            assertEquals(1, matches.size());
-            assertNull(e);
-            latch.countDown();
-        }
-
-        }
-
-        @Override
-        public void afterMailet(Mailet m, String mailName, String state, long processTime, MessagingException e) {
-        if (ExceptionThrowingMailet.class.equals(m.getClass())) {
-            // the name should be not the same as we have a part match
-            assertFalse(mail.getName().equals(mailName));
-            assertNotNull(e);
-            assertEquals(Mail.ERROR, state);
-            latch.countDown();
+        final CountDownLatch latch = new CountDownLatch(2);
+        final MailImpl mail = new MailImpl();
+        mail.setName(MailImpl.getId());
+        mail.setSender(new MailAddress("test@localhost"));
+        mail.setRecipients(Arrays.asList(new MailAddress("test@localhost"), new MailAddress("test2@localhost")));
+
+        AbstractStateMailetProcessor processor = createProcessor(createConfig(MockMatcher.class,
+                ExceptionThrowingMailet.class, 1));
+        processor.addListener(new MailetProcessorListener() {
+
+            @Override
+            public void afterMatcher(Matcher m, String mailName, Collection<MailAddress> recipients,
+                                     Collection<MailAddress> matches, long processTime, MessagingException e) {
+                if (MockMatcher.class.equals(m.getClass())) {
+                    assertEquals(mail.getName(), mailName);
+                    // match one recipient
+                    assertEquals(1, matches.size());
+                    assertNull(e);
+                    latch.countDown();
+                }
+
+            }
+
+            @Override
+            public void afterMailet(Mailet m, String mailName, String state, long processTime, MessagingException e) {
+                if (ExceptionThrowingMailet.class.equals(m.getClass())) {
+                    // the name should be not the same as we have a part match
+                    assertFalse(mail.getName().equals(mailName));
+                    assertNotNull(e);
+                    assertEquals(Mail.ERROR, state);
+                    latch.countDown();
+                }
+            }
+        });
+
+        assertEquals(Mail.DEFAULT, mail.getState());
+
+        boolean catched = false;
+        try {
+            processor.service(mail);
+        } catch (MessagingException e) {
+            catched = true;
         }
-        }
-    });
-
-    assertEquals(Mail.DEFAULT, mail.getState());
-
-    boolean catched = false;
-    try {
-        processor.service(mail);
-    } catch (MessagingException e) {
-        catched = true;
-    }
-    assertTrue(catched);
+        assertTrue(catched);
 
-    latch.await();
-    processor.destroy();
+        latch.await();
+        processor.destroy();
 
     }
 }

Modified: james/server/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/pom.xml?rev=1452015&r1=1452014&r2=1452015&view=diff
==============================================================================
--- james/server/trunk/pom.xml (original)
+++ james/server/trunk/pom.xml Sun Mar  3 07:44:02 2013
@@ -174,6 +174,7 @@
         <karaf.version>2.3.0</karaf.version>
         <karaf.tooling.exam.container.version>2.3.0</karaf.tooling.exam.container.version>
         <pax-logging-api.version>1.6.4</pax-logging-api.version>
+        <mockito-core.version>1.9.0</mockito-core.version>
     </properties>
 
     <dependencyManagement>
@@ -815,6 +816,14 @@
             </dependency>
 
             <dependency>
+                <groupId>org.mockito</groupId>
+                <artifactId>mockito-core</artifactId>
+                <version>${mockito-core.version}</version>
+                <scope>test</scope>
+            </dependency>
+
+
+            <dependency>
                 <groupId>concurrent</groupId>
                 <artifactId>concurrent</artifactId>
                 <version>${concurrent.version}</version>



---------------------------------------------------------------------
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