james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [james-project] 01/06: JAMES-2729 MappingSource should have a method to get the domain
Date Mon, 29 Apr 2019 12:45:34 GMT
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ef3b76ef95d929beaf4039f2fa9f6189626d34f4
Author: Tran Tien Duc <dtran@linagora.com>
AuthorDate: Mon Apr 22 17:29:49 2019 +0700

    JAMES-2729 MappingSource should have a method to get the domain
    
    from Optional<User> and Optional<Domain>. To be used in the validation
    at the AbstractRecipientRewriteTable
---
 .../org/apache/james/rrt/lib/MappingSource.java    | 11 +++++--
 .../apache/james/rrt/lib/MappingSourceTest.java    | 35 ++++++++++++++++++----
 2 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingSource.java
b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingSource.java
index 92c5264..0955256 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingSource.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingSource.java
@@ -123,12 +123,17 @@ public class MappingSource implements Serializable {
     }
 
     public String getFixedDomain() {
-        return OptionalUtils.or(
-                user.flatMap(User::getDomainPart).map(Domain::asString),
-                domain.map(Domain::asString))
+        return availableDomain()
+            .map(Domain::asString)
             .orElse(WILDCARD);
     }
 
+    public Optional<Domain> availableDomain() {
+        return OptionalUtils.or(
+            user.flatMap(User::getDomainPart),
+            domain);
+    }
+
     @Override
     public final boolean equals(Object o) {
         if (o instanceof MappingSource) {
diff --git a/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingSourceTest.java
b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingSourceTest.java
index c467bb7..4462969 100644
--- a/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingSourceTest.java
+++ b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingSourceTest.java
@@ -29,9 +29,10 @@ import org.junit.jupiter.api.Test;
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class MappingSourceTest {
-    private static final String DOMAIN = "domain.tld";
+    private static final String DOMAIN_AS_STRING = "domain.tld";
+    private static final Domain DOMAIN = Domain.of(DOMAIN_AS_STRING);
     private static final  String USER = "alice";
-    private static final String MAIL_ADDRESS = USER + "@" + DOMAIN;
+    private static final String MAIL_ADDRESS = USER + "@" + DOMAIN_AS_STRING;
 
     @Test
     void shouldRespectBeanContract() {
@@ -49,14 +50,14 @@ class MappingSourceTest {
 
     @Test
     void asMailAddressStringShouldSerializeDomain() {
-        MappingSource mappingSource = MappingSource.fromDomain(Domain.of(DOMAIN));
+        MappingSource mappingSource = MappingSource.fromDomain(DOMAIN);
 
-        assertThat(mappingSource.asMailAddressString()).isEqualTo("*@" + DOMAIN);
+        assertThat(mappingSource.asMailAddressString()).isEqualTo("*@" + DOMAIN_AS_STRING);
     }
 
     @Test
     void asMailAddressStringShouldSerializeUser() {
-        MappingSource mappingSource = MappingSource.fromUser(USER, DOMAIN);
+        MappingSource mappingSource = MappingSource.fromUser(USER, DOMAIN_AS_STRING);
 
         assertThat(mappingSource.asMailAddressString()).isEqualTo(MAIL_ADDRESS);
     }
@@ -74,4 +75,28 @@ class MappingSourceTest {
 
         assertThat(mappingSource.asMailAddressString()).isEqualTo(MAIL_ADDRESS);
     }
+
+    @Test
+    void availableDomainShouldReturnUserDomainIfExist() throws Exception {
+        MappingSource mappingSource = MappingSource.fromMailAddress(new MailAddress(MAIL_ADDRESS));
+
+        assertThat(mappingSource.availableDomain())
+            .contains(DOMAIN);
+    }
+
+    @Test
+    void availableDomainShouldReturnDomainIfExist() {
+        MappingSource mappingSource = MappingSource.fromDomain(DOMAIN);
+
+        assertThat(mappingSource.availableDomain())
+            .contains(DOMAIN);
+    }
+
+    @Test
+    void availableDomainShouldReturnEmptyWhenNoDomainUserOrDomain() {
+        MappingSource mappingSource = MappingSource.wildCard();
+
+        assertThat(mappingSource.availableDomain())
+            .isEmpty();
+    }
 }
\ 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