james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [01/24] james-project git commit: JAMES-2366 Introduce Forward RRT mapping type
Date Fri, 06 Apr 2018 13:20:20 GMT
Repository: james-project
Updated Branches:
  refs/heads/master dbc6f88cd -> 99b5cb6c7


JAMES-2366 Introduce Forward RRT mapping type


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

Branch: refs/heads/master
Commit: fd6f10ab67c1f6988f16ebaf1491a29abae091dd
Parents: dbc6f88
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Tue Mar 27 16:48:00 2018 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Fri Apr 6 14:38:36 2018 +0200

----------------------------------------------------------------------
 .../james/rrt/api/RecipientRewriteTable.java    |  4 ++
 .../java/org/apache/james/rrt/lib/Mapping.java  |  7 ++-
 .../org/apache/james/rrt/lib/MappingTest.java   | 24 +++++++++
 .../rrt/file/XMLRecipientRewriteTableTest.java  |  2 +
 .../rrt/lib/AbstractRecipientRewriteTable.java  | 53 ++++++++++++++------
 .../org/apache/james/rrt/lib/MappingImpl.java   |  4 ++
 .../user/lib/AbstractJamesUsersRepository.java  |  9 ++++
 .../lib/AbstractRecipientRewriteTableTest.java  | 38 +++++++++++++-
 .../apache/james/rrt/lib/MappingImplTest.java   | 47 +++++++++++------
 .../james/rrt/lib/RewriteTablesStepdefs.java    | 10 ++++
 .../resources/cucumber/rewrite_tables.feature   | 24 ++++++++-
 11 files changed, 188 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
index f07fd69..f1f11bd 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
@@ -207,6 +207,10 @@ public interface RecipientRewriteTable {
      */
     void removeAliasDomainMapping(Domain aliasDomain, Domain realDomain) throws RecipientRewriteTableException;
 
+    void addForwardMapping(String user, Domain domain, String address) throws RecipientRewriteTableException;
+
+    void removeForwardMapping(String user, Domain domain, String address) throws RecipientRewriteTableException;
+
     class ErrorMappingException extends Exception {
 
         private static final long serialVersionUID = 2348752938798L;

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
index 4bbf11f..72193dc 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
@@ -38,6 +38,9 @@ public interface Mapping {
         if (input.startsWith(Type.Error.asPrefix())) {
             return Type.Error;
         }
+        if (input.startsWith(Type.Forward.asPrefix())) {
+            return Type.Forward;
+        }
         return Type.Address;
     }
 
@@ -47,6 +50,7 @@ public interface Mapping {
         Regex("regex:"), 
         Domain("domain:"), 
         Error("error:"), 
+        Forward("forward:"),
         Address(""); 
 
         private final String asPrefix;
@@ -67,7 +71,8 @@ public interface Mapping {
         public static boolean hasPrefix(String mapping) {
             return mapping.startsWith(Regex.asPrefix())
                 || mapping.startsWith(Domain.asPrefix())
-                || mapping.startsWith(Error.asPrefix());
+                || mapping.startsWith(Error.asPrefix())
+                || mapping.startsWith(Forward.asPrefix());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
index 5c4bca8..8297fca 100644
--- a/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
+++ b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
@@ -45,6 +45,12 @@ public class MappingTest {
     }
 
     @Test
+    public void hasPrefixShouldReturnTrueWhenForward() {
+        boolean hasPrefix = Mapping.Type.hasPrefix(Type.Forward.asPrefix() + "myRegex");
+        assertThat(hasPrefix).isTrue();
+    }
+
+    @Test
     public void hasPrefixShouldReturnFalseWhenAddress() {
         boolean hasPrefix = Mapping.Type.hasPrefix(Type.Address.asPrefix() + "myRegex");
         assertThat(hasPrefix).isFalse();
@@ -75,6 +81,12 @@ public class MappingTest {
     }
 
     @Test
+    public void detectTypeShouldReturnForwardWhenForwardPrefix() {
+        assertThat(Mapping.detectType(Type.Forward.asPrefix() + "mapping"))
+            .isEqualTo(Type.Forward);
+    }
+
+    @Test
     public void withoutPrefixShouldRemoveAddressPrefix() {
         assertThat(Type.Address.withoutPrefix(Type.Address.asPrefix() + "mapping"))
             .isEqualTo("mapping");
@@ -105,6 +117,12 @@ public class MappingTest {
     }
 
     @Test
+    public void withoutPrefixShouldRemoveForwardPrefix() {
+        assertThat(Type.Forward.withoutPrefix(Type.Forward.asPrefix() + "mapping"))
+            .isEqualTo("mapping");
+    }
+
+    @Test
     public void withoutPrefixShouldThrowOnBadPrefix() {
         assertThatThrownBy(() -> Type.Regex.withoutPrefix(Type.Domain.asPrefix() + "mapping"))
             .isInstanceOf(IllegalArgumentException.class);
@@ -115,4 +133,10 @@ public class MappingTest {
         assertThatThrownBy(() -> Type.Regex.withoutPrefix("mapping"))
             .isInstanceOf(IllegalArgumentException.class);
     }
+
+    @Test
+    public void withoutPrefixShouldThrowWhenNoPrefixOnForwardType() {
+        assertThatThrownBy(() -> Type.Forward.withoutPrefix("mapping"))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
b/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
index d4dd938..f5b7712 100644
--- a/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
+++ b/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
@@ -119,6 +119,8 @@ public class XMLRecipientRewriteTableTest extends AbstractRecipientRewriteTableT
             mappings = mappings.remove(MappingImpl.address(mapping));
         } else if (type == Type.Domain) {
             mappings = mappings.remove(MappingImpl.domain(Domain.of(mapping)));
+        } else if (type == Type.Forward) {
+            mappings = mappings.remove(MappingImpl.forward(mapping));
         }
 
         if (mappings.size() > 0) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/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 a079777..2b11cee 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
@@ -207,35 +207,37 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
 
     @Override
     public void addAddressMapping(String user, Domain domain, String address) throws RecipientRewriteTableException
{
+        String addressWithDomain = addDefaultDomainIfNone(address);
+        checkAddressIsValid(addressWithDomain);
+        checkMapping(user, domain, MappingImpl.address(addressWithDomain));
+        LOGGER.info("Add address mapping => {} for user: {} domain: {}", addressWithDomain,
user, domain.name());
+        addMappingInternal(user, domain, MappingImpl.address(addressWithDomain));
+    }
+
+    private String addDefaultDomainIfNone(String address) throws RecipientRewriteTableException
{
         if (address.indexOf('@') < 0) {
             try {
-                address = address + "@" + domainList.getDefaultDomain().asString();
+                return address + "@" + domainList.getDefaultDomain().asString();
             } catch (DomainListException e) {
                 throw new RecipientRewriteTableException("Unable to retrieve default domain",
e);
             }
         }
+        return address;
+    }
+
+    private void checkAddressIsValid(String addressWithDomain) throws RecipientRewriteTableException
{
         try {
-            new MailAddress(address);
+            new MailAddress(addressWithDomain);
         } catch (ParseException e) {
-            throw new RecipientRewriteTableException("Invalid emailAddress: " + address,
e);
+            throw new RecipientRewriteTableException("Invalid emailAddress: " + addressWithDomain,
e);
         }
-        checkMapping(user, domain, MappingImpl.address(address));
-        LOGGER.info("Add address mapping => {} for user: {} domain: {}", address, user,
domain.name());
-        addMappingInternal(user, domain, MappingImpl.address(address));
-
     }
 
     @Override
     public void removeAddressMapping(String user, Domain domain, String address) throws RecipientRewriteTableException
{
-        if (address.indexOf('@') < 0) {
-            try {
-                address = address + "@" + domainList.getDefaultDomain().asString();
-            } catch (DomainListException e) {
-                throw new RecipientRewriteTableException("Unable to retrieve default domain",
e);
-            }
-        }
-        LOGGER.info("Remove address mapping => {} for user: {} domain: {}", address, user,
domain.name());
-        removeMappingInternal(user, domain, MappingImpl.address(address));
+        String addressWithDomain = addDefaultDomainIfNone(address);
+        LOGGER.info("Remove address mapping => {} for user: {} domain: {}", addressWithDomain,
user, domain.name());
+        removeMappingInternal(user, domain, MappingImpl.address(addressWithDomain));
     }
 
     @Override
@@ -294,6 +296,9 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
             case Address:
                 removeAddressMapping(user, domain, map);
                 break;
+            case Forward:
+                removeForwardMapping(user, domain, map);
+                break;
         }
     }
 
@@ -326,6 +331,22 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
         removeMappingInternal(null, aliasDomain, MappingImpl.domain(realDomain));
     }
 
+    @Override
+    public void addForwardMapping(String user, Domain domain, String address) throws RecipientRewriteTableException
{
+        String addressWithDomain = addDefaultDomainIfNone(address);
+        checkAddressIsValid(addressWithDomain);
+        checkMapping(user, domain, MappingImpl.forward(addressWithDomain));
+        LOGGER.info("Add forward mapping => {} for user: {} domain: {}", addressWithDomain,
user, domain.name());
+        addMappingInternal(user, domain, MappingImpl.forward(addressWithDomain));
+    }
+
+    @Override
+    public void removeForwardMapping(String user, Domain domain, String address) throws RecipientRewriteTableException
{
+        String addressWithDomain = addDefaultDomainIfNone(address);
+        LOGGER.info("Remove forward mapping => {} for user: {} domain: {}", addressWithDomain,
user, domain.name());
+        removeMappingInternal(user, domain, MappingImpl.forward(addressWithDomain));
+    }
+
     /**
      * Add new mapping
      *

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
index fcd6572..1dc0c92 100644
--- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
+++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
@@ -53,6 +53,10 @@ public class MappingImpl implements Mapping, Serializable {
     public static MappingImpl domain(Domain mapping) {
         return new MappingImpl(Type.Domain, mapping.asString());
     }
+
+    public static MappingImpl forward(String mapping) {
+        return new MappingImpl(Type.Forward, mapping);
+    }
     
     private final Type type;
     private final String mapping;

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
index 3941868..8d3ce08 100644
--- a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
+++ b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
@@ -266,4 +266,13 @@ public abstract class AbstractJamesUsersRepository extends AbstractUsersReposito
 
     }
 
+    @Override
+    public void addForwardMapping(String user, Domain domain, String address) throws RecipientRewriteTableException
{
+        throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable");
+    }
+
+    @Override
+    public void removeForwardMapping(String user, Domain domain, String address) throws RecipientRewriteTableException
{
+        throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable");
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/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 3dad6a0..26b3187 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
@@ -211,7 +211,6 @@ public abstract class AbstractRecipientRewriteTableTest {
 
     @Test
     public void testAliasDomainMapping() throws ErrorMappingException, RecipientRewriteTableException
{
-
         String domain = "realdomain";
         Domain aliasDomain = Domain.of("aliasdomain");
         String user = "user";
@@ -291,6 +290,36 @@ public abstract class AbstractRecipientRewriteTableTest {
         assertThat(virtualUserTable.getMappings(user, domain)).hasSize(2);
     }
 
+    @Test
+    public void addForwardMappingShouldStore() throws ErrorMappingException, RecipientRewriteTableException
{
+        String user = "test";
+        Domain domain = Domain.LOCALHOST;
+        String address = "test@localhost2";
+        String address2 = "test@james";
+
+        addMapping(user, domain, address, Type.Forward);
+        addMapping(user, domain, address2, Type.Forward);
+
+        assertThat(virtualUserTable.getMappings(user, domain)).hasSize(2);
+    }
+
+    @Test
+    public void removeForwardMappingShouldDelete() throws ErrorMappingException, RecipientRewriteTableException
{
+        String user = "test";
+        Domain domain = Domain.LOCALHOST;
+        String address = "test@localhost2";
+        String address2 = "test@james";
+
+        addMapping(user, domain, address, Type.Forward);
+        addMapping(user, domain, address2, Type.Forward);
+
+
+        removeMapping(user, domain, address, Type.Forward);
+        removeMapping(user, domain, address2, Type.Forward);
+
+        assertThat(virtualUserTable.getMappings(user, domain)).isNull();
+    }
+
     protected abstract AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception;
 
 
@@ -308,12 +337,14 @@ public abstract class AbstractRecipientRewriteTableTest {
             case Domain:
                 virtualUserTable.addAliasDomainMapping(domain, Domain.of(mapping));
                 break;
+            case Forward:
+                virtualUserTable.addForwardMapping(user, domain, mapping);
+                break;
             default:
                 throw new RuntimeException("Invalid mapping type: " + type.asPrefix());
         }
     }
 
-
     protected void removeMapping(String user, Domain domain, String mapping, Type type) throws
RecipientRewriteTableException {
         switch (type) {
             case Error:
@@ -328,6 +359,9 @@ public abstract class AbstractRecipientRewriteTableTest {
             case Domain:
                 virtualUserTable.removeAliasDomainMapping(domain, Domain.of(mapping));
                 break;
+            case Forward:
+                virtualUserTable.removeForwardMapping(user, domain, mapping);
+                break;
             default:
                 throw new RuntimeException("Invalid mapping type: " + type.asPrefix());
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingImplTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingImplTest.java
b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingImplTest.java
index 8810d83..e18823f 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingImplTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingImplTest.java
@@ -36,44 +36,53 @@ public class MappingImplTest {
             .verify();
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void addressFactoryMethodShouldThrowOnNull() {
-        assertThat(MappingImpl.address(null));
+        assertThatThrownBy(() -> MappingImpl.address(null))
+            .isInstanceOf(NullPointerException.class);
     }
     
-    @Test(expected = NullPointerException.class)
+    @Test
     public void regexFactoryMethodShouldThrowOnNull() {
-        assertThat(MappingImpl.regex(null));
+        assertThatThrownBy(() -> MappingImpl.regex(null))
+            .isInstanceOf(NullPointerException.class);
     }
     
-    @Test(expected = NullPointerException.class)
+    @Test
     public void domainFactoryMethodShouldThrowOnNull() {
-        assertThat(MappingImpl.domain(null));
+        assertThatThrownBy(() -> MappingImpl.domain(null))
+            .isInstanceOf(NullPointerException.class);
     }
-    
-    
-    @Test(expected = NullPointerException.class)
+
+    @Test
     public void errorFactoryMethodShouldThrowOnNull() {
-        assertThat(MappingImpl.error(null));
+        assertThatThrownBy(() -> MappingImpl.error(null))
+            .isInstanceOf(NullPointerException.class);
     }
     
     @Test
-    public void hasDomainshouldReturnTrueWhenMappingContainAtMark() {
+    public void forwardFactoryMethodShouldThrowOnNull() {
+        assertThatThrownBy(() -> MappingImpl.forward(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+    
+    @Test
+    public void hasDomainShouldReturnTrueWhenMappingContainAtMark() {
         assertThat(MappingImpl.address("a@b").hasDomain()).isTrue();
     }
     
     @Test
-    public void hasDomainshouldReturnFalseWhenMappingIsEmpty() {
+    public void hasDomainShouldReturnFalseWhenMappingIsEmpty() {
         assertThat(MappingImpl.address("").hasDomain()).isFalse();
     }
 
     @Test
-    public void hasDomainshouldReturnFalseWhenMappingIsBlank() {
+    public void hasDomainShouldReturnFalseWhenMappingIsBlank() {
         assertThat(MappingImpl.address(" ").hasDomain()).isFalse();
     }
 
     @Test
-    public void hasDefaultDomainShouldReturnFalseWhenMappingDoesntContainAtMark() {
+    public void hasDomainShouldReturnFalseWhenMappingDoesntContainAtMark() {
         assertThat(MappingImpl.address("abc").hasDomain()).isFalse();
     }
     
@@ -116,6 +125,11 @@ public class MappingImplTest {
     public void getTypeShouldReturnDomainWhenDomainPrefix() {
         assertThat(MappingImpl.domain(Domain.of("abc")).getType()).isEqualTo(Mapping.Type.Domain);
     }
+
+    @Test
+    public void getTypeShouldReturnForwardWhenForwardPrefix() {
+        assertThat(MappingImpl.forward("abc").getType()).isEqualTo(Mapping.Type.Forward);
+    }
     
     @Test(expected = IllegalStateException.class)
     public void getErrorMessageShouldThrowWhenMappingIsNotAnError() {
@@ -152,4 +166,9 @@ public class MappingImplTest {
     public void getAddressShouldThrowForDomain() {
         assertThatThrownBy(() -> MappingImpl.domain(Domain.of("value")).getAddress()).isInstanceOf(IllegalStateException.class);
     }
+
+    @Test
+    public void getAddressShouldThrowForForward() {
+        assertThatThrownBy(() -> MappingImpl.forward("value").getAddress()).isInstanceOf(IllegalStateException.class);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
index 14655fe..44423d5 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
@@ -71,6 +71,11 @@ public class RewriteTablesStepdefs {
         rewriteTable.addAliasDomainMapping(Domain.of(aliasDomain), Domain.of(domain));
     }
 
+    @Given("store \"([^\"]*)\" forward mapping for user \"([^\"]*)\" at domain \"([^\"]*)\"")
+    public void storeForwardMappingForUserAtDomain(String address, String user, String domain)
throws Throwable {
+        rewriteTable.addForwardMapping(user, Domain.of(domain), address);
+    }
+
     @Given("recursive mapping is disable")
     public void disableRecursiveMapping() {
         rewriteTable.setRecursiveMapping(false);
@@ -96,6 +101,11 @@ public class RewriteTablesStepdefs {
         rewriteTable.removeErrorMapping(user, Domain.of(domain), error);
     }
 
+    @When("user \"([^\"]*)\" at domain \"([^\"]*)\" removes a forward mapping \"([^\"]*)\"")
+    public void userAtDomainRemovesForwardMapping(String user, String domain, String address)
throws Throwable {
+        rewriteTable.removeForwardMapping(user, Domain.of(domain), address);
+    }
+
     @When("wildcard address mapping \"([^\"]*)\" at domain \"([^\"]*)\" is removed")
     public void removeWildcardAddressMappingAtDomain(String address, String domain) throws
Throwable {
         userAtDomainRemovesAddressMapping(RecipientRewriteTable.WILDCARD, domain, address);

http://git-wip-us.apache.org/repos/asf/james-project/blob/fd6f10ab/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature b/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
index 5ce3ec8..9e66fc0 100644
--- a/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
+++ b/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
@@ -218,4 +218,26 @@ Feature: Rewrite Tables tests
     Given store "domain2" alias domain mapping for domain "domain1"
     And store "domain3" alias domain mapping for domain "domain2"
     And store "domain4" alias domain mapping for domain "domain3"
-    Then mappings for user "test" at domain "domain4" should contains only "test@domain1"
\ No newline at end of file
+    Then mappings for user "test" at domain "domain4" should contains only "test@domain1"
+
+# Forward mapping
+
+  Scenario: stored forward mapping should be retrieved when one mapping is matching
+    Given store "test@localhost2" forward mapping for user "test" at domain "localhost"
+    Then mappings for user "test" at domain "localhost" should contains only "forward:test@localhost2"
+
+  Scenario: stored forward mapping should be retrieved when two mappings are matching
+    Given store "test@localhost2" forward mapping for user "test" at domain "localhost"
+    And store "test@james" forward mapping for user "test" at domain "localhost"
+    Then mappings for user "test" at domain "localhost" should contains only "forward:test@localhost2,
forward:test@james"
+
+  Scenario: stored forward mapping should not be retrieved by another user
+    Given store "test@localhost2" forward mapping for user "test" at domain "localhost"
+    And store "test@james" forward mapping for user "test" at domain "localhost"
+    Then mappings for user "test2" at domain "localhost" should be empty
+
+  Scenario: removing a stored forward mapping should work
+    Given store "test@localhost2" forward mapping for user "test" at domain "localhost"
+    And store "test@james" forward mapping for user "test" at domain "localhost"
+    When user "test" at domain "localhost" removes a forward mapping "test@james"
+    Then mappings for user "test" at domain "localhost" should contains only "forward:test@localhost2"
\ No newline at end of file


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