james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [2/4] james-project git commit: JAMES-1735 getDomains returns a List instead of an array
Date Wed, 18 May 2016 06:21:39 GMT
JAMES-1735 getDomains returns a List instead of an array


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/26349aa1
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/26349aa1
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/26349aa1

Branch: refs/heads/master
Commit: 26349aa1059a529d283f89cbf52e3e154e1775ff
Parents: e0641d5
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Tue May 10 15:00:40 2016 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Tue May 17 14:47:10 2016 +0200

----------------------------------------------------------------------
 .../org/apache/james/cli/probe/ServerProbe.java |  3 +-
 .../james/cli/probe/impl/JmxServerProbe.java    |  3 +-
 .../org/apache/james/cli/ServerCmdTest.java     |  5 +-
 .../apache/james/utils/GuiceServerProbe.java    |  2 +-
 .../apache/james/domainlist/api/DomainList.java |  4 +-
 .../api/DomainListManagementMBean.java          |  4 +-
 .../james/domainlist/xml/XMLDomainListTest.java | 12 +++--
 .../james/domainlist/jpa/JPADomainList.java     | 19 ++++---
 .../domainlist/lib/AbstractDomainList.java      | 10 +---
 .../domainlist/lib/DomainListManagement.java    |  8 ++-
 .../domainlist/api/mock/SimpleDomainList.java   |  6 ++-
 .../domainlist/lib/AbstractDomainListTest.java  | 14 +++--
 .../impl/JamesMailetContext.java                | 56 ++++++++++----------
 13 files changed, 75 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
b/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
index 78e665f..bb63bde 100644
--- a/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
+++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
@@ -20,6 +20,7 @@ package org.apache.james.cli.probe;
 
 import java.io.Closeable;
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.james.rrt.lib.Mappings;
@@ -100,7 +101,7 @@ public interface ServerProbe extends Closeable {
      * @return domains an array of domains, or null if no domains exist.
      * @throws Exception
      */
-    String[] listDomains() throws Exception;
+    List<String> listDomains() throws Exception;
 
     /**
      * Get a Map which holds all mappings. The key is the user@domain and the

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
index 4a7dee0..e06c24c 100644
--- a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
+++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
@@ -20,6 +20,7 @@ package org.apache.james.cli.probe.impl;
 
 import java.io.IOException;
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 
 import javax.management.MBeanServerConnection;
@@ -177,7 +178,7 @@ public class JmxServerProbe implements ServerProbe {
     }
 
     @Override
-    public String[] listDomains() throws Exception {
+    public List<String> listDomains() throws Exception {
         return domainListProcxy.getDomains();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java b/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
index ebbbe54..b406912 100644
--- a/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
+++ b/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
@@ -44,6 +44,8 @@ import org.easymock.IMocksControl;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
+
 public class ServerCmdTest {
 
     public static final String ADDITIONAL_ARGUMENT = "additionalArgument";
@@ -106,8 +108,7 @@ public class ServerCmdTest {
         String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.LISTDOMAINS.getCommand()};
         CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
 
-        String[] res = {};
-        expect(serverProbe.listDomains()).andReturn(res);
+        expect(serverProbe.listDomains()).andReturn(ImmutableList.<String> of());
 
         control.replay();
         testee.executeCommandLine(commandLine);

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java
b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java
index 06ce5df..fc8e9bd 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java
@@ -123,7 +123,7 @@ public class GuiceServerProbe implements ExtendedServerProbe {
     }
 
     @Override
-    public String[] listDomains() throws Exception {
+    public List<String> listDomains() throws Exception {
         return domainList.getDomains();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/data/data-api/src/main/java/org/apache/james/domainlist/api/DomainList.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/domainlist/api/DomainList.java
b/server/data/data-api/src/main/java/org/apache/james/domainlist/api/DomainList.java
index 4752503..fd22361 100644
--- a/server/data/data-api/src/main/java/org/apache/james/domainlist/api/DomainList.java
+++ b/server/data/data-api/src/main/java/org/apache/james/domainlist/api/DomainList.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.domainlist.api;
 
+import java.util.List;
+
 /**
  * This interface should be implemented by services which offer domains for
  * which email will accepted.
@@ -30,7 +32,7 @@ public interface DomainList {
      * 
      * @return domains
      */
-    String[] getDomains() throws DomainListException;
+    List<String> getDomains() throws DomainListException;
 
     /**
      * Return true if the domain exists in the service

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/data/data-api/src/main/java/org/apache/james/domainlist/api/DomainListManagementMBean.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/domainlist/api/DomainListManagementMBean.java
b/server/data/data-api/src/main/java/org/apache/james/domainlist/api/DomainListManagementMBean.java
index 6e3689a..f823d93 100644
--- a/server/data/data-api/src/main/java/org/apache/james/domainlist/api/DomainListManagementMBean.java
+++ b/server/data/data-api/src/main/java/org/apache/james/domainlist/api/DomainListManagementMBean.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.domainlist.api;
 
+import java.util.List;
+
 /**
  * JMX MBean for DomainList
  */
@@ -29,7 +31,7 @@ public interface DomainListManagementMBean {
      * 
      * @return domains
      */
-    String[] getDomains() throws Exception;
+    List<String> getDomains() throws Exception;
 
     /**
      * Return true if the domain exists in the service

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/data/data-file/src/test/java/org/apache/james/domainlist/xml/XMLDomainListTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/test/java/org/apache/james/domainlist/xml/XMLDomainListTest.java
b/server/data/data-file/src/test/java/org/apache/james/domainlist/xml/XMLDomainListTest.java
index 237eb14..5d14c11 100644
--- a/server/data/data-file/src/test/java/org/apache/james/domainlist/xml/XMLDomainListTest.java
+++ b/server/data/data-file/src/test/java/org/apache/james/domainlist/xml/XMLDomainListTest.java
@@ -18,15 +18,17 @@
  ****************************************************************/
 package org.apache.james.domainlist.xml;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
+
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.dnsservice.api.mock.MockDNSService;
-import static org.junit.Assert.*;
 import org.junit.Test;
 import org.slf4j.LoggerFactory;
 
@@ -72,7 +74,7 @@ public class XMLDomainListTest {
         dom.configure(setUpConfiguration(false, false, domains));
         dom.setDNSService(setUpDNSServer("localhost"));
 
-        assertNull("No domain found", dom.getDomains());
+        assertThat(dom.getDomains()).describedAs("No domain found").isEmpty();
     }
 
     @Test
@@ -86,7 +88,7 @@ public class XMLDomainListTest {
         dom.configure(setUpConfiguration(false, false, domains));
         dom.setDNSService(setUpDNSServer("localhost"));
 
-        assertTrue("Two domain found", dom.getDomains().length == 2);
+        assertThat(dom.getDomains()).describedAs("Two domain found").hasSize(2);
     }
 
     @Test
@@ -99,7 +101,7 @@ public class XMLDomainListTest {
         dom.configure(setUpConfiguration(true, false, domains));
 
         dom.setDNSService(setUpDNSServer("local"));
-        assertEquals("Two domains found", dom.getDomains().length, 2);
+        assertThat(dom.getDomains()).describedAs("Two domains found").hasSize(2);
     }
 
     @Test
@@ -113,6 +115,6 @@ public class XMLDomainListTest {
 
         dom.setDNSService(setUpDNSServer("localhost"));
 
-        assertEquals("One domain found", dom.getDomains().length, 1);
+        assertThat(dom.getDomains()).describedAs("One domain found").hasSize(1);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/data/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
----------------------------------------------------------------------
diff --git a/server/data/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
b/server/data/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
index 2672dd0..f5cde85 100644
--- a/server/data/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
+++ b/server/data/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
@@ -18,9 +18,8 @@
  ****************************************************************/
 package org.apache.james.domainlist.jpa;
 
-import org.apache.james.domainlist.api.DomainListException;
-import org.apache.james.domainlist.jpa.model.JPADomain;
-import org.apache.james.domainlist.lib.AbstractDomainList;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.annotation.PostConstruct;
 import javax.persistence.EntityManager;
@@ -29,8 +28,12 @@ import javax.persistence.EntityTransaction;
 import javax.persistence.NoResultException;
 import javax.persistence.PersistenceException;
 import javax.persistence.PersistenceUnit;
-import java.util.ArrayList;
-import java.util.List;
+
+import org.apache.james.domainlist.api.DomainListException;
+import org.apache.james.domainlist.jpa.model.JPADomain;
+import org.apache.james.domainlist.lib.AbstractDomainList;
+
+import com.google.common.collect.ImmutableList;
 
 /**
  * JPA implementation of the DomainList.<br>
@@ -76,11 +79,7 @@ public class JPADomainList extends AbstractDomainList {
         } finally {
             entityManager.close();
         }
-        if (domains.size() == 0) {
-            return null;
-        } else {
-            return new ArrayList<String>(domains);
-        }
+        return ImmutableList.copyOf(domains);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
index c191cce..739a980 100644
--- a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
+++ b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
@@ -78,7 +78,7 @@ public abstract class AbstractDomainList implements DomainList, LogEnabled,
Conf
     }
 
     @Override
-    public String[] getDomains() throws DomainListException {
+    public List<String> getDomains() throws DomainListException {
         List<String> domains = getDomainListInternal();
         if (domains != null) {
 
@@ -104,14 +104,8 @@ public abstract class AbstractDomainList implements DomainList, LogEnabled,
Conf
                     getLogger().debug("Handling mail for: " + domain);
                 }
             }
-            if (domains.isEmpty()) {
-                return null;
-            } else {
-                return domains.toArray(new String[domains.size()]);
-            }
-        } else {
-            return null;
         }
+        return domains;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/DomainListManagement.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/DomainListManagement.java
b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/DomainListManagement.java
index 7c0f4e9..83a433f 100644
--- a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/DomainListManagement.java
+++ b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/DomainListManagement.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.domainlist.lib;
 
+import java.util.List;
+
 import javax.inject.Inject;
 import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
@@ -26,6 +28,8 @@ import org.apache.james.domainlist.api.DomainList;
 import org.apache.james.domainlist.api.DomainListException;
 import org.apache.james.domainlist.api.DomainListManagementMBean;
 
+import com.google.common.collect.ImmutableList;
+
 public class DomainListManagement extends StandardMBean implements DomainListManagementMBean
{
 
     private DomainList domainList;
@@ -60,9 +64,9 @@ public class DomainListManagement extends StandardMBean implements DomainListMan
     }
 
     @Override
-    public String[] getDomains() throws Exception {
+    public List<String> getDomains() throws Exception {
         try {
-            return domainList.getDomains();
+            return ImmutableList.copyOf(domainList.getDomains());
         }
         catch (DomainListException e) {
             throw new Exception(e.getMessage());

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/data/data-library/src/test/java/org/apache/james/domainlist/api/mock/SimpleDomainList.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/domainlist/api/mock/SimpleDomainList.java
b/server/data/data-library/src/test/java/org/apache/james/domainlist/api/mock/SimpleDomainList.java
index f992731..195d68e 100644
--- a/server/data/data-library/src/test/java/org/apache/james/domainlist/api/mock/SimpleDomainList.java
+++ b/server/data/data-library/src/test/java/org/apache/james/domainlist/api/mock/SimpleDomainList.java
@@ -24,6 +24,8 @@ import java.util.List;
 import org.apache.james.domainlist.api.DomainList;
 import org.apache.james.domainlist.api.DomainListException;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * Simplest implementation for ManageableDomainList
  */
@@ -37,8 +39,8 @@ public class SimpleDomainList implements DomainList {
     }
 
     @Override
-    public String[] getDomains() throws DomainListException {
-        return domains.toArray(new String[domains.size()]);
+    public List<String> getDomains() throws DomainListException {
+        return ImmutableList.copyOf(domains);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
b/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
index 58f9d32..31320f2 100644
--- a/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/AbstractDomainListTest.java
@@ -80,14 +80,14 @@ public abstract class AbstractDomainListTest {
 
     @Test
     public void listDomainsShouldReturnNullWhenThereIsNoDomains() throws DomainListException
{
-        assertThat(domainList.getDomains()).isNull();
+        assertThat(domainList.getDomains()).isEmpty();
     }
 
     @Test
     public void testAddRemoveContainsSameDomain() throws DomainListException {
         domainList.addDomain(DOMAIN_1);
         domainList.removeDomain(DOMAIN_1);
-        assertThat(domainList.getDomains()).isNull();
+        assertThat(domainList.getDomains()).isEmpty();
     }
 
     @Test(expected = DomainListException.class)
@@ -155,12 +155,10 @@ public abstract class AbstractDomainListTest {
     /**
      * Delete all possible domains from database.
      */
-    private void deleteAll() {
-        deleteWithoutError(DOMAIN_1);
-        deleteWithoutError(DOMAIN_2);
-        deleteWithoutError(DOMAIN_3);
-        deleteWithoutError(DOMAIN_4);
-        deleteWithoutError(DOMAIN_5);
+    private void deleteAll() throws DomainListException {
+        for (String domain : domainList.getDomains()) {
+            deleteWithoutError(domain);
+        }
     }
 
     private void deleteWithoutError(String domain) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/26349aa1/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
index 76bc6e7..732a303 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
@@ -19,6 +19,27 @@
 
 package org.apache.james.mailetcontainer.impl;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Vector;
+
+import javax.inject.Inject;
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.ParseException;
+
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.core.MailImpl;
@@ -41,26 +62,6 @@ import org.apache.mailet.MailetContext;
 import org.apache.mailet.base.RFC2822Headers;
 import org.slf4j.Logger;
 
-import javax.inject.Inject;
-import javax.mail.Address;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.ParseException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Vector;
-
 @SuppressWarnings("deprecation")
 public class JamesMailetContext implements MailetContext, LogEnabled, Configurable {
 
@@ -456,17 +457,14 @@ public class JamesMailetContext implements MailetContext, LogEnabled,
Configurab
                 // loop through candidate domains until we find one or exhaust
                 // the
                 // list
-                String[] doms = domains.getDomains();
-                if (doms != null) {
-                    for (String dom : doms) {
-                        String serverName = dom.toLowerCase(Locale.US);
-                        if (!("localhost".equals(serverName))) {
-                            domainName = serverName; // ok, not localhost, so
-                            // use it
-                        }
+                for (String dom : domains.getDomains()) {
+                    String serverName = dom.toLowerCase(Locale.US);
+                    if (!("localhost".equals(serverName))) {
+                        domainName = serverName; // ok, not localhost, so
+                        // use it
                     }
-
                 }
+
                 // if we found a suitable domain, use it. Otherwise fallback to
                 // the
                 // host name.


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