james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [32/44] james-project git commit: JAMES-2267 Make InMemorySmtp slightly easier to work with
Date Fri, 05 Jan 2018 02:56:51 GMT
JAMES-2267 Make InMemorySmtp slightly easier to work with

Also, a SMTP gateway allows to get ride of it.


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

Branch: refs/heads/improve-mailet-testing-experience-v1
Commit: c6532c8fb762ef63c9970b259964e022aab20349
Parents: 5f65878
Author: benwa <btellier@linagora.com>
Authored: Thu Dec 21 11:11:31 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Jan 5 09:33:52 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mpt/smtp/ForwardSmtpTest.java   |  5 +----
 .../james/dnsservice/api/InMemoryDNSService.java |  6 ++++++
 .../GatewayRemoteDeliveryIntegrationTest.java    | 19 +++++--------------
 .../transport/mailets/GroupMappingTest.java      | 15 +++------------
 .../james/jmap/VacationRelayIntegrationTest.java |  5 +----
 5 files changed, 16 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c6532c8f/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java
b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java
index 12e41fb..bcfdd5d 100644
--- a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java
+++ b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java
@@ -22,7 +22,6 @@ import static com.jayway.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS;
 import static com.jayway.awaitility.Duration.ONE_MINUTE;
 import static org.hamcrest.Matchers.equalTo;
 
-import java.net.InetAddress;
 import java.util.Locale;
 
 import org.apache.james.mpt.script.SimpleScriptedTestProtocol;
@@ -70,11 +69,9 @@ public abstract class ForwardSmtpTest {
         scriptedTest = new SimpleScriptedTestProtocol("/org/apache/james/smtp/scripts/",
hostSystem)
                 .withLocale(Locale.US)
                 .withUser(USER_AT_DOMAIN, PASSWORD);
-
-        InetAddress containerIp = InetAddress.getByName(fakeSmtp.getContainerIp());
         
         hostSystem.getInMemoryDnsService()
-            .registerRecord("yopmail.com", containerIp, "yopmail.com");
+            .registerMxRecord("yopmail.com", fakeSmtp.getContainerIp());
         hostSystem.addAddressMapping(USER, DOMAIN, "ray@yopmail.com");
 
         RestAssured.requestSpecification = FakeSmtpHelper.requestSpecification(fakeSmtp.getContainerIp());

http://git-wip-us.apache.org/repos/asf/james-project/blob/c6532c8f/server/dns-service/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/InMemoryDNSService.java
----------------------------------------------------------------------
diff --git a/server/dns-service/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/InMemoryDNSService.java
b/server/dns-service/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/InMemoryDNSService.java
index 851ace7..3a3ff92 100644
--- a/server/dns-service/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/InMemoryDNSService.java
+++ b/server/dns-service/dnsservice-api/src/test/java/org/apache/james/dnsservice/api/InMemoryDNSService.java
@@ -56,6 +56,12 @@ public class InMemoryDNSService implements DNSService {
         registerRecord(hostname, ImmutableList.of(address), ImmutableList.of(mxRecord), emptyTxtRecords);
     }
 
+    public InMemoryDNSService registerMxRecord(String hostname, String ip) throws UnknownHostException
{
+        InetAddress containerIp = InetAddress.getByName(ip);
+        registerRecord(hostname, containerIp, hostname);
+        return this;
+    }
+
     public void registerRecord(String hostname, List<InetAddress> addresses, Collection<String>
mxRecords, Collection<String> txtRecords ){
         records.put(hostname, dnsRecordFor(mxRecords, txtRecords, addresses));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c6532c8f/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
index f5d3818..55900f0 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
@@ -31,7 +31,6 @@ import static org.apache.james.mailets.configuration.Constants.awaitOneMinute;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.hasSize;
 
-import java.net.InetAddress;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.james.dnsservice.api.DNSService;
@@ -85,12 +84,16 @@ public class GatewayRemoteDeliveryIntegrationTest {
 
     private TemporaryJamesServer jamesServer;
     private DataProbe dataProbe;
+    private InMemoryDNSService inMemoryDNSService;
 
     @Before
     public void setup() throws Exception {
         awaitOneMinute.until(() -> fakeSmtp.tryConnect(25));
 
         RestAssured.requestSpecification = FakeSmtpHelper.requestSpecification(fakeSmtp.getContainerIp());
+
+        inMemoryDNSService = new InMemoryDNSService()
+            .registerMxRecord(JAMES_ANOTHER_DOMAIN, fakeSmtp.getContainerIp());
     }
 
     @After
@@ -179,9 +182,6 @@ public class GatewayRemoteDeliveryIntegrationTest {
     @Test
     public void outgoingMailShouldNotBeSentDirectlyToTheHostWhenGatewayFails() throws Exception
{
         String gatewayProperty = "invalid.domain";
-        InMemoryDNSService inMemoryDNSService = new InMemoryDNSService();
-        InetAddress containerIp = InetAddress.getByName(fakeSmtp.getContainerIp());
-        inMemoryDNSService.registerRecord(JAMES_ANOTHER_DOMAIN, containerIp, JAMES_ANOTHER_DOMAIN);
 
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
@@ -203,12 +203,10 @@ public class GatewayRemoteDeliveryIntegrationTest {
             .statusCode(200)
             .body("", hasSize(0));
     }
+
     @Test
     public void remoteDeliveryShouldBounceUponFailure() throws Exception {
         String gatewayProperty = "invalid.domain";
-        InMemoryDNSService inMemoryDNSService = new InMemoryDNSService();
-        InetAddress containerIp = InetAddress.getByName(fakeSmtp.getContainerIp());
-        inMemoryDNSService.registerRecord(JAMES_ANOTHER_DOMAIN, containerIp, JAMES_ANOTHER_DOMAIN);
 
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_AND_IMAP_MODULE)
@@ -237,9 +235,6 @@ public class GatewayRemoteDeliveryIntegrationTest {
     @Test
     public void remoteDeliveryShouldBounceUponFailureWhenNoBounceProcessor() throws Exception
{
         String gatewayProperty = "invalid.domain";
-        InMemoryDNSService inMemoryDNSService = new InMemoryDNSService();
-        InetAddress containerIp = InetAddress.getByName(fakeSmtp.getContainerIp());
-        inMemoryDNSService.registerRecord(JAMES_ANOTHER_DOMAIN, containerIp, JAMES_ANOTHER_DOMAIN);
 
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_AND_IMAP_MODULE)
@@ -279,10 +274,6 @@ public class GatewayRemoteDeliveryIntegrationTest {
 
     @Test
     public void directResolutionShouldBeWellPerformed() throws Exception {
-        InMemoryDNSService inMemoryDNSService = new InMemoryDNSService();
-        InetAddress containerIp = InetAddress.getByName(fakeSmtp.getContainerIp());
-        inMemoryDNSService.registerRecord(JAMES_ANOTHER_DOMAIN, containerIp, JAMES_ANOTHER_DOMAIN);
-
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
             .withOverrides(binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService))

http://git-wip-us.apache.org/repos/asf/james-project/blob/c6532c8f/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
index 9a95c42..5f51620 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
@@ -30,13 +30,10 @@ import static org.apache.james.mailets.configuration.Constants.calmlyAwait;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 
-import java.net.InetAddress;
 import java.util.concurrent.TimeUnit;
 
 import javax.mail.internet.MimeMessage;
 
-import org.apache.james.dnsservice.api.DNSService;
-import org.apache.james.dnsservice.api.InMemoryDNSService;
 import org.apache.james.jmap.mailet.VacationMailet;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailets.TemporaryJamesServer;
@@ -90,7 +87,6 @@ public class GroupMappingTest {
         .withAffinityToContainer()
         .waitingFor(new HostPortWaitStrategy());
 
-    private final InMemoryDNSService inMemoryDNSService = new InMemoryDNSService();
     @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
     @Rule
@@ -98,13 +94,8 @@ public class GroupMappingTest {
     @Rule
     public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
-    private InetAddress containerIp;
     @Before
     public void setup() throws Exception {
-
-        containerIp = InetAddress.getByName(fakeSmtp.getContainerIp());
-        inMemoryDNSService.registerRecord("yopmail.com", containerIp, "yopmail.com");
-
         MailetContainer mailetContainer = MailetContainer.builder()
             .addProcessor(CommonProcessors.simpleRoot())
             .addProcessor(CommonProcessors.error())
@@ -126,11 +117,11 @@ public class GroupMappingTest {
                     .addProperty("maxDnsProblemRetries", "0")
                     .addProperty("deliveryThreads", "10")
                     .addProperty("sendpartial", "true")
-                    .addProperty("bounceProcessor", "bounces")))
+                    .addProperty("bounceProcessor", "bounces")
+                    .addProperty("gateway", fakeSmtp.getContainerIp())))
             .build();
 
         jamesServer = TemporaryJamesServer.builder()
-            .withOverrides(binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService))
             .withMailetContainer(mailetContainer)
             .build(temporaryFolder);
 
@@ -464,7 +455,7 @@ public class GroupMappingTest {
             .until(() -> {
                 try {
                     with()
-                        .baseUri("http://" + containerIp.getHostAddress())
+                        .baseUri("http://" + fakeSmtp.getContainerIp())
                         .port(80)
                         .get("/api/email")
                     .then()

http://git-wip-us.apache.org/repos/asf/james-project/blob/c6532c8f/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
index 3ef66d6..dda4ddd 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
@@ -21,7 +21,6 @@ package org.apache.james.jmap;
 
 import static org.hamcrest.Matchers.equalTo;
 
-import java.net.InetAddress;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.net.smtp.SMTPClient;
@@ -79,10 +78,8 @@ public abstract class VacationRelayIntegrationTest {
 
     @Before
     public void setUp() throws Exception {
-
-        InetAddress containerIp = InetAddress.getByName(fakeSmtp.getContainerIp());
         getInMemoryDns()
-            .registerRecord("yopmail.com", containerIp, "yopmail.com");
+            .registerMxRecord("yopmail.com", fakeSmtp.getContainerIp());
 
         guiceJamesServer = getJmapServer();
         guiceJamesServer.start();


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