james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [40/44] james-project git commit: JAMES-2267 Improve code quality of MailetErrorsTest
Date Fri, 05 Jan 2018 02:56:59 GMT
JAMES-2267 Improve code quality of MailetErrorsTest


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

Branch: refs/heads/improve-mailet-testing-experience-v1
Commit: 4a34bf26a2f67b5692645613ca5fa0bf82aacac1
Parents: 1c52910
Author: benwa <btellier@linagora.com>
Authored: Wed Jan 3 11:38:47 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Jan 5 09:34:39 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailets/MailetErrorsTest.java  | 583 +++++++------------
 .../impl/camel/CamelMailetProcessor.java        |   7 +-
 .../impl/camel/CamelProcessor.java              |   4 +-
 .../impl/camel/MatcherSplitter.java             |   4 +-
 4 files changed, 222 insertions(+), 376 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4a34bf26/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java
index 127a2ff..e912faa 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java
@@ -21,63 +21,41 @@ package org.apache.james.mailets;
 
 import static org.apache.james.MemoryJamesServerMain.SMTP_ONLY_MODULE;
 import static org.apache.james.mailets.configuration.CommonProcessors.ERROR_REPOSITORY;
+import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
+import static org.apache.james.mailets.configuration.Constants.FROM;
+import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
+import static org.apache.james.mailets.configuration.Constants.SMTP_PORT;
+import static org.apache.james.mailets.configuration.Constants.awaitOneMinute;
 
+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.probe.DataProbe;
 import org.apache.james.transport.mailets.ErrorMailet;
 import org.apache.james.transport.mailets.ErrorMatcher;
 import org.apache.james.transport.mailets.NoopMailet;
-import org.apache.james.transport.mailets.RemoveMimeHeader;
+import org.apache.james.transport.mailets.Null;
 import org.apache.james.transport.mailets.RuntimeErrorMailet;
 import org.apache.james.transport.mailets.RuntimeErrorMatcher;
 import org.apache.james.transport.mailets.ToRepository;
 import org.apache.james.transport.matchers.All;
-import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.MailRepositoryProbeImpl;
 import org.apache.james.utils.SMTPMessageSender;
-import org.apache.mailet.Mail;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
-import com.jayway.awaitility.Awaitility;
-import com.jayway.awaitility.Duration;
-import com.jayway.awaitility.core.ConditionFactory;
-
 public class MailetErrorsTest {
-    private static final String LOCALHOST_IP = "127.0.0.1";
-    private static final int SMTP_PORT = 1025;
-    private static final String PASSWORD = "secret";
-
-    private static final String JAMES_APACHE_ORG = "james.org";
-    private static final String JAMES_ANOTHER_DOMAIN = "james.com";
-
-    private static final String FROM = "from@" + JAMES_APACHE_ORG;
-    private static final String RECIPIENT = "touser@" + JAMES_ANOTHER_DOMAIN;
     public static final String CUSTOM_PROCESSOR = "custom";
-    public static final String CUSTOM_REPOSITORY = "file://var/mail/error/";
+    public static final String CUSTOM_REPOSITORY = "file://var/mail/custom/";
 
     @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    @Rule
+    public SMTPMessageSender smtpMessageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
 
     private TemporaryJamesServer jamesServer;
-    private ConditionFactory calmlyAwait;
-    private DataProbe dataProbe;
-
-    @Before
-    public void setup() throws Exception {
-        Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
-        calmlyAwait = Awaitility.with()
-            .pollInterval(slowPacedPollInterval)
-            .and()
-            .with()
-            .pollDelay(slowPacedPollInterval)
-            .await();
-    }
 
     @After
     public void tearDown() {
@@ -90,454 +68,327 @@ public class MailetErrorsTest {
     public void mailetProcessorsShouldHandleMessagingException() throws Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(All.class)
-                            .mailet(ErrorMailet.class)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(ErrorMailet.class))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1);
-        }
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1);
     }
 
     @Test
     public void mailetProcessorsShouldHandleRuntimeException() throws Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(All.class)
-                            .mailet(RuntimeErrorMailet.class)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(RuntimeErrorMailet.class))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1);
-        }
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1);
     }
 
     @Test
     public void mailetProcessorsShouldHandleMessagingExceptionWhenSpecificErrorHandlingSpecified()
throws Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(customProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(All.class)
-                            .mailet(ErrorMailet.class)
-                            .addProperty("onMailetException", CUSTOM_PROCESSOR)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(customProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(ErrorMailet.class)
+                        .addProperty("onMailetException", CUSTOM_PROCESSOR))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) ==
1);
 
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
-        }
     }
 
     @Test
     public void mailetProcessorsShouldHandleRuntimeExceptionWhenSpecificErrorHandlingSpecified()
throws Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(customProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(All.class)
-                            .mailet(RuntimeErrorMailet.class)
-                            .addProperty("onMailetException", CUSTOM_PROCESSOR)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(customProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(RuntimeErrorMailet.class)
+                        .addProperty("onMailetException", CUSTOM_PROCESSOR))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
-        }
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) ==
1);
     }
 
     @Test
     public void onExceptionIgnoreShouldContinueProcessingWhenRuntimeException() throws Exception
{
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(customProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(All.class)
-                            .mailet(RuntimeErrorMailet.class)
-                            .addProperty("onMailetException", "ignore")
-                            .build())
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(All.class)
-                            .mailet(ToRepository.class)
-                            .addProperty("repositoryPath", CUSTOM_REPOSITORY)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(customProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(RuntimeErrorMailet.class)
+                        .addProperty("onMailetException", "ignore"))
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(ToRepository.class)
+                        .addProperty("repositoryPath", CUSTOM_REPOSITORY))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
-
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
-        }
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) ==
1);
     }
 
     @Test
     public void onExceptionIgnoreShouldContinueProcessingWhenMessagingException() throws
Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(customProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(All.class)
-                            .mailet(ErrorMailet.class)
-                            .addProperty("onMailetException", "ignore")
-                            .build())
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(All.class)
-                            .mailet(ToRepository.class)
-                            .addProperty("repositoryPath", CUSTOM_REPOSITORY)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(customProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(ErrorMailet.class)
+                        .addProperty("onMailetException", "ignore"))
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(ToRepository.class)
+                        .addProperty("repositoryPath", CUSTOM_REPOSITORY))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
-        }
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) ==
1);
     }
 
     @Test
     public void matcherProcessorsShouldHandleMessagingException() throws Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(ErrorMatcher.class)
-                            .mailet(NoopMailet.class)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(ErrorMatcher.class)
+                        .mailet(NoopMailet.class))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1);
-        }
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1);
     }
 
     @Test
     public void matcherProcessorsShouldHandleRuntimeException() throws Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(RuntimeErrorMatcher.class)
-                            .mailet(NoopMailet.class)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(RuntimeErrorMatcher.class)
+                        .mailet(NoopMailet.class))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
-
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1);
-        }
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(ERROR_REPOSITORY) == 1);
     }
 
     @Test
     public void matcherProcessorsShouldHandleMessagingExceptionWhenSpecificErrorHandlingSpecified()
throws Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(customProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(ErrorMatcher.class)
-                            .mailet(NoopMailet.class)
-                            .addProperty("onMailetException", CUSTOM_PROCESSOR)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(customProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(ErrorMatcher.class)
+                        .mailet(NoopMailet.class)
+                        .addProperty("onMatchException", CUSTOM_PROCESSOR))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
-        }
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) ==
1);
     }
 
     @Test
     public void matcherProcessorsShouldHandleRuntimeExceptionWhenSpecificErrorHandlingSpecified()
throws Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(customProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(RuntimeErrorMatcher.class)
-                            .mailet(NoopMailet.class)
-                            .addProperty("onMailetException", CUSTOM_PROCESSOR)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(customProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(RuntimeErrorMatcher.class)
+                        .mailet(NoopMailet.class)
+                        .addProperty("onMatchException", CUSTOM_PROCESSOR))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
-
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
-        }
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) ==
1);
     }
 
     @Test
-    public void onMatcherExceptionIgnoreShouldContinueProcessingWhenRuntimeException() throws
Exception {
+    public void onMatcherExceptionIgnoreShouldNotMatchWhenRuntimeExceptionAndNoMatchConfigured()
throws Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(customProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(RuntimeErrorMatcher.class)
-                            .mailet(NoopMailet.class)
-                            .addProperty("onMailetException", "ignore")
-                            .build())
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(All.class)
-                            .mailet(ToRepository.class)
-                            .addProperty("repositoryPath", CUSTOM_REPOSITORY)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(customProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(RuntimeErrorMatcher.class)
+                        .mailet(Null.class)
+                        .addProperty("onMatchException", "nomatch"))
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(ToRepository.class)
+                        .addProperty("repositoryPath", CUSTOM_REPOSITORY))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) ==
1);
+    }
 
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
-        }
+    @Test
+    public void onMatcherExceptionIgnoreShouldNotMatchWhenMessagingExceptionAndNoMatchConfigured()
throws Exception {
+        jamesServer = TemporaryJamesServer.builder()
+            .withBase(SMTP_ONLY_MODULE)
+            .withMailetContainer(MailetContainer.builder()
+                .addProcessor(CommonProcessors.deliverOnlyTransport())
+                .addProcessor(errorProcessor())
+                .addProcessor(customProcessor())
+                .addProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(ErrorMatcher.class)
+                        .mailet(Null.class)
+                        .addProperty("onMatchException", "nomatch"))
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(ToRepository.class)
+                        .addProperty("repositoryPath", CUSTOM_REPOSITORY))))
+            .build(temporaryFolder);
+        MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
+
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
+
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) ==
1);
     }
 
     @Test
-    public void onMatcherExceptionIgnoreShouldContinueProcessingWhenMessagingException()
throws Exception {
+    public void onMatcherExceptionIgnoreShouldMatchWhenRuntimeExceptionAndAllMatchConfigured()
throws Exception {
         jamesServer = TemporaryJamesServer.builder()
             .withBase(SMTP_ONLY_MODULE)
-            .build(temporaryFolder,
-                MailetContainer.builder()
-                    .threads(2)
-                    .postmaster("postmaster@localhost")
-                    .addProcessor(emptyTransport())
-                    .addProcessor(errorProcessor())
-                    .addProcessor(customProcessor())
-                    .addProcessor(ProcessorConfiguration.builder()
-                        .state(Mail.DEFAULT)
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(ErrorMatcher.class)
-                            .mailet(NoopMailet.class)
-                            .addProperty("onMailetException", "ignore")
-                            .build())
-                        .addMailet(MailetConfiguration.builder()
-                            .matcher(All.class)
-                            .mailet(ToRepository.class)
-                            .addProperty("repositoryPath", CUSTOM_REPOSITORY)
-                            .build())
-                        .build())
-                    .build());
-        dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+            .withMailetContainer(MailetContainer.builder()
+                .putProcessor(CommonProcessors.deliverOnlyTransport())
+                .putProcessor(errorProcessor())
+                .putProcessor(customProcessor())
+                .putProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(RuntimeErrorMatcher.class)
+                        .mailet(ToRepository.class)
+                        .addProperty("repositoryPath", CUSTOM_REPOSITORY)
+                        .addProperty("onMatchException", "matchall"))
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(Null.class))))
+            .build(temporaryFolder);
         MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
 
-        dataProbe.addDomain(JAMES_APACHE_ORG);
-        dataProbe.addUser(FROM, PASSWORD);
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
 
-        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP,
SMTP_PORT, JAMES_APACHE_ORG)) {
-            messageSender.sendMessage(FROM, RECIPIENT);
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) ==
1);
+    }
 
-            calmlyAwait.atMost(Duration.TEN_SECONDS)
-                .until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
-        }
+    @Test
+    public void onMatcherExceptionIgnoreShouldMatchWhenMessagingExceptionAndAllMatchConfigured()
throws Exception {
+        jamesServer = TemporaryJamesServer.builder()
+            .withBase(SMTP_ONLY_MODULE)
+            .withMailetContainer(MailetContainer.builder()
+                .putProcessor(CommonProcessors.deliverOnlyTransport())
+                .putProcessor(errorProcessor())
+                .putProcessor(customProcessor())
+                .putProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(ErrorMatcher.class)
+                        .mailet(ToRepository.class)
+                        .addProperty("repositoryPath", CUSTOM_REPOSITORY)
+                        .addProperty("onMatchException", "matchall"))
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(Null.class))))
+            .build(temporaryFolder);
+        MailRepositoryProbeImpl probe = jamesServer.getProbe(MailRepositoryProbeImpl.class);
+
+        smtpMessageSender.connect(LOCALHOST_IP, SMTP_PORT).sendMessage(FROM, FROM);
+
+        awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) ==
1);
     }
 
-    private ProcessorConfiguration errorProcessor() {
-        return ProcessorConfiguration.builder()
-            .state(Mail.ERROR)
-            .enableJmx(true)
+    private ProcessorConfiguration.Builder errorProcessor() {
+        return ProcessorConfiguration.error()
             .addMailet(MailetConfiguration.builder()
                 .matcher(All.class)
                 .mailet(ToRepository.class)
-                .addProperty("repositoryPath", ERROR_REPOSITORY)
-                .build())
-            .build();
+                .addProperty("repositoryPath", ERROR_REPOSITORY));
     }
 
-    private ProcessorConfiguration customProcessor() {
+    private ProcessorConfiguration.Builder customProcessor() {
         return ProcessorConfiguration.builder()
             .state("custom")
-            .enableJmx(true)
             .addMailet(MailetConfiguration.builder()
                 .matcher(All.class)
                 .mailet(ToRepository.class)
-                .addProperty("repositoryPath", CUSTOM_REPOSITORY)
-                .build())
-            .build();
-    }
-
-    private ProcessorConfiguration emptyTransport() {
-        return ProcessorConfiguration.builder()
-            .state("transport")
-            .addMailet(MailetConfiguration.builder()
-                .matcher(All.class)
-                .mailet(RemoveMimeHeader.class)
-                .addProperty("name", "bcc")
-                .build())
-            .build();
+                .addProperty("repositoryPath", CUSTOM_REPOSITORY));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4a34bf26/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
index 0884ff2..42dbaed 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
@@ -33,7 +33,6 @@ import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
-import org.apache.james.mailetcontainer.impl.MailetConfigImpl;
 import org.apache.james.mailetcontainer.impl.MatcherMailetPair;
 import org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor;
 import org.apache.james.metrics.api.MetricFactory;
@@ -161,12 +160,8 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor
implement
                 Matcher matcher = pair.getMatcher();
                 Mailet mailet = pair.getMailet();
 
-                String onMatchException = null;
                 MailetConfig mailetConfig = mailet.getMailetConfig();
-
-                if (mailetConfig instanceof MailetConfigImpl) {
-                    onMatchException = ((MailetConfigImpl) mailetConfig).getInitAttribute("onMatchException");
-                }
+                String onMatchException = mailetConfig.getInitParameter("onMatchException");
 
                 CamelProcessor mailetProccessor = new CamelProcessor(metricFactory, mailet,
CamelMailetProcessor.this);
                 // Store the matcher to use for splitter in properties

http://git-wip-us.apache.org/repos/asf/james-project/blob/4a34bf26/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
index d82f127..e5da468 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
@@ -88,14 +88,14 @@ public class CamelProcessor implements Processor {
 
             MailetConfig mailetConfig = mailet.getMailetConfig();
             if (mailetConfig instanceof MailetConfigImpl) {
-                onMailetException = ((MailetConfigImpl) mailetConfig).getInitAttribute("onMailetException");
+                onMailetException = mailetConfig.getInitParameter("onMailetException");
             }
             if (onMailetException == null) {
                 onMailetException = Mail.ERROR;
             } else {
                 onMailetException = onMailetException.trim().toLowerCase(Locale.US);
             }
-            if (onMailetException.compareTo("ignore") == 0) {
+            if (onMailetException.equalsIgnoreCase("ignore")) {
                 // ignore the exception and continue
                 // this option should not be used if the mail object can be
                 // changed by the mailet

http://git-wip-us.apache.org/repos/asf/james-project/blob/4a34bf26/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
index 64f00c1..876ce6a 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
@@ -127,12 +127,12 @@ public class MatcherSplitter {
                 } else {
                     onMatchException = onMatchException.trim().toLowerCase(Locale.US);
                 }
-                if (onMatchException.compareTo("nomatch") == 0) {
+                if (onMatchException.equalsIgnoreCase("nomatch")) {
                     // In case the matcher returned null, create an empty
                     // Collection
                     LOGGER.warn("Encountered error while executing matcher {}. Matching none.",
matcher, ex);
                     matchedRcpts = new ArrayList<>(0);
-                } else if (onMatchException.compareTo("matchall") == 0) {
+                } else if (onMatchException.equalsIgnoreCase("matchall")) {
                     LOGGER.warn("Encountered error while executing matcher {}. matching all.",
matcher, ex);
                     matchedRcpts = mail.getRecipients();
                     // no need to verify addresses


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