james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [08/24] james-project git commit: JAMES-2366 getAllMappingsInternal should not return null
Date Fri, 20 Apr 2018 02:12:53 GMT
JAMES-2366 getAllMappingsInternal should not return null


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

Branch: refs/heads/master
Commit: f7d515c83e1565c8e065e488f1464824f2ab1bd8
Parents: 57fa4c4
Author: benwa <btellier@linagora.com>
Authored: Fri Apr 6 09:56:26 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Apr 19 11:12:07 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/cli/DataCommandsIntegrationTest.java |  4 ++--
 .../rrt/cassandra/CassandraRecipientRewriteTable.java     |  3 +--
 .../apache/james/rrt/file/XMLRecipientRewriteTable.java   |  3 ++-
 .../apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java  |  4 +++-
 .../apache/james/rrt/jpa/JPARecipientRewriteTable.java    |  4 +++-
 .../james/rrt/lib/AbstractRecipientRewriteTable.java      |  6 +-----
 .../james/rrt/lib/AbstractRecipientRewriteTableTest.java  | 10 +++++-----
 .../james/rrt/memory/MemoryRecipientRewriteTable.java     |  3 ---
 8 files changed, 17 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f7d515c8/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
b/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
index 9c46c2a..03c29c2 100644
--- a/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
@@ -177,7 +177,7 @@ public class DataCommandsIntegrationTest {
         ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "removeaddressmapping",
USER, DOMAIN, redirectionAddress});
 
         assertThat(dataProbe.listMappings())
-            .isNull();
+            .isEmpty();
     }
 
     @Test
@@ -202,7 +202,7 @@ public class DataCommandsIntegrationTest {
         ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "removeregexmapping",
USER, DOMAIN, regex});
 
         assertThat(dataProbe.listMappings())
-            .isNull();
+            .isEmpty();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7d515c8/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
index 863857f..ef8a649 100644
--- a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
@@ -131,7 +131,7 @@ public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTabl
 
     @Override
     protected Map<String, Mappings> getAllMappingsInternal() {
-        Map<String, Mappings> map = executor.execute(retrieveAllMappingsStatement.bind())
+        return executor.execute(retrieveAllMappingsStatement.bind())
             .thenApply(resultSet -> cassandraUtils.convertToStream(resultSet)
                 .map(row -> new UserMapping(row.getString(USER), Domain.of(row.getString(DOMAIN)),
row.getString(MAPPING)))
                 .collect(Guavate.toImmutableMap(
@@ -139,7 +139,6 @@ public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTabl
                     UserMapping::toMapping,
                     Mappings::union)))
             .join();
-        return map.isEmpty() ? null : map;
     }
 
     private static class UserMapping {

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7d515c8/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
b/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
index 31bbb6c..9df10a6 100644
--- a/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
+++ b/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
@@ -32,6 +32,7 @@ import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 import org.apache.james.rrt.lib.RecipientRewriteTableUtil;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 
 /**
@@ -88,7 +89,7 @@ public class XMLRecipientRewriteTable extends AbstractRecipientRewriteTable
{
             }
             return mappingsNew;
         } else {
-            return null;
+            return ImmutableMap.of();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7d515c8/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
b/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
index 64b6a49..8a2e235 100644
--- a/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
+++ b/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
@@ -47,6 +47,8 @@ import org.apache.james.util.sql.SqlResources;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.ImmutableMap;
+
 /**
  * Class responsible to implement the Virtual User Table in database with JDBC
  * access.
@@ -285,7 +287,7 @@ public class JDBCRecipientRewriteTable extends AbstractRecipientRewriteTable
{
             theJDBCUtil.closeJDBCStatement(mappingStmt);
             theJDBCUtil.closeJDBCConnection(conn);
         }
-        return null;
+        return ImmutableMap.of();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7d515c8/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
b/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
index 7740bf6..566b3d7 100644
--- a/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
+++ b/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
@@ -39,6 +39,8 @@ import org.apache.james.rrt.lib.MappingsImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.ImmutableMap;
+
 /**
  * Class responsible to implement the Virtual User Table in database with JPA
  * access.
@@ -165,7 +167,7 @@ public class JPARecipientRewriteTable extends AbstractRecipientRewriteTable
{
         } finally {
             entityManager.close();
         }
-        return null;
+        return ImmutableMap.of();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7d515c8/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
index 873a9d4..b5d1f4f 100644
--- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
+++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
@@ -304,11 +304,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
     public Map<String, Mappings> getAllMappings() throws RecipientRewriteTableException
{
         Map<String, Mappings> mappings = getAllMappingsInternal();
 
-        int count = Optional.ofNullable(mappings)
-            .map(Map::size)
-            .orElse(0);
-
-        LOGGER.debug("Retrieve all mappings. Mapping count: {}", count);
+        LOGGER.debug("Retrieve all mappings. Mapping count: {}", mappings.size());
         return mappings;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7d515c8/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
index f779524..396649f 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
@@ -112,7 +112,7 @@ public abstract class AbstractRecipientRewriteTableTest {
 
         assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
-        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
+        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
     }
 
     @Test
@@ -162,7 +162,7 @@ public abstract class AbstractRecipientRewriteTableTest {
 
         assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
-        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
+        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
     }
 
     @Test
@@ -186,7 +186,7 @@ public abstract class AbstractRecipientRewriteTableTest {
 
         assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
             .isEqualTo(MappingsImpl.empty());
-        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
+        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
     }
 
     @Test
@@ -226,7 +226,7 @@ public abstract class AbstractRecipientRewriteTableTest {
 
         virtualUserTable.setRecursiveMapping(true);
 
-            assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
+            assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
 
             addMapping(user1, domain1, user2 + "@" + domain2.asString(), Type.Address);
             addMapping(user2, domain2, user3 + "@" + domain3.asString(), Type.Address);
@@ -250,7 +250,7 @@ public abstract class AbstractRecipientRewriteTableTest {
         String user = "user";
         String user2 = "user2";
 
-        assertThat(virtualUserTable.getAllMappings()).describedAs("No mappings").isNull();
+        assertThat(virtualUserTable.getAllMappings()).describedAs("No mappings").isEmpty();
 
         addMapping(RecipientRewriteTable.WILDCARD, aliasDomain, user2 + "@" + domain, Type.Address);
         addMapping(RecipientRewriteTable.WILDCARD, aliasDomain, domain, Type.Domain);

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7d515c8/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
b/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
index 79bf3da..89dd813 100644
--- a/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
+++ b/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
@@ -118,9 +118,6 @@ public class MemoryRecipientRewriteTable extends AbstractRecipientRewriteTable
{
 
     @Override
     protected Map<String, Mappings> getAllMappingsInternal() {
-        if (mappingEntries.isEmpty()) {
-            return null;
-        }
         return Multimaps.index(mappingEntries, InMemoryMappingEntry::asKey)
             .asMap()
             .entrySet()


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