james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject svn commit: r1711986 - in /james/project/trunk/server: container/cli/src/main/java/org/apache/james/cli/ data/data-api/src/main/java/org/apache/james/rrt/lib/ data/data-file/src/test/java/org/apache/james/rrt/file/ data/data-hbase/src/main/java/org/apa...
Date Mon, 02 Nov 2015 13:47:10 GMT
Author: matthieu
Date: Mon Nov  2 13:47:09 2015
New Revision: 1711986

URL: http://svn.apache.org/viewvc?rev=1711986&view=rev
Log:
JAMES-1595 move RecipientRewriteTableUtil.CollectionToMapping to Mappings.serialize

Removed:
    james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RecipientRewriteTableUtilTest.java
Modified:
    james/project/trunk/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
    james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
    james/project/trunk/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
    james/project/trunk/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
    james/project/trunk/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
    james/project/trunk/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
    james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
    james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
    james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableUtil.java
    james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
    james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java
    james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/mock/MockRecipientRewriteTableManagementImpl.java

Modified: james/project/trunk/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
(original)
+++ james/project/trunk/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
Mon Nov  2 13:47:09 2015
@@ -314,7 +314,7 @@ public class ServerCmd {
     private void print(Map<String, Mappings> map, PrintStream out) {
         if (map != null) {
             for (Entry<String, Mappings> entry : map.entrySet()) {
-                out.println(entry.getKey() + '=' + entry.getValue().asStrings().toString());
+                out.println(entry.getKey() + '=' + entry.getValue().serialize());
             }
             out.println();
         }

Modified: james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
(original)
+++ james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
Mon Nov  2 13:47:09 2015
@@ -33,4 +33,6 @@ public interface Mappings extends Iterab
 
     Iterable<String> asStrings();
     
+    String serialize();
+    
 }
\ No newline at end of file

Modified: james/project/trunk/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
(original)
+++ james/project/trunk/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
Mon Nov  2 13:47:09 2015
@@ -29,7 +29,6 @@ import org.apache.james.rrt.lib.Abstract
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 import org.apache.james.rrt.lib.MappingsImpl.Builder;
-import org.apache.james.rrt.lib.RecipientRewriteTableUtil;
 import org.junit.Before;
 import org.slf4j.LoggerFactory;
 
@@ -81,8 +80,7 @@ public class XMLRecipientRewriteTableTes
         Mappings updatedMappings = builder.build();
         
         if (!updatedMappings.isEmpty()) {
-            defaultConfiguration.addProperty("mapping", user + "@" + domain + "=" + RecipientRewriteTableUtil.
-                    CollectionToMapping(updatedMappings.asStrings()));
+            defaultConfiguration.addProperty("mapping", user + "@" + domain + "=" + updatedMappings.serialize());
         }
 
         try {
@@ -118,8 +116,7 @@ public class XMLRecipientRewriteTableTes
         }
 
         if (mappings.size() > 0) {
-            defaultConfiguration.addProperty("mapping", user + "@" + domain + "=" + RecipientRewriteTableUtil.
-                    CollectionToMapping(mappings.asStrings()));
+            defaultConfiguration.addProperty("mapping", user + "@" + domain + "=" + mappings.serialize());
         }
 
         try {
@@ -133,7 +130,7 @@ public class XMLRecipientRewriteTableTes
     private void removeMappingsFromConfig(String user, String domain, Mappings mappings)
{
         List<String> stored = new ArrayList<String>();
         for (String c : defaultConfiguration.getStringArray("mapping")) {
-            String mapping = user + "@" + domain + "=" + RecipientRewriteTableUtil.CollectionToMapping(mappings.asStrings());
+            String mapping = user + "@" + domain + "=" + mappings.serialize();
             if (!c.equalsIgnoreCase(mapping)) {
                 stored.add(c);
             }

Modified: james/project/trunk/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
(original)
+++ james/project/trunk/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
Mon Nov  2 13:47:09 2015
@@ -37,7 +37,6 @@ import org.apache.james.rrt.hbase.def.HR
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
-import org.apache.james.rrt.lib.RecipientRewriteTableUtil;
 import org.apache.james.system.hbase.TablePool;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -65,7 +64,7 @@ public class HBaseRecipientRewriteTable
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
         if (map != null && map.size() != 0) {
             Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build();
-            doUpdateMapping(fixedUser, fixedDomain, RecipientRewriteTableUtil.CollectionToMapping(updatedMappings.asStrings()));
+            doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
             doAddMapping(fixedUser, fixedDomain, mapping);
         }
@@ -215,7 +214,7 @@ public class HBaseRecipientRewriteTable
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
         if (map != null && map.size() > 1) {
             Mappings updatedMappings = map.remove(mapping);
-            doUpdateMapping(fixedUser, fixedDomain, RecipientRewriteTableUtil.CollectionToMapping(updatedMappings.asStrings()));
+            doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
             doRemoveMapping(fixedUser, fixedDomain, mapping);
         }

Modified: james/project/trunk/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
(original)
+++ james/project/trunk/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
Mon Nov  2 13:47:09 2015
@@ -40,7 +40,6 @@ import org.apache.james.rrt.api.Recipien
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
-import org.apache.james.rrt.lib.RecipientRewriteTableUtil;
 import org.apache.james.util.sql.JDBCUtil;
 import org.apache.james.util.sql.SqlResources;
 
@@ -210,7 +209,7 @@ public class JDBCRecipientRewriteTable e
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
         if (map != null && map.size() != 0) {
             Mappings updatedMappings = MappingsImpl.from(map).add(regex).build();
-            doUpdateMapping(fixedUser, fixedDomain, RecipientRewriteTableUtil.CollectionToMapping(updatedMappings.asStrings()));
+            doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         }
         doAddMapping(fixedUser, fixedDomain, regex);
     }
@@ -327,7 +326,7 @@ public class JDBCRecipientRewriteTable e
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
         if (map != null && map.size() > 1) {
             Mappings updatedMappings = map.remove(mapping);
-            doUpdateMapping(fixedUser, fixedDomain, RecipientRewriteTableUtil.CollectionToMapping(updatedMappings.asStrings()));
+            doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
             doRemoveMapping(fixedUser, fixedDomain, mapping);
         }

Modified: james/project/trunk/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
(original)
+++ james/project/trunk/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
Mon Nov  2 13:47:09 2015
@@ -33,7 +33,6 @@ import org.apache.james.rrt.jpa.model.JP
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
-import org.apache.james.rrt.lib.RecipientRewriteTableUtil;
 
 /**
  * Class responsible to implement the Virtual User Table in database with JPA
@@ -66,7 +65,7 @@ public class JPARecipientRewriteTable ex
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
         if (map != null && map.size() != 0) {
             Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build();
-            doUpdateMapping(fixedUser, fixedDomain, RecipientRewriteTableUtil.CollectionToMapping(updatedMappings.asStrings()));
+            doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
             doAddMapping(fixedUser, fixedDomain, mapping);
         }
@@ -166,7 +165,7 @@ public class JPARecipientRewriteTable ex
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
         if (map != null && map.size() > 1) {
             Mappings updatedMappings = map.remove(mapping);
-            doUpdateMapping(fixedUser, fixedDomain, RecipientRewriteTableUtil.CollectionToMapping(updatedMappings.asStrings()));
+            doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
             doRemoveMapping(fixedUser, fixedDomain, mapping);
         }

Modified: james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
(original)
+++ james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
Mon Nov  2 13:47:09 2015
@@ -467,7 +467,7 @@ public abstract class AbstractRecipientR
                     col.add(mapping);
                 }
             }
-            return RecipientRewriteTableUtil.CollectionToMapping(col);
+            return MappingsImpl.fromCollection(col).serialize();
         } else {
             return mappings;
         }

Modified: james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
(original)
+++ james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
Mon Nov  2 13:47:09 2015
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.StringTokenizer;
 
 import com.google.common.base.Function;
+import com.google.common.base.Joiner;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
@@ -138,5 +139,10 @@ public class MappingsImpl implements Map
     public Iterator<Mapping> iterator() {
         return mappings.iterator();
     }
+    
+    @Override
+    public String serialize() {
+        return Joiner.on(';').join(asStrings());
+    }
 
 }
\ No newline at end of file

Modified: james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableUtil.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableUtil.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableUtil.java
(original)
+++ james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableUtil.java
Mon Nov  2 13:47:09 2015
@@ -211,15 +211,4 @@ public class RecipientRewriteTableUtil {
         return mappings;
     }
 
-    /**
-     * Convert a Collection which holds mappings to a raw mapping String
-     * 
-     * @param map
-     *            the Collection
-     * @return mapping the mapping String
-     */
-    public static String CollectionToMapping(Iterable<String> map) {
-        return Joiner.on(';').join(map);
-    }
-
 }

Modified: james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
(original)
+++ james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
Mon Nov  2 13:47:09 2015
@@ -320,7 +320,7 @@ public abstract class AbstractRecipientR
     public void sortMappingsShouldReturnSameStringWhenTwoDomainAliases() {
         String firstAliasMapping = RecipientRewriteTable.ALIASDOMAIN_PREFIX + "first";
         String secondAliasMapping = RecipientRewriteTable.ALIASDOMAIN_PREFIX + "second";
-        String mappings = RecipientRewriteTableUtil.CollectionToMapping(Arrays.asList(firstAliasMapping,
secondAliasMapping));
+        String mappings = MappingsImpl.fromCollection(Arrays.asList(firstAliasMapping, secondAliasMapping)).serialize();
         assertEquals(mappings, AbstractRecipientRewriteTable.sortMappings(mappings));
     }
     
@@ -328,8 +328,8 @@ public abstract class AbstractRecipientR
     public void sortMappingsShouldPutDomainAliasFirstWhenVariousMappings() {
         String regexMapping = RecipientRewriteTable.REGEX_PREFIX + "first";
         String domainMapping = RecipientRewriteTable.ALIASDOMAIN_PREFIX + "second";
-        String inputMappings = RecipientRewriteTableUtil.CollectionToMapping(Arrays.asList(regexMapping,
domainMapping));
-        String expectedMappings = RecipientRewriteTableUtil.CollectionToMapping(Arrays.asList(domainMapping,
regexMapping));
+        String inputMappings = MappingsImpl.fromCollection(Arrays.asList(regexMapping, domainMapping)).serialize();
+        String expectedMappings = MappingsImpl.fromCollection(Arrays.asList(domainMapping,
regexMapping)).serialize();
         assertEquals(expectedMappings, AbstractRecipientRewriteTable.sortMappings(inputMappings));
     }
 

Modified: james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java
(original)
+++ james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingsImplTest.java
Mon Nov  2 13:47:09 2015
@@ -119,5 +119,22 @@ public class MappingsImplTest {
         assertThat(actual).containsExactly(MappingImpl.of("regex:test"));
     }
 
+    @Test
+    public void serializeShouldReturnEmptyStringWhenEmpty() {
+        assertThat(MappingsImpl.empty()).isEmpty();
+    }
+
+    @Test
+    public void serializeShouldReturnSimpleValueWhenSingleElement() {
+        String actual = MappingsImpl.builder().add("value").build().serialize();
+        assertThat(actual).isEqualTo("value");
+    }
+
+    @Test
+    public void collectionToMappingShouldReturnSeparatedValuesWhenSeveralElementsCollection()
{
+        String actual = MappingsImpl.builder().add("value1").add("value2").build().serialize();
+        assertThat(actual).isEqualTo("value1;value2");
+    }
+
     
 }

Modified: james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/mock/MockRecipientRewriteTableManagementImpl.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/mock/MockRecipientRewriteTableManagementImpl.java?rev=1711986&r1=1711985&r2=1711986&view=diff
==============================================================================
--- james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/mock/MockRecipientRewriteTableManagementImpl.java
(original)
+++ james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/mock/MockRecipientRewriteTableManagementImpl.java
Mon Nov  2 13:47:09 2015
@@ -25,7 +25,6 @@ import org.apache.james.rrt.api.Recipien
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
-import org.apache.james.rrt.lib.RecipientRewriteTableUtil;
 
 public class MockRecipientRewriteTableManagementImpl implements RecipientRewriteTable {
 
@@ -119,7 +118,7 @@ public class MockRecipientRewriteTableMa
                 throw new RecipientRewriteTableException("Mapping " + mapping + " already
exist!");
             } else {
                 Mappings updateMappings = MappingsImpl.from(map).add(mapping).build();
-                store.put(key, RecipientRewriteTableUtil.CollectionToMapping(updateMappings.asStrings()));
+                store.put(key, updateMappings.serialize());
             }
         } else {
             store.put(key, mapping);
@@ -133,7 +132,7 @@ public class MockRecipientRewriteTableMa
         if (mappings != null) {
             map = MappingsImpl.fromRawString(mappings);
             if (map.contains(mapping)) {
-                store.put(key, RecipientRewriteTableUtil.CollectionToMapping(map.remove(mapping).asStrings()));
+                store.put(key, map.remove(mapping).serialize());
             }
         }
         throw new RecipientRewriteTableException("Mapping does not exist");



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