JAMES-2242 RemoteDelivery should be run on a SMTP only server
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9ad16167 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9ad16167 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9ad16167 Branch: refs/heads/master Commit: 9ad1616766d5eeb9d5e213ae6c6dd125dc194d62 Parents: 2a5f46b Author: benwa <btell...@linagora.com> Authored: Thu Nov 30 17:10:23 2017 +0700 Committer: Antoine Duprat <adup...@linagora.com> Committed: Mon Dec 4 14:42:22 2017 +0100 ---------------------------------------------------------------------- .../java/org/apache/james/GuiceJamesServer.java | 5 ++ .../org/apache/james/MemoryJamesServerMain.java | 5 +- .../modules/server/MemoryMailQueueModule.java | 2 - .../james/mailets/AddDeliveredToHeaderTest.java | 4 +- .../james/mailets/BounceIntegrationTest.java | 14 +-- .../mailets/CommonMailetConfigurationTest.java | 6 +- .../GatewayRemoteDeliveryIntegrationTest.java | 91 +++++++++++--------- .../RecipientRewriteTableIntegrationTest.java | 4 +- .../org/apache/james/mailets/SieveDelivery.java | 6 +- .../james/mailets/TemporaryJamesServer.java | 42 ++++++++- .../crypto/SMIMEDecryptIntegrationTest.java | 5 +- .../crypto/SMIMESignIntegrationTest.java | 5 +- .../mailets/AmqpForwardAttachmentTest.java | 12 +-- .../transport/mailets/ContactExtractorTest.java | 2 +- .../transport/mailets/GroupMappingTest.java | 4 +- .../mailets/ICSAttachmentWorkflowTest.java | 2 +- .../transport/mailets/StripAttachmentTest.java | 2 +- .../jmap/memory/cucumber/MemoryStepdefs.java | 2 +- 18 files changed, 131 insertions(+), 82 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java index 075f5c4..510a85b 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java @@ -19,6 +19,7 @@ package org.apache.james; import java.util.Arrays; +import java.util.List; import javax.annotation.PreDestroy; @@ -62,6 +63,10 @@ public class GuiceJamesServer { return new GuiceJamesServer(Modules.override(module).with(overrides)); } + public GuiceJamesServer overrideWith(List<Module> overrides) { + return new GuiceJamesServer(Modules.override(module).with(overrides)); + } + public void start() throws Exception { Injector injector = Guice.createInjector(module); preDestroy = injector.getInstance(Key.get(new TypeLiteral<Stager<PreDestroy>>() {})); http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java index 98fe669..38ab031 100644 --- a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java +++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java @@ -19,7 +19,6 @@ package org.apache.james; -import org.apache.james.jmap.send.PostDequeueDecoratorFactory; import org.apache.james.modules.MailboxModule; import org.apache.james.modules.data.MemoryDataJmapModule; import org.apache.james.modules.data.MemoryDataModule; @@ -37,7 +36,6 @@ import org.apache.james.modules.server.MailboxRoutesModule; import org.apache.james.modules.server.MemoryMailQueueModule; import org.apache.james.modules.server.SwaggerRoutesModule; import org.apache.james.modules.server.WebAdminServerModule; -import org.apache.james.queue.api.MailQueueItemDecoratorFactory; import com.google.inject.Module; import com.google.inject.util.Modules; @@ -60,8 +58,7 @@ public class MemoryJamesServerMain { public static final Module jmap = Modules.combine( new MemoryDataJmapModule(), - new JMAPServerModule(), - binder -> binder.bind(MailQueueItemDecoratorFactory.class).to(PostDequeueDecoratorFactory.class)); + new JMAPServerModule()); public static final Module inMemoryServerModule = Modules.combine( new MemoryDataModule(), http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/server/MemoryMailQueueModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/server/MemoryMailQueueModule.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/server/MemoryMailQueueModule.java index 0e2964e..fe41a1c 100644 --- a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/server/MemoryMailQueueModule.java +++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/server/MemoryMailQueueModule.java @@ -19,7 +19,6 @@ package org.apache.james.modules.server; -import org.apache.james.jmap.send.PostDequeueDecoratorFactory; import org.apache.james.queue.api.MailQueueFactory; import com.google.inject.AbstractModule; @@ -30,7 +29,6 @@ public class MemoryMailQueueModule extends AbstractModule { @Override protected void configure() { bind(MemoryMailQueueFactory.class).in(Scopes.SINGLETON); - bind(PostDequeueDecoratorFactory.class).in(Scopes.SINGLETON); bind(MailQueueFactory.class).to(MemoryMailQueueFactory.class); } http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java index 1e18728..ef1bc5d 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java @@ -22,12 +22,12 @@ package org.apache.james.mailets; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailets.configuration.CommonProcessors; import org.apache.james.mailets.configuration.MailetContainer; -import org.apache.james.utils.SMTPMessageSender; import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.probe.DataProbe; import org.apache.james.transport.mailets.AddDeliveredToHeader; import org.apache.james.utils.DataProbeImpl; import org.apache.james.utils.IMAPMessageReader; +import org.apache.james.utils.SMTPMessageSender; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -67,7 +67,7 @@ public class AddDeliveredToHeaderTest { .addProcessor(CommonProcessors.sieveManagerCheck()) .build(); - jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer); + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, mailetContainer); Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with() .pollInterval(slowPacedPollInterval) http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/BounceIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/BounceIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/BounceIntegrationTest.java index c7216df..f8daddb 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/BounceIntegrationTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/BounceIntegrationTest.java @@ -89,7 +89,7 @@ public class BounceIntegrationTest { @Test public void dsnBounceMailetShouldDeliverBounce() throws Exception { - jamesServer = new TemporaryJamesServer(temporaryFolder, + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, generateMailetContainerConfiguration(MailetConfiguration.builder() .matcher(All.class) .mailet(DSNBounce.class) @@ -111,7 +111,7 @@ public class BounceIntegrationTest { @Test public void bounceMailetShouldDeliverBounce() throws Exception { - jamesServer = new TemporaryJamesServer(temporaryFolder, + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, generateMailetContainerConfiguration(MailetConfiguration.builder() .matcher(All.class) .mailet(Bounce.class) @@ -133,7 +133,7 @@ public class BounceIntegrationTest { @Test public void forwardMailetShouldDeliverBounce() throws Exception { - jamesServer = new TemporaryJamesServer(temporaryFolder, + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, generateMailetContainerConfiguration(MailetConfiguration.builder() .matcher(All.class) .mailet(Forward.class) @@ -156,7 +156,7 @@ public class BounceIntegrationTest { @Test public void redirectMailetShouldDeliverBounce() throws Exception { - jamesServer = new TemporaryJamesServer(temporaryFolder, + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, generateMailetContainerConfiguration(MailetConfiguration.builder() .matcher(All.class) .mailet(Redirect.class) @@ -179,7 +179,7 @@ public class BounceIntegrationTest { @Test public void resendMailetShouldDeliverBounce() throws Exception { - jamesServer = new TemporaryJamesServer(temporaryFolder, + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, generateMailetContainerConfiguration(MailetConfiguration.builder() .matcher(All.class) .mailet(Resend.class) @@ -202,7 +202,7 @@ public class BounceIntegrationTest { @Test public void notifySenderMailetShouldDeliverBounce() throws Exception { - jamesServer = new TemporaryJamesServer(temporaryFolder, + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, generateMailetContainerConfiguration(MailetConfiguration.builder() .matcher(All.class) .mailet(NotifySender.class) @@ -224,7 +224,7 @@ public class BounceIntegrationTest { @Test public void notifyPostmasterMailetShouldDeliverBounce() throws Exception { - jamesServer = new TemporaryJamesServer(temporaryFolder, + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, generateMailetContainerConfiguration(MailetConfiguration.builder() .matcher(All.class) .mailet(NotifyPostmaster.class) http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/CommonMailetConfigurationTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/CommonMailetConfigurationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/CommonMailetConfigurationTest.java index c4fc960..67ea84b 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/CommonMailetConfigurationTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/CommonMailetConfigurationTest.java @@ -22,11 +22,11 @@ package org.apache.james.mailets; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailets.configuration.CommonProcessors; import org.apache.james.mailets.configuration.MailetContainer; -import org.apache.james.utils.SMTPMessageSender; import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.probe.DataProbe; -import org.apache.james.utils.IMAPMessageReader; import org.apache.james.utils.DataProbeImpl; +import org.apache.james.utils.IMAPMessageReader; +import org.apache.james.utils.SMTPMessageSender; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -66,7 +66,7 @@ public class CommonMailetConfigurationTest { .addProcessor(CommonProcessors.sieveManagerCheck()) .build(); - jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer); + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, mailetContainer); Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/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 e325ef2..7d4b6d1 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 @@ -28,14 +28,20 @@ import static org.hamcrest.Matchers.hasSize; import java.net.InetAddress; import java.util.concurrent.TimeUnit; +import org.apache.commons.configuration.DefaultConfigurationBuilder; +import org.apache.james.MemoryJamesServerMain; 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.configuration.CommonProcessors; import org.apache.james.mailets.configuration.MailetConfiguration; import org.apache.james.mailets.configuration.MailetContainer; import org.apache.james.mailets.configuration.ProcessorConfiguration; +import org.apache.james.modules.protocols.IMAPServerModule; +import org.apache.james.modules.protocols.ProtocolHandlerModule; +import org.apache.james.modules.protocols.SMTPServerModule; +import org.apache.james.modules.server.CamelMailetContainerModule; +import org.apache.james.modules.server.RawPostDequeueDecoratorModule; import org.apache.james.probe.DataProbe; import org.apache.james.transport.mailets.LocalDelivery; import org.apache.james.transport.mailets.Null; @@ -59,6 +65,8 @@ import org.junit.rules.TemporaryFolder; import org.testcontainers.containers.wait.HostPortWaitStrategy; import com.google.common.base.Charsets; +import com.google.inject.Module; +import com.google.inject.util.Modules; import com.jayway.awaitility.Awaitility; import com.jayway.awaitility.Duration; import com.jayway.awaitility.core.ConditionFactory; @@ -77,6 +85,16 @@ public class GatewayRemoteDeliveryIntegrationTest { private static final String FROM = "from@" + JAMES_APACHE_ORG; private static final String RECIPIENT = "touser@" + JAMES_ANOTHER_DOMAIN; + private static final Module SMTP_ONLY_MODULE = Modules.combine( + MemoryJamesServerMain.inMemoryServerModule, + new ProtocolHandlerModule(), + new SMTPServerModule(), + new RawPostDequeueDecoratorModule(), + binder -> binder.bind(CamelMailetContainerModule.DefaultProcessorsConfigurationSupplier.class) + .toInstance(DefaultConfigurationBuilder::new)); + private static final Module SMTP_AND_IMAP_MODULE = Modules.combine( + SMTP_ONLY_MODULE, + new IMAPServerModule()); @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); @@ -94,7 +112,6 @@ public class GatewayRemoteDeliveryIntegrationTest { private ConditionFactory calmlyAwait; private DataProbe dataProbe; - @Before public void setup() throws Exception { Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; @@ -125,8 +142,9 @@ public class GatewayRemoteDeliveryIntegrationTest { public void outgoingMailShouldTransitThroughGatewayWhenNoPort() throws Exception { String gatewayProperty = fakeSmtp.getContainerIp(); - jamesServer = new TemporaryJamesServer(temporaryFolder, - generateMailetContainerConfiguration(gatewayProperty)); + jamesServer = TemporaryJamesServer.builder() + .withBase(SMTP_ONLY_MODULE) + .build(temporaryFolder, generateMailetContainerConfiguration(gatewayProperty)); dataProbe = jamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(JAMES_APACHE_ORG); @@ -143,8 +161,9 @@ public class GatewayRemoteDeliveryIntegrationTest { public void outgoingMailShouldTransitThroughGatewayWhenPort() throws Exception { String gatewayProperty = fakeSmtp.getContainerIp() + ":25"; - jamesServer = new TemporaryJamesServer(temporaryFolder, - generateMailetContainerConfiguration(gatewayProperty)); + jamesServer = TemporaryJamesServer.builder() + .withBase(SMTP_ONLY_MODULE) + .build(temporaryFolder, generateMailetContainerConfiguration(gatewayProperty)); dataProbe = jamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(JAMES_APACHE_ORG); @@ -161,8 +180,9 @@ public class GatewayRemoteDeliveryIntegrationTest { public void outgoingMailShouldTransitThroughGatewayWhenSeveralIps() throws Exception { String gatewayProperty = fakeSmtp.getContainerIp() + ",invalid.domain"; - jamesServer = new TemporaryJamesServer(temporaryFolder, - generateMailetContainerConfiguration(gatewayProperty)); + jamesServer = TemporaryJamesServer.builder() + .withBase(SMTP_ONLY_MODULE) + .build(temporaryFolder, generateMailetContainerConfiguration(gatewayProperty)); dataProbe = jamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(JAMES_APACHE_ORG); @@ -179,8 +199,9 @@ public class GatewayRemoteDeliveryIntegrationTest { public void outgoingMailShouldFallbackToSecondGatewayWhenFirstInvalid() throws Exception { String gatewayProperty = "invalid.domain," + fakeSmtp.getContainerIp(); - jamesServer = new TemporaryJamesServer(temporaryFolder, - generateMailetContainerConfiguration(gatewayProperty)); + jamesServer = TemporaryJamesServer.builder() + .withBase(SMTP_ONLY_MODULE) + .build(temporaryFolder, generateMailetContainerConfiguration(gatewayProperty)); dataProbe = jamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(JAMES_APACHE_ORG); @@ -200,9 +221,10 @@ public class GatewayRemoteDeliveryIntegrationTest { InetAddress containerIp = InetAddress.getByName(fakeSmtp.getContainerIp()); inMemoryDNSService.registerRecord(JAMES_ANOTHER_DOMAIN, containerIp, JAMES_ANOTHER_DOMAIN); - jamesServer = new TemporaryJamesServer(temporaryFolder, - generateMailetContainerConfiguration(gatewayProperty), - binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)); + jamesServer = TemporaryJamesServer.builder() + .withBase(SMTP_ONLY_MODULE) + .withOverrides(binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)) + .build(temporaryFolder, generateMailetContainerConfiguration(gatewayProperty)); dataProbe = jamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(JAMES_APACHE_ORG); @@ -226,16 +248,17 @@ public class GatewayRemoteDeliveryIntegrationTest { InetAddress containerIp = InetAddress.getByName(fakeSmtp.getContainerIp()); inMemoryDNSService.registerRecord(JAMES_ANOTHER_DOMAIN, containerIp, JAMES_ANOTHER_DOMAIN); - jamesServer = new TemporaryJamesServer(temporaryFolder, - MailetContainer.builder() + jamesServer = TemporaryJamesServer.builder() + .withBase(SMTP_AND_IMAP_MODULE) + .withOverrides(binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)) + .build(temporaryFolder, MailetContainer.builder() .postmaster("postmaster@" + JAMES_APACHE_ORG) .threads(5) .addProcessor(root()) .addProcessor(CommonProcessors.error()) .addProcessor(relayAndLocalDeliveryTransport(gatewayProperty)) .addProcessor(CommonProcessors.bounces()) - .build(), - binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)); + .build()); dataProbe = jamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(JAMES_APACHE_ORG); @@ -257,8 +280,10 @@ public class GatewayRemoteDeliveryIntegrationTest { InetAddress containerIp = InetAddress.getByName(fakeSmtp.getContainerIp()); inMemoryDNSService.registerRecord(JAMES_ANOTHER_DOMAIN, containerIp, JAMES_ANOTHER_DOMAIN); - jamesServer = new TemporaryJamesServer(temporaryFolder, - MailetContainer.builder() + jamesServer = TemporaryJamesServer.builder() + .withBase(SMTP_AND_IMAP_MODULE) + .withOverrides(binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)) + .build(temporaryFolder, MailetContainer.builder() .postmaster("postmaster@" + JAMES_APACHE_ORG) .threads(5) .addProcessor(root()) @@ -273,10 +298,6 @@ public class GatewayRemoteDeliveryIntegrationTest { .build()) .addMailet(MailetConfiguration.builder() .matcher(RecipientIsLocal.class) - .mailet(VacationMailet.class) - .build()) - .addMailet(MailetConfiguration.builder() - .matcher(RecipientIsLocal.class) .mailet(LocalDelivery.class) .build()) .addMailet(MailetConfiguration.builder() @@ -292,8 +313,7 @@ public class GatewayRemoteDeliveryIntegrationTest { .build()) .build()) .addProcessor(CommonProcessors.bounces()) - .build(), - binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)); + .build()); dataProbe = jamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(JAMES_APACHE_ORG); @@ -314,16 +334,17 @@ public class GatewayRemoteDeliveryIntegrationTest { InetAddress containerIp = InetAddress.getByName(fakeSmtp.getContainerIp()); inMemoryDNSService.registerRecord(JAMES_ANOTHER_DOMAIN, containerIp, JAMES_ANOTHER_DOMAIN); - jamesServer = new TemporaryJamesServer(temporaryFolder, - MailetContainer.builder() + jamesServer = TemporaryJamesServer.builder() + .withBase(SMTP_ONLY_MODULE) + .withOverrides(binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)) + .build(temporaryFolder, MailetContainer.builder() .postmaster("postmaster@" + JAMES_APACHE_ORG) .threads(5) .addProcessor(root()) .addProcessor(CommonProcessors.error()) .addProcessor(directResolutionTransport()) .addProcessor(CommonProcessors.bounces()) - .build(), - binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)); + .build()); dataProbe = jamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(JAMES_APACHE_ORG); @@ -394,10 +415,6 @@ public class GatewayRemoteDeliveryIntegrationTest { .addProperty("name", "bcc") .build()) .addMailet(MailetConfiguration.builder() - .matcher(RecipientIsLocal.class) - .mailet(VacationMailet.class) - .build()) - .addMailet(MailetConfiguration.builder() .matcher(All.class) .mailet(RemoteDelivery.class) .addProperty("outgoingQueue", "outgoing") @@ -423,10 +440,6 @@ public class GatewayRemoteDeliveryIntegrationTest { .build()) .addMailet(MailetConfiguration.builder() .matcher(RecipientIsLocal.class) - .mailet(VacationMailet.class) - .build()) - .addMailet(MailetConfiguration.builder() - .matcher(RecipientIsLocal.class) .mailet(LocalDelivery.class) .build()) .addMailet(MailetConfiguration.builder() @@ -454,10 +467,6 @@ public class GatewayRemoteDeliveryIntegrationTest { .addProperty("name", "bcc") .build()) .addMailet(MailetConfiguration.builder() - .matcher(RecipientIsLocal.class) - .mailet(VacationMailet.class) - .build()) - .addMailet(MailetConfiguration.builder() .matcher(All.class) .mailet(RemoteDelivery.class) .addProperty("outgoingQueue", "outgoing") http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RecipientRewriteTableIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RecipientRewriteTableIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RecipientRewriteTableIntegrationTest.java index 931fdfe..3b6a061 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RecipientRewriteTableIntegrationTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RecipientRewriteTableIntegrationTest.java @@ -22,11 +22,11 @@ package org.apache.james.mailets; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailets.configuration.CommonProcessors; import org.apache.james.mailets.configuration.MailetContainer; -import org.apache.james.utils.SMTPMessageSender; import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.probe.DataProbe; import org.apache.james.utils.DataProbeImpl; import org.apache.james.utils.IMAPMessageReader; +import org.apache.james.utils.SMTPMessageSender; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -77,7 +77,7 @@ public class RecipientRewriteTableIntegrationTest { .addProcessor(CommonProcessors.sieveManagerCheck()) .build(); - jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer); + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, mailetContainer); Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await(); dataProbe = jamesServer.getProbe(DataProbeImpl.class); http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SieveDelivery.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SieveDelivery.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SieveDelivery.java index b80f3a9..11aa9e6 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SieveDelivery.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SieveDelivery.java @@ -23,12 +23,12 @@ import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.store.probe.MailboxProbe; import org.apache.james.mailets.configuration.CommonProcessors; import org.apache.james.mailets.configuration.MailetContainer; -import org.apache.james.utils.SMTPMessageSender; import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.modules.protocols.SieveProbeImpl; import org.apache.james.probe.DataProbe; -import org.apache.james.utils.IMAPMessageReader; import org.apache.james.utils.DataProbeImpl; +import org.apache.james.utils.IMAPMessageReader; +import org.apache.james.utils.SMTPMessageSender; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -68,7 +68,7 @@ public class SieveDelivery { .addProcessor(CommonProcessors.sieveManagerCheck()) .build(); - jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer); + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, mailetContainer); Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java index 3ebaa1e..6fc4496 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java @@ -25,6 +25,9 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; import org.apache.activemq.store.PersistenceAdapter; import org.apache.activemq.store.memory.MemoryPersistenceAdapter; @@ -39,22 +42,55 @@ import org.apache.james.webadmin.WebAdminConfiguration; import org.apache.james.webadmin.WebAdminUtils; import org.junit.rules.TemporaryFolder; +import com.google.common.collect.ImmutableList; import com.google.inject.Module; public class TemporaryJamesServer { + public static class Builder { + private ImmutableList.Builder<Module> overrideModules; + private Optional<Module> module; + + private Builder() { + overrideModules = ImmutableList.builder(); + module = Optional.empty(); + } + + public Builder withBase(Module module) { + this.module = Optional.of(module); + return this; + } + + public Builder withOverrides(Module... modules) { + this.overrideModules.addAll(Arrays.asList(modules)); + return this; + } + + public TemporaryJamesServer build(TemporaryFolder temporaryFolder, MailetContainer mailetContainer) throws Exception { + return new TemporaryJamesServer( + temporaryFolder, + mailetContainer, + module.orElse(MemoryJamesServerMain.inMemoryServerAggregateModule), + overrideModules.build()); + } + } + + public static Builder builder() { + return new Builder(); + } + private static final String MAILETCONTAINER_CONFIGURATION_FILENAME = "mailetcontainer.xml"; private static final int LIMIT_TO_3_MESSAGES = 3; private final GuiceJamesServer jamesServer; - - public TemporaryJamesServer(TemporaryFolder temporaryFolder, MailetContainer mailetContainer, Module... additionalModules) throws Exception { + private TemporaryJamesServer(TemporaryFolder temporaryFolder, MailetContainer mailetContainer, + Module serverBaseModule, List<Module> additionalModules) throws Exception { appendMailetConfigurations(temporaryFolder, mailetContainer); jamesServer = new GuiceJamesServer() - .combineWith(MemoryJamesServerMain.inMemoryServerAggregateModule) + .combineWith(serverBaseModule) .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class)) .overrideWith(additionalModules) .overrideWith(new TestJMAPServerModule(LIMIT_TO_3_MESSAGES)) http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java index 3d09a73..d8084dc 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java @@ -104,8 +104,9 @@ public class SMIMEDecryptIntegrationTest { .build()) .build(); - jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer, - binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(() -> DATE_2015)); + jamesServer = TemporaryJamesServer.builder() + .withOverrides(binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(() -> DATE_2015)) + .build(temporaryFolder, mailetContainer); Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await(); http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java index bee6474..1561c54 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java @@ -148,8 +148,9 @@ public class SMIMESignIntegrationTest { .addProcessor(CommonProcessors.sieveManagerCheck()) .build(); - jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer, - binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(() -> DATE_2015)); + jamesServer = TemporaryJamesServer.builder() + .withOverrides(binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(() -> DATE_2015)) + .build(temporaryFolder, mailetContainer); Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await(); http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java index fd13da2..04471a0 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java @@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat; import javax.mail.internet.MimeMessage; +import org.apache.james.core.MailAddress; import org.apache.james.jmap.mailet.VacationMailet; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailets.TemporaryJamesServer; @@ -30,17 +31,16 @@ import org.apache.james.mailets.configuration.CommonProcessors; import org.apache.james.mailets.configuration.MailetConfiguration; import org.apache.james.mailets.configuration.MailetContainer; import org.apache.james.mailets.configuration.ProcessorConfiguration; -import org.apache.james.transport.matchers.All; -import org.apache.james.transport.matchers.RecipientIsLocal; -import org.apache.james.utils.SMTPMessageSender; import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.probe.DataProbe; import org.apache.james.transport.mailets.amqp.AmqpRule; +import org.apache.james.transport.matchers.All; +import org.apache.james.transport.matchers.RecipientIsLocal; import org.apache.james.util.streams.SwarmGenericContainer; -import org.apache.james.utils.IMAPMessageReader; import org.apache.james.utils.DataProbeImpl; +import org.apache.james.utils.IMAPMessageReader; +import org.apache.james.utils.SMTPMessageSender; import org.apache.mailet.Mail; -import org.apache.james.core.MailAddress; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.MimeMessageBuilder; import org.junit.After; @@ -130,7 +130,7 @@ public class AmqpForwardAttachmentTest { .build()) .build(); - jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer); + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, mailetContainer); Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with() .pollInterval(slowPacedPollInterval) http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java index 16eeb89..16ef6a8 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java @@ -114,7 +114,7 @@ public class ContactExtractorTest { .build()) .build()) .build(); - jamesServer = new TemporaryJamesServer(folder, mailets); + jamesServer = TemporaryJamesServer.builder().build(folder, mailets); DataProbeImpl probe = jamesServer.getProbe(DataProbeImpl.class); probe.addDomain(JAMES_ORG); probe.addUser(SENDER, PASSWORD); http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/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 0e5e18f..0222ce0 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 @@ -166,7 +166,9 @@ public class GroupMappingTest { .build()) .build(); - jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer, (binder) -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)); + jamesServer = TemporaryJamesServer.builder() + .withOverrides(binder -> binder.bind(DNSService.class).toInstance(inMemoryDNSService)) + .build(temporaryFolder, mailetContainer); Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await(); http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java index 3a9f664..e44853e 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java @@ -517,7 +517,7 @@ public class ICSAttachmentWorkflowTest { .build()) .build(); - jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer); + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, mailetContainer); Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await(); http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java index 132b661..f32fb0c 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java @@ -111,7 +111,7 @@ public class StripAttachmentTest { .build()) .build(); - jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer); + jamesServer = TemporaryJamesServer.builder().build(temporaryFolder, mailetContainer); Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await(); http://git-wip-us.apache.org/repos/asf/james-project/blob/9ad16167/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java index 89d4b87..138b1ed 100644 --- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java +++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java @@ -52,7 +52,7 @@ public class MemoryStepdefs { temporaryFolder.create(); mainStepdefs.messageIdFactory = new InMemoryMessageId.Factory(); mainStepdefs.jmapServer = new GuiceJamesServer() - .combineWith(MemoryJamesServerMain.inMemoryServerModule) + .combineWith(MemoryJamesServerMain.inMemoryServerAggregateModule) .overrideWith(new MemoryJmapServerModule(temporaryFolder), (binder) -> binder.bind(MessageId.Factory.class).toInstance(mainStepdefs.messageIdFactory)) .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class)); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org