JAMES-1904 Default domain should be created with XMLDomainList

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

Branch: refs/heads/master
Commit: b0d35b70bcefd27ba7f46627183a7758bdc20408
Parents: 3e5a16d
Author: Antoine Duprat <adup...@linagora.com>
Authored: Wed Apr 19 14:17:14 2017 +0200
Committer: benwa <btell...@linagora.com>
Committed: Thu Apr 20 07:47:38 2017 +0700

----------------------------------------------------------------------
 .../james/domainlist/xml/XMLDomainList.java     | 24 +++++++++++++-------
 .../james/domainlist/xml/XMLDomainListTest.java | 17 ++++++++++++++
 2 files changed, 33 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b0d35b70/server/data/data-file/src/main/java/org/apache/james/domainlist/xml/XMLDomainList.java
----------------------------------------------------------------------
diff --git 
a/server/data/data-file/src/main/java/org/apache/james/domainlist/xml/XMLDomainList.java
 
b/server/data/data-file/src/main/java/org/apache/james/domainlist/xml/XMLDomainList.java
index 1fd705a..34376a9 100644
--- 
a/server/data/data-file/src/main/java/org/apache/james/domainlist/xml/XMLDomainList.java
+++ 
b/server/data/data-file/src/main/java/org/apache/james/domainlist/xml/XMLDomainList.java
@@ -19,18 +19,18 @@
 
 package org.apache.james.domainlist.xml;
 
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.james.domainlist.api.DomainListException;
-import org.apache.james.domainlist.lib.AbstractDomainList;
-import org.apache.james.lifecycle.api.Configurable;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 
 import javax.inject.Singleton;
 
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.domainlist.api.DomainListException;
+import org.apache.james.domainlist.lib.AbstractDomainList;
+import org.apache.james.lifecycle.api.Configurable;
+
 /**
  * Mimic the old behavior of JAMES
  */
@@ -38,6 +38,7 @@ import javax.inject.Singleton;
 public class XMLDomainList extends AbstractDomainList implements Configurable {
 
     private final List<String> domainNames = new ArrayList<String>();
+    private boolean isConfigured = false;
 
     @Override
     public void configure(HierarchicalConfiguration config) throws 
ConfigurationException {
@@ -49,6 +50,7 @@ public class XMLDomainList extends AbstractDomainList 
implements Configurable {
                 throw new ConfigurationException("Unable to add domain to 
memory", e);
             }
         }
+        isConfigured = true;
     }
 
     @Override
@@ -63,12 +65,18 @@ public class XMLDomainList extends AbstractDomainList 
implements Configurable {
 
     @Override
     public void addDomain(String domain) throws DomainListException {
-        throw new DomainListException("Read-Only DomainList implementation");
+        if (isConfigured) {
+            throw new DomainListException("Read-Only DomainList 
implementation");
+        }
+        domainNames.add(domain);
     }
 
     @Override
     public void removeDomain(String domain) throws DomainListException {
-        throw new DomainListException("Read-Only DomainList implementation");
+        if (isConfigured) {
+            throw new DomainListException("Read-Only DomainList 
implementation");
+        }
+        domainNames.remove(domain);
     }
 
     private void addToServedDomains(String domain) throws DomainListException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/b0d35b70/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 15a07ff..d8412a8 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
@@ -48,6 +48,7 @@ public class XMLDomainListTest {
         for (String name : names) {
             configuration.addProperty("domainnames.domainname", name);
         }
+        configuration.addProperty("defaultDomain", "default.domain");
         return configuration;
     }
 
@@ -151,4 +152,20 @@ public class XMLDomainListTest {
 
         testee.removeDomain("newDomain");
     }
+
+    @Test
+    public void configureShouldNotFailWhenConfiguringDefaultDomain() throws 
Exception {
+        DefaultConfigurationBuilder configuration = new 
DefaultConfigurationBuilder();
+
+        configuration.addProperty("autodetect", true);
+        configuration.addProperty("autodetectIP", false);
+        configuration.addProperty("domainnames.domainname", "domain1");
+        configuration.addProperty("defaultDomain", "localhost");
+
+        XMLDomainList testee = new XMLDomainList();
+        testee.setLog(LoggerFactory.getLogger("MockLog"));
+        testee.configure(configuration);
+
+        assertThat(testee.getDomainListInternal()).hasSize(2);
+    }
 }


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

Reply via email to