This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 1d451515a633bbc5c3d4178c2d2320b8c514e2a2
Author: Benoit Tellier <[email protected]>
AuthorDate: Wed Nov 18 13:41:59 2020 +0700

    JAMES-3441 Integration test for starting James with a disabled spooler
    
    This enables starting James instances not involved in mail processing
---
 .../java/org/apache/james/DisabledSpoolerTest.java | 84 ++++++++++++++++++++++
 .../src/test/resources/mailetcontainer.xml         |  1 +
 2 files changed, 85 insertions(+)

diff --git 
a/server/container/guice/memory-guice/src/test/java/org/apache/james/DisabledSpoolerTest.java
 
b/server/container/guice/memory-guice/src/test/java/org/apache/james/DisabledSpoolerTest.java
new file mode 100644
index 0000000..fcd3d9b
--- /dev/null
+++ 
b/server/container/guice/memory-guice/src/test/java/org/apache/james/DisabledSpoolerTest.java
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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;
+
+import static org.apache.james.jmap.JMAPTestingConstants.ALICE;
+import static org.apache.james.jmap.JMAPTestingConstants.ALICE_PASSWORD;
+import static org.apache.james.jmap.JMAPTestingConstants.BOB;
+import static org.apache.james.jmap.JMAPTestingConstants.BOB_PASSWORD;
+import static org.apache.james.jmap.JMAPTestingConstants.DOMAIN;
+import static org.apache.james.jmap.JMAPTestingConstants.LOCALHOST_IP;
+import static 
org.apache.james.jmap.draft.JmapJamesServerContract.JAMES_SERVER_HOST;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailetcontainer.impl.JamesMailSpooler;
+import org.apache.james.mailrepository.api.MailRepositoryUrl;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.apache.james.modules.protocols.ImapGuiceProbe;
+import org.apache.james.modules.protocols.SmtpGuiceProbe;
+import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.SMTPMessageSender;
+import org.apache.james.utils.TestIMAPClient;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class DisabledSpoolerTest {
+    private static final String MESSAGE = "Subject: test\r\n" +
+        "\r\n" +
+        "testmail";
+
+    @RegisterExtension
+    static JamesServerExtension jamesServerExtension = new 
JamesServerBuilder<>(JamesServerBuilder.defaultConfigurationProvider())
+        .server(configuration -> 
MemoryJamesServerMain.createServer(configuration)
+            .overrideWith(new TestJMAPServerModule())
+            .overrideWith(binder -> 
binder.bind(JamesMailSpooler.Configuration.class)
+                .toInstance(new JamesMailSpooler.Configuration(0, 
MailRepositoryUrl.from("memory://repo1")))))
+        .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
+        .build();
+
+    @RegisterExtension
+    SMTPMessageSender smtpMessageSender = new SMTPMessageSender(DOMAIN);
+    @RegisterExtension
+    TestIMAPClient testIMAPClient = new TestIMAPClient();
+
+    @BeforeEach
+    void setUp(GuiceJamesServer guiceJamesServer) throws Exception {
+        DataProbeImpl dataProbe = 
guiceJamesServer.getProbe(DataProbeImpl.class);
+        dataProbe.fluent()
+            .addDomain(DOMAIN)
+            .addUser(ALICE.asString(), ALICE_PASSWORD)
+            .addUser(BOB.asString(), BOB_PASSWORD);
+    }
+
+    @Test
+    void emailsShouldNotBeDequeuedWhenZeroSpoolerThreads(GuiceJamesServer 
server) throws Exception {
+        smtpMessageSender.connect(LOCALHOST_IP, 
server.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .sendMessageWithHeaders(ALICE.asString(), BOB.asString(), MESSAGE);
+
+        Thread.sleep(5000);
+
+        long messageCount = testIMAPClient.connect(JAMES_SERVER_HOST, 
server.getProbe(ImapGuiceProbe.class).getImapPort())
+            .login(BOB, BOB_PASSWORD)
+            .getMessageCount(MailboxConstants.INBOX);
+        assertThat(messageCount).isEqualTo(0L);
+    }
+}
diff --git 
a/server/container/guice/memory-guice/src/test/resources/mailetcontainer.xml 
b/server/container/guice/memory-guice/src/test/resources/mailetcontainer.xml
index ea088d1..2c0ddc6 100644
--- a/server/container/guice/memory-guice/src/test/resources/mailetcontainer.xml
+++ b/server/container/guice/memory-guice/src/test/resources/mailetcontainer.xml
@@ -95,6 +95,7 @@
             <mailet match="All" class="SpamAssassin">
                 <spamdHost>localhost</spamdHost>
                 <spamdPort>783</spamdPort>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="IsMarkedAsSpam" class="WithStorageDirective">
                 <targetFolderName>Spam</targetFolderName>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to