Author: matthieu
Date: Mon Nov  2 13:48:06 2015
New Revision: 1711990

URL: http://svn.apache.org/viewvc?rev=1711990&view=rev
Log:
JAMES-1595 Mapping now have a getType method

Modified:
    
james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
    
james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
    
james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingImplTest.java

Modified: 
james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java?rev=1711990&r1=1711989&r2=1711990&view=diff
==============================================================================
--- 
james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
 (original)
+++ 
james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
 Mon Nov  2 13:48:06 2015
@@ -23,6 +23,10 @@ package org.apache.james.rrt.lib;
 
 public interface Mapping {
 
+    enum Type { Regex, Domain, Error, Address };
+    
+    Type getType();
+    
     String asString();
 
     boolean hasDomain();

Modified: 
james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java?rev=1711990&r1=1711989&r2=1711990&view=diff
==============================================================================
--- 
james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
 (original)
+++ 
james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
 Mon Nov  2 13:48:06 2015
@@ -20,6 +20,8 @@
 
 package org.apache.james.rrt.lib;
 
+import org.apache.james.rrt.api.RecipientRewriteTable;
+
 import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
 
@@ -33,6 +35,7 @@ public class MappingImpl implements Mapp
     private final String mapping;
 
     public MappingImpl(String mapping) {
+        Preconditions.checkNotNull(mapping);
         this.mapping = mapping;
     }
     
@@ -53,6 +56,19 @@ public class MappingImpl implements Mapp
     }
     
     @Override
+    public Type getType() {
+        if (mapping.startsWith(RecipientRewriteTable.ALIASDOMAIN_PREFIX)) {
+            return Type.Domain;
+        } else if (mapping.startsWith(RecipientRewriteTable.REGEX_PREFIX)) {
+            return Type.Regex;
+        } else if (mapping.startsWith(RecipientRewriteTable.ERROR_PREFIX)) {
+            return Type.Error;
+        } else {
+            return Type.Address;
+        }
+    }
+    
+    @Override
     public boolean equals(Object other) {
         if (other instanceof MappingImpl) {
             MappingImpl otherMapping = (MappingImpl) other;

Modified: 
james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingImplTest.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingImplTest.java?rev=1711990&r1=1711989&r2=1711990&view=diff
==============================================================================
--- 
james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingImplTest.java
 (original)
+++ 
james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/MappingImplTest.java
 Mon Nov  2 13:48:06 2015
@@ -20,12 +20,18 @@
 
 package org.apache.james.rrt.lib;
 
+import org.apache.james.rrt.api.RecipientRewriteTable;
 import org.junit.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class MappingImplTest {
 
+    @Test(expected=NullPointerException.class)
+    public void factoryMethodShouldThrowOnNull() {
+        assertThat(MappingImpl.of(null));
+    }
+    
     @Test
     public void hasDomainshouldReturnTrueWhenMappingContainAtMark() {
         assertThat(MappingImpl.of("a@b").hasDomain()).isTrue();
@@ -66,4 +72,28 @@ public class MappingImplTest {
         
assertThat(MappingImpl.of("abc").appendDomain("")).isEqualTo(MappingImpl.of("abc@"));
     }
 
+    @Test
+    public void getTypeShouldReturnAddressWhenNoPrefix() {
+        
assertThat(MappingImpl.of("abc").getType()).isEqualTo(Mapping.Type.Address);
+    }
+
+    @Test
+    public void getTypeShouldReturnAddressWhenEmpty() {
+        
assertThat(MappingImpl.of("").getType()).isEqualTo(Mapping.Type.Address);
+    }
+    
+    @Test
+    public void getTypeShouldReturnRegexWhenRegexPrefix() {
+        assertThat(MappingImpl.of(RecipientRewriteTable.REGEX_PREFIX + 
"abc").getType()).isEqualTo(Mapping.Type.Regex);
+    }
+
+    @Test
+    public void getTypeShouldReturnErrorWhenErrorPrefix() {
+        assertThat(MappingImpl.of(RecipientRewriteTable.ERROR_PREFIX + 
"abc").getType()).isEqualTo(Mapping.Type.Error);
+    }
+
+    @Test
+    public void getTypeShouldReturnDomainWhenDomainPrefix() {
+        assertThat(MappingImpl.of(RecipientRewriteTable.ALIASDOMAIN_PREFIX + 
"abc").getType()).isEqualTo(Mapping.Type.Domain);
+    }
 }



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