You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/06/19 11:03:54 UTC
[james-project] 06/06: JAMES-3208 Add SizeGreaterThan integration
test
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 7f08147d5f0e0af5d6fbe22460a5de4c75778a52
Author: RĂ©mi KOWALSKI <rk...@linagora.com>
AuthorDate: Tue Jun 9 17:40:12 2020 +0200
JAMES-3208 Add SizeGreaterThan integration test
---
.../mailets/SizeGreaterThanIntegrationTest.java | 113 +++++++++++++++++++++
1 file changed, 113 insertions(+)
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SizeGreaterThanIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SizeGreaterThanIntegrationTest.java
new file mode 100644
index 0000000..30715ef
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SizeGreaterThanIntegrationTest.java
@@ -0,0 +1,113 @@
+/****************************************************************
+ * 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.mailets.configuration.CommonProcessors.ERROR_REPOSITORY;
+import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
+import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
+import static org.apache.james.mailets.configuration.Constants.PASSWORD;
+import static org.apache.james.mailets.configuration.Constants.RECIPIENT;
+import static org.apache.james.mailets.configuration.Constants.awaitAtMostOneMinute;
+
+import org.apache.james.MemoryJamesServerMain;
+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.ImapGuiceProbe;
+import org.apache.james.modules.protocols.SmtpGuiceProbe;
+import org.apache.james.transport.mailets.ToRepository;
+import org.apache.james.transport.matchers.SizeGreaterThan;
+import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.MailRepositoryProbeImpl;
+import org.apache.james.utils.SMTPMessageSender;
+import org.apache.james.utils.TestIMAPClient;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class SizeGreaterThanIntegrationTest {
+ public static final String POSTMASTER = "postmaster@" + DEFAULT_DOMAIN;
+ public static final String SENDER = "sender@" + DEFAULT_DOMAIN;
+
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @Rule
+ public TestIMAPClient testIMAPClient = new TestIMAPClient();
+ @Rule
+ public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
+
+ private TemporaryJamesServer jamesServer;
+
+ @Before
+ public void setup() throws Exception {
+ jamesServer = TemporaryJamesServer.builder()
+ .withBase(MemoryJamesServerMain.SMTP_AND_IMAP_MODULE)
+ .withMailetContainer(
+ generateMailetContainerConfiguration())
+ .build(temporaryFolder.newFolder());
+
+ jamesServer.getProbe(DataProbeImpl.class)
+ .fluent()
+ .addDomain(DEFAULT_DOMAIN)
+ .addUser(RECIPIENT, PASSWORD)
+ .addUser(SENDER, PASSWORD);
+ }
+
+ @After
+ public void tearDown() {
+ jamesServer.shutdown();
+ }
+
+ @Test
+ public void mailShouldGoToErrorRepositoryWhenSizeExceeded() throws Exception {
+
+ messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+ .sendMessageWithHeaders(SENDER, RECIPIENT, "01234567\r\n".repeat(1025));
+
+ awaitAtMostOneMinute.until(() -> jamesServer.getProbe(MailRepositoryProbeImpl.class).getRepositoryMailCount(ERROR_REPOSITORY) == 1);
+ }
+
+ @Test
+ public void mailShouldBeDeliveredWhenSizeWithinLimit() throws Exception {
+ messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+ .sendMessageWithHeaders(SENDER, RECIPIENT, "01234567\r\n".repeat(1000));
+
+ testIMAPClient.connect(LOCALHOST_IP, jamesServer.getProbe(ImapGuiceProbe.class).getImapPort())
+ .login(RECIPIENT, PASSWORD)
+ .select(TestIMAPClient.INBOX)
+ .awaitMessage(awaitAtMostOneMinute);
+ }
+
+ private MailetContainer.Builder generateMailetContainerConfiguration() {
+ return TemporaryJamesServer.DEFAULT_MAILET_CONTAINER_CONFIGURATION
+ .postmaster(POSTMASTER)
+ .putProcessor(ProcessorConfiguration.transport()
+ .addMailet(MailetConfiguration.builder()
+ .matcher(SizeGreaterThan.class)
+ .matcherCondition("10k")
+ .mailet(ToRepository.class)
+ .addProperty("repositoryPath", ERROR_REPOSITORY.asString())
+ .addProperty("passThrough", "false"))
+ .addMailetsFrom(CommonProcessors.deliverOnlyTransport()));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org