You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/08/03 00:58:17 UTC
[2/8] james-project git commit: JAMES-2470 Allow FakeSmtp to be reused
JAMES-2470 Allow FakeSmtp to be reused
This allow to use statically FakeSmtp, saving time
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f6af9e07
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f6af9e07
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f6af9e07
Branch: refs/heads/master
Commit: f6af9e078575363c3fa6a70e4d30d945b119b459
Parents: a139cc2
Author: benwa <bt...@linagora.com>
Authored: Thu Aug 2 15:29:51 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Aug 3 07:55:59 2018 +0700
----------------------------------------------------------------------
.../apache/james/mpt/smtp/ForwardSmtpTest.java | 33 ++++++++++----------
...ResolutionRemoteDeliveryIntegrationTest.java | 11 ++++---
.../GatewayRemoteDeliveryIntegrationTest.java | 14 ++++++---
.../james/smtp/SmtpAuthorizedAddressesTest.java | 22 +++++++------
.../mailets/GroupMappingRelayTest.java | 14 ++++++---
.../jmap/VacationRelayIntegrationTest.java | 16 ++++++----
.../java/org/apache/james/utils/FakeSmtp.java | 14 ++++++++-
7 files changed, 79 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f6af9e07/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 e30d555..d6bffc8 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
@@ -18,7 +18,7 @@
****************************************************************/
package org.apache.james.mpt.smtp;
-import static org.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS;
+import static org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS;
import static org.awaitility.Duration.ONE_MINUTE;
import static org.hamcrest.Matchers.equalTo;
@@ -30,7 +30,8 @@ import org.awaitility.Awaitility;
import org.awaitility.Duration;
import org.awaitility.core.ConditionFactory;
import org.junit.Before;
-import org.junit.Rule;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
public abstract class ForwardSmtpTest {
@@ -39,17 +40,27 @@ public abstract class ForwardSmtpTest {
public static final String DOMAIN = "mydomain.tld";
public static final String USER_AT_DOMAIN = USER + "@" + DOMAIN;
public static final String PASSWORD = "secret";
+ public static final Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS;
+ public static final ConditionFactory calmlyAwait = Awaitility.with()
+ .pollInterval(slowPacedPollInterval)
+ .and()
+ .with()
+ .pollDelay(slowPacedPollInterval)
+ .await();
- @Rule
- public FakeSmtp fakeSmtp = new FakeSmtp();
-
- private ConditionFactory calmlyAwait;
+ @ClassRule
+ public static FakeSmtp fakeSmtp = new FakeSmtp();
protected abstract SmtpHostSystem createSmtpHostSystem();
private SmtpHostSystem hostSystem;
private SimpleScriptedTestProtocol scriptedTest;
+ @BeforeClass
+ public static void classSetUp() {
+ fakeSmtp.awaitStarted(calmlyAwait.atMost(ONE_MINUTE));
+ }
+
@Before
public void setUp() throws Exception {
hostSystem = createSmtpHostSystem();
@@ -61,16 +72,6 @@ public abstract class ForwardSmtpTest {
hostSystem.getInMemoryDnsService()
.registerMxRecord("yopmail.com", fakeSmtp.getContainer().getContainerIp());
hostSystem.addAddressMapping(USER, DOMAIN, "ray@yopmail.com");
-
- Duration slowPacedPollInterval = FIVE_HUNDRED_MILLISECONDS;
- calmlyAwait = Awaitility.with()
- .pollInterval(slowPacedPollInterval)
- .and()
- .with()
- .pollDelay(slowPacedPollInterval)
- .await();
-
- fakeSmtp.awaitStarted(calmlyAwait.atMost(ONE_MINUTE));
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/f6af9e07/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
index 69c088c..c9509a4 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
@@ -48,7 +48,7 @@ import org.apache.james.utils.IMAPMessageReader;
import org.apache.james.utils.SMTPMessageSender;
import org.awaitility.Duration;
import org.junit.After;
-import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -74,22 +74,23 @@ public class DirectResolutionRemoteDeliveryIntegrationTest {
public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
@Rule
public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
- @Rule
- public FakeSmtp fakeSmtp = new FakeSmtp();
+ @ClassRule
+ public static FakeSmtp fakeSmtp = new FakeSmtp();
@ClassRule
public static FakeSmtp fakeSmtpOnPort26 = FakeSmtp.withSmtpPort(26);
private TemporaryJamesServer jamesServer;
private DataProbe dataProbe;
- @Before
- public void setup() {
+ @BeforeClass
+ public static void setup() {
fakeSmtp.awaitStarted(awaitAtMostOneMinute);
fakeSmtpOnPort26.awaitStarted(awaitAtMostOneMinute);
}
@After
public void tearDown() {
+ fakeSmtp.clean();
if (jamesServer != null) {
jamesServer.shutdown();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f6af9e07/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 9da3345..71c1ebe 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
@@ -46,6 +46,8 @@ import org.apache.james.utils.SMTPMessageSender;
import org.awaitility.Duration;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -56,29 +58,33 @@ public class GatewayRemoteDeliveryIntegrationTest {
private static final String FROM = "from@" + DEFAULT_DOMAIN;
private static final String RECIPIENT = "touser@" + JAMES_ANOTHER_DOMAIN;
+ @ClassRule
+ public static FakeSmtp fakeSmtp = new FakeSmtp();
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Rule
public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
@Rule
public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
- @Rule
- public FakeSmtp fakeSmtp = new FakeSmtp();
private TemporaryJamesServer jamesServer;
private DataProbe dataProbe;
private InMemoryDNSService inMemoryDNSService;
- @Before
- public void setup() throws Exception {
+ @BeforeClass
+ public static void classSetUp() {
fakeSmtp.awaitStarted(awaitAtMostOneMinute);
+ }
+ @Before
+ public void setup() throws Exception {
inMemoryDNSService = new InMemoryDNSService()
.registerMxRecord(JAMES_ANOTHER_DOMAIN, fakeSmtp.getContainer().getContainerIp());
}
@After
public void tearDown() {
+ fakeSmtp.clean();
if (jamesServer != null) {
jamesServer.shutdown();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f6af9e07/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
index 1248a04..ed3a9b6 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
@@ -46,7 +46,8 @@ import org.apache.james.utils.SMTPSendingException;
import org.apache.james.utils.SmtpSendingStep;
import org.awaitility.Duration;
import org.junit.After;
-import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -55,8 +56,8 @@ public class SmtpAuthorizedAddressesTest {
private static final String FROM = "fromuser@" + DEFAULT_DOMAIN;
private static final String TO = "to@any.com";
- @Rule
- public FakeSmtp fakeSmtp = new FakeSmtp();
+ @ClassRule
+ public static FakeSmtp fakeSmtp = new FakeSmtp();
@Rule
public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
@Rule
@@ -66,8 +67,8 @@ public class SmtpAuthorizedAddressesTest {
private TemporaryJamesServer jamesServer;
- @Before
- public void setup() {
+ @BeforeClass
+ public static void setup() {
fakeSmtp.awaitStarted(awaitAtMostOneMinute);
}
@@ -93,6 +94,7 @@ public class SmtpAuthorizedAddressesTest {
@After
public void tearDown() {
+ fakeSmtp.clean();
if (jamesServer != null) {
jamesServer.shutdown();
}
@@ -107,10 +109,12 @@ public class SmtpAuthorizedAddressesTest {
messageSender.connect(LOCALHOST_IP, SMTP_PORT)
.sendMessage(FROM, TO);
- awaitAtMostOneMinute.until(() -> fakeSmtp.isReceived(response -> response
- .body("", hasSize(1))
- .body("[0].from", equalTo(FROM))
- .body("[0].subject", equalTo("test"))));
+ awaitAtMostOneMinute
+ .pollDelay(Duration.ONE_HUNDRED_MILLISECONDS)
+ .until(() -> fakeSmtp.isReceived(response -> response
+ .body("", hasSize(1))
+ .body("[0].from", equalTo(FROM))
+ .body("[0].subject", equalTo("test"))));
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/f6af9e07/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingRelayTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingRelayTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingRelayTest.java
index b9842a1..7a58eff 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingRelayTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingRelayTest.java
@@ -52,6 +52,8 @@ import org.apache.mailet.base.test.FakeMail;
import org.awaitility.Duration;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -73,8 +75,8 @@ public class GroupMappingRelayTest {
private MimeMessage message;
private RequestSpecification webAdminApi;
- @Rule
- public final FakeSmtp fakeSmtp = new FakeSmtp();
+ @ClassRule
+ public static final FakeSmtp fakeSmtp = new FakeSmtp();
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Rule
@@ -82,6 +84,11 @@ public class GroupMappingRelayTest {
@Rule
public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
+ @BeforeClass
+ public static void classSetUp() {
+ fakeSmtp.awaitStarted(awaitAtMostOneMinute);
+ }
+
@Before
public void setup() throws Exception {
MailetContainer.Builder mailetContainer = TemporaryJamesServer.SIMPLE_MAILET_CONTAINER_CONFIGURATION
@@ -115,8 +122,6 @@ public class GroupMappingRelayTest {
.withMailetContainer(mailetContainer)
.build(temporaryFolder);
- fakeSmtp.awaitStarted(awaitAtMostOneMinute);
-
DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
dataProbe.addDomain(DOMAIN1);
@@ -135,6 +140,7 @@ public class GroupMappingRelayTest {
@After
public void tearDown() {
+ fakeSmtp.clean();
jamesServer.shutdown();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f6af9e07/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 050f9e0..0a40262 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
@@ -44,7 +44,8 @@ import org.apache.james.utils.FakeSmtp;
import org.apache.james.utils.JmapGuiceProbe;
import org.junit.After;
import org.junit.Before;
-import org.junit.Rule;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
public abstract class VacationRelayIntegrationTest {
@@ -54,9 +55,8 @@ public abstract class VacationRelayIntegrationTest {
private static final String PASSWORD = "secret";
private static final String REASON = "Message explaining my wonderful vacations";
-
- @Rule
- public FakeSmtp fakeSmtp = new FakeSmtp();
+ @ClassRule
+ public static FakeSmtp fakeSmtp = new FakeSmtp();
private GuiceJamesServer guiceJamesServer;
private JmapGuiceProbe jmapGuiceProbe;
@@ -67,6 +67,11 @@ public abstract class VacationRelayIntegrationTest {
protected abstract InMemoryDNSService getInMemoryDns();
+ @BeforeClass
+ public static void classSetUp() {
+ fakeSmtp.awaitStarted(calmlyAwait.atMost(ONE_MINUTE));
+ }
+
@Before
public void setUp() throws Exception {
getInMemoryDns()
@@ -84,12 +89,11 @@ public abstract class VacationRelayIntegrationTest {
await();
jmapGuiceProbe = guiceJamesServer.getProbe(JmapGuiceProbe.class);
-
- fakeSmtp.awaitStarted(calmlyAwait.atMost(ONE_MINUTE));
}
@After
public void teardown() {
+ fakeSmtp.clean();
guiceJamesServer.stop();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f6af9e07/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java b/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java
index 167a0a7..51685dd 100644
--- a/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java
+++ b/server/testing/src/main/java/org/apache/james/utils/FakeSmtp.java
@@ -65,7 +65,7 @@ public class FakeSmtp implements TestRule {
this(fakeSmtpContainer().withExposedPorts(SMTP_PORT), SMTP_PORT);
}
- public FakeSmtp(SwarmGenericContainer container, Integer smtpPort) {
+ private FakeSmtp(SwarmGenericContainer container, Integer smtpPort) {
this.smtpPort = smtpPort;
this.container = container;
}
@@ -105,4 +105,16 @@ public class FakeSmtp implements TestRule {
public SwarmGenericContainer getContainer() {
return container;
}
+
+ public void clean() {
+ given(requestSpecification(), RESPONSE_SPECIFICATION)
+ .get("/api/email")
+ .jsonPath()
+ .getList("id", String.class)
+ .stream()
+ .mapToInt(Integer::valueOf)
+ .max()
+ .ifPresent(id -> given(requestSpecification(), RESPONSE_SPECIFICATION)
+ .get("/api/email/purge/" + id));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org