Author: norman
Date: Thu Oct 19 08:19:58 2006
New Revision: 465657

URL: http://svn.apache.org/viewvc?view=rev&rev=465657
Log:
Add containsDomain to DomainList service. See JAMES-426
Fix junit tests.


Modified:
    james/server/trunk/src/conf/sqlResources.xml
    james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java
    james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java
    james/server/trunk/src/java/org/apache/james/services/DomainList.java
    james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java
    james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java
    james/server/trunk/src/test/org/apache/james/JamesTest.java
    
james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java
    
james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java

Modified: james/server/trunk/src/conf/sqlResources.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/conf/sqlResources.xml?view=diff&rev=465657&r1=465656&r2=465657
==============================================================================
--- james/server/trunk/src/conf/sqlResources.xml (original)
+++ james/server/trunk/src/conf/sqlResources.xml Thu Oct 19 08:19:58 2006
@@ -1002,7 +1002,9 @@
    
     <sql name="addMapping">insert into VirtualUserTable values(?,?,?) </sql>
     
-    <sql name="selectDomains">select domain from VirtualUserTable</sql>
+    <sql name="selectDomains">select distinct domain from 
VirtualUserTable</sql>
+    
+    <sql name="selectDomain">select distinct domain from VirtualUserTable 
where domain = ? </sql>
     
     <!-- Statements used to create the table associated with this class. -->
     <sql name="createTable" db="mysql">

Modified: 
james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java?view=diff&rev=465657&r1=465656&r2=465657
==============================================================================
--- james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java 
Thu Oct 19 08:19:58 2006
@@ -69,7 +69,7 @@
         if (domains.size() > 0 ) {
             for (int i = 0; i < domains.size(); i++) {
                 try {
-                    InetAddress[]  addrs = 
InetAddress.getAllByName(domains.get(i).toString());
+                    InetAddress[]  addrs = 
dns.getAllByName(domains.get(i).toString());
                     for (int j = 0; j < addrs.length ; j++) {
                         domainIP.add(addrs[j].getHostAddress());
                     }

Modified: 
james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java?view=diff&rev=465657&r1=465656&r2=465657
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java 
(original)
+++ 
james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java 
Thu Oct 19 08:19:58 2006
@@ -79,4 +79,11 @@
     protected List getInternalDomainList() {
         return serverNames;
     }
+
+    /**
+     * @see 
org.apache.james.services.DomainList#containsDomain(java.lang.String)
+     */
+    public boolean containsDomain(String domains) {
+        return serverNames.contains(domains);
+    }
 }

Modified: james/server/trunk/src/java/org/apache/james/services/DomainList.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/DomainList.java?view=diff&rev=465657&r1=465656&r2=465657
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/DomainList.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/services/DomainList.java Thu 
Oct 19 08:19:58 2006
@@ -27,9 +27,18 @@
     public final static String ROLE ="org.apache.james.services.DomainList";
     
     /**
-     * Return List of domains which should be used as localdomains
+     * Return List of domains which should be used as localdomains. Return 
null if no
+     * domains were found
      * 
      * @return domains
      */
     public List getDomains();
+    
+    /**
+     * Return true if the domain is 
+     * 
+     * @param domain
+     * @return
+     */
+    public boolean containsDomain(String domain);
 }

Modified: 
james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java?view=diff&rev=465657&r1=465656&r2=465657
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java 
Thu Oct 19 08:19:58 2006
@@ -530,6 +530,37 @@
         } else {
             return domains;
         }
+    }
+
+    /**
+     * @see 
org.apache.james.services.DomainList#containsDomain(java.lang.String)
+     */
+    public boolean containsDomain(String domain) {
+        Connection conn = null;
+        PreparedStatement mappingStmt = null;
+        
+        try {
+            conn = dataSourceComponent.getConnection();
+            mappingStmt = 
conn.prepareStatement(sqlQueries.getSqlString("selectDomain", true));
+
+            ResultSet mappingRS = null;
+            try {
+                mappingStmt.setString(1, domain);
+                mappingRS = mappingStmt.executeQuery();
+                if (mappingRS.next()) {
+                    return true;
+                }
+            } finally {
+                theJDBCUtil.closeJDBCResultSet(mappingRS);
+            }
+            
+        } catch (SQLException sqle) {
+            getLogger().error("Error accessing database", sqle);
+        } finally {
+            theJDBCUtil.closeJDBCStatement(mappingStmt);
+            theJDBCUtil.closeJDBCConnection(conn);
+        }
+        return false;
     } 
 }
 

Modified: 
james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java?view=diff&rev=465657&r1=465656&r2=465657
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java 
Thu Oct 19 08:19:58 2006
@@ -114,4 +114,11 @@
         return domains;
     }
 
+    /**
+     * @see 
org.apache.james.services.DomainList#containsDomain(java.lang.String)
+     */
+    public boolean containsDomain(String domain) {
+    return domains.contains(domain);
+    }
+
 }

Modified: james/server/trunk/src/test/org/apache/james/JamesTest.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/JamesTest.java?view=diff&rev=465657&r1=465656&r2=465657
==============================================================================
--- james/server/trunk/src/test/org/apache/james/JamesTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/JamesTest.java Thu Oct 19 
08:19:58 2006
@@ -104,7 +104,11 @@
                 ArrayList d = new ArrayList();
                 d.add("localhost");
                 return d;
-            }            
+            }
+
+        public boolean containsDomain(String domain) {
+        return getDomains().contains(domain);
+        }            
         });
         MockStore mockStore = new MockStore();
         mockMailRepository = new InMemorySpoolRepository();

Modified: 
james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java?view=diff&rev=465657&r1=465656&r2=465657
==============================================================================
--- 
james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java
 (original)
+++ 
james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java
 Thu Oct 19 08:19:58 2006
@@ -23,6 +23,7 @@
 package org.apache.james.domain;
 
 import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 
 import org.apache.avalon.framework.configuration.Configuration;
@@ -43,10 +44,11 @@
         DefaultConfiguration configuration = new DefaultConfiguration("test");
         DefaultConfiguration sNamesConf = new 
DefaultConfiguration("servernames");
         sNamesConf.setAttribute("autodetect", auto);
+        sNamesConf.setAttribute("autodetectIP", autoIP);
         
         for (int i= 0; i< names.size(); i++) {
             DefaultConfiguration nameConf = new 
DefaultConfiguration("servername");
-            nameConf.setAttribute("autodetectIP", autoIP);
+            
             nameConf.setValue(names.get(i).toString());
             sNamesConf.addChild(nameConf);
         }
@@ -60,6 +62,11 @@
             public String getHostName(InetAddress inet) {
                 return hostName;
             }
+            
+            public InetAddress[] getAllByName(String name) throws 
UnknownHostException {
+        return new InetAddress[] { InetAddress.getByName("127.0.0.1")};
+            
+            }
         };
         return dns;
     }
@@ -72,7 +79,7 @@
     
     public void testGetDomains() throws ConfigurationException, 
ServiceException {
         ArrayList domains = new ArrayList();
-        domains.add("domain1");
+        domains.add("domain1.");
     
         HardCodedDomainList dom = new HardCodedDomainList();
         ContainerUtil.enableLogging(dom,new MockLogger());
@@ -84,7 +91,7 @@
     
     public void testGetDomainsAutoDetectNotLocalHost() throws 
ConfigurationException, ServiceException {
         ArrayList domains = new ArrayList();
-        domains.add("domain1");
+        domains.add("domain1.");
     
         HardCodedDomainList dom = new HardCodedDomainList();
         ContainerUtil.enableLogging(dom,new MockLogger());
@@ -96,7 +103,7 @@
     
     public void testGetDomainsAutoDetectLocalHost() throws 
ConfigurationException, ServiceException {
         ArrayList domains = new ArrayList();
-        domains.add("domain1");
+        domains.add("domain1.");
     
         HardCodedDomainList dom = new HardCodedDomainList();
         ContainerUtil.enableLogging(dom,new MockLogger());

Modified: 
james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java?view=diff&rev=465657&r1=465656&r2=465657
==============================================================================
--- 
james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java
 (original)
+++ 
james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java
 Thu Oct 19 08:19:58 2006
@@ -30,6 +30,7 @@
 public abstract class AbstractVirtualUserTableTest extends TestCase {
 
     protected AbstractVirtualUserTable virtualUserTable;
+    
     protected void setUp() throws Exception {
         virtualUserTable = getVirtalUserTable();
     }
@@ -59,8 +60,10 @@
 
             assertTrue("Two mappings",virtualUserTable.getMappings(user, 
domain).size() == 2);
             
+            // Test DomainList implementations!
             assertEquals("One domain",virtualUserTable.getDomains().size(), 1);
-        
+            assertTrue("Contains 
Domain",virtualUserTable.containsDomain(domain));
+            
             assertTrue("remove virtual mapping", 
virtualUserTable.removeRegexMapping(user, domain, regex));
         
             try {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to