james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/9] james-project git commit: JAMES-2263 Added integration testing proposed in review
Date Wed, 03 Jan 2018 03:20:35 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 77125c1fe -> ab8ea00cd


JAMES-2263 Added integration testing proposed in review


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

Branch: refs/heads/master
Commit: 23353aed5cf053e4913afe54a3de123f8298935a
Parents: d730186
Author: apptaro <apptaro@gmail.com>
Authored: Thu Dec 28 18:23:41 2017 +0900
Committer: benwa <btellier@linagora.com>
Committed: Wed Jan 3 10:16:13 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailets/MailetErrorsTest.java  | 330 +++++++++++++++++++
 .../mailets/configuration/CommonProcessors.java |   6 +-
 .../james/transport/mailets/ErrorMailet.java    |  32 ++
 .../transport/mailets/RuntimeErrorMailet.java   |  32 ++
 4 files changed, 398 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/23353aed/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
new file mode 100644
index 0000000..40a37b9
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/MailetErrorsTest.java
@@ -0,0 +1,330 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+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 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.RemoveMimeHeader;
+import org.apache.james.transport.mailets.RuntimeErrorMailet;
+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/";
+
+    @Rule
+    public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+    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() {
+        if (jamesServer != null) {
+            jamesServer.shutdown();
+        }
+    }
+
+    @Test
+    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);
+        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);
+
+            calmlyAwait.atMost(Duration.TEN_SECONDS)
+                .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);
+        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);
+
+            calmlyAwait.atMost(Duration.TEN_SECONDS)
+                .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);
+        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);
+
+            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);
+        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);
+
+            calmlyAwait.atMost(Duration.TEN_SECONDS)
+                .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);
+        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);
+
+            calmlyAwait.atMost(Duration.TEN_SECONDS)
+                .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);
+        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);
+
+            calmlyAwait.atMost(Duration.TEN_SECONDS)
+                .until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1);
+        }
+    }
+
+    private ProcessorConfiguration errorProcessor() {
+        return ProcessorConfiguration.builder()
+            .state(Mail.ERROR)
+            .enableJmx(true)
+            .addMailet(MailetConfiguration.builder()
+                .matcher(All.class)
+                .mailet(ToRepository.class)
+                .addProperty("repositoryPath", ERROR_REPOSITORY)
+                .build())
+            .build();
+    }
+
+    private ProcessorConfiguration 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();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/23353aed/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
index 130dae7..7e5938e 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
@@ -47,7 +47,9 @@ import org.apache.mailet.Mail;
 
 public class CommonProcessors {
 
-    public static ProcessorConfiguration root() {
+	public static final String ERROR_REPOSITORY = "file://var/mail/error/";
+
+	public static ProcessorConfiguration root() {
         return ProcessorConfiguration.builder()
                 .state("root")
                 .enableJmx(true)
@@ -114,7 +116,7 @@ public class CommonProcessors {
                 .addMailet(MailetConfiguration.builder()
                         .matcher(All.class)
                         .mailet(ToRepository.class)
-                        .addProperty("repositoryPath", "file://var/mail/error/")
+                        .addProperty("repositoryPath", ERROR_REPOSITORY)
                         .build())
                 .build();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/23353aed/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ErrorMailet.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ErrorMailet.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ErrorMailet.java
new file mode 100644
index 0000000..3d7ba53
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ErrorMailet.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.mailets;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMailet;
+
+public class ErrorMailet extends GenericMailet {
+    @Override
+    public void service(Mail mail) throws MessagingException {
+        throw new MessagingException();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/23353aed/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/RuntimeErrorMailet.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/RuntimeErrorMailet.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/RuntimeErrorMailet.java
new file mode 100644
index 0000000..154c5ec
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/RuntimeErrorMailet.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.mailets;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMailet;
+
+public class RuntimeErrorMailet extends GenericMailet {
+    @Override
+    public void service(Mail mail) throws MessagingException {
+        throw new RuntimeException();
+    }
+}


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