Repository: james-project
Updated Branches:
  refs/heads/master c105847d0 -> 43d732497


JAMES-2347 Demonstrate that IsOverQuota matcher is working in mailet pipeline


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

Branch: refs/heads/master
Commit: 142438a52e7c80b1f248bcaf1842afdc88b7b316
Parents: c105847
Author: Antoine Duprat <adup...@linagora.com>
Authored: Mon Mar 12 16:03:29 2018 +0100
Committer: benwa <btell...@linagora.com>
Committed: Wed Mar 14 09:05:15 2018 +0700

----------------------------------------------------------------------
 .../mailets/IsOverQuotaMatcherTest.java         | 133 +++++++++++++++++++
 1 file changed, 133 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/142438a5/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/IsOverQuotaMatcherTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/IsOverQuotaMatcherTest.java
 
b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/IsOverQuotaMatcherTest.java
new file mode 100644
index 0000000..7e514f9
--- /dev/null
+++ 
b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/IsOverQuotaMatcherTest.java
@@ -0,0 +1,133 @@
+/****************************************************************
+ * 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 static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
+import static org.apache.james.mailets.configuration.Constants.IMAP_PORT;
+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.SMTP_PORT;
+import static 
org.apache.james.mailets.configuration.Constants.awaitAtMostOneMinute;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.MemoryJamesServerMain;
+import org.apache.james.mailbox.quota.QuotaSize;
+import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue;
+import org.apache.james.mailbox.store.probe.QuotaProbe;
+import org.apache.james.mailets.TemporaryJamesServer;
+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.QuotaProbesImpl;
+import org.apache.james.probe.DataProbe;
+import org.apache.james.transport.matchers.IsOverQuota;
+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;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class IsOverQuotaMatcherTest {
+
+    private static final String FROM = "fromuser@" + DEFAULT_DOMAIN;
+    private static final String RECIPIENT = "touser@" + DEFAULT_DOMAIN;
+    private static final String BOUNCE_SENDER = "bounce.sender@" + 
DEFAULT_DOMAIN;
+
+    private static final String OVER_QUOTA_MESSAGE = "The recipient is over 
quota";
+    private static final String RECIPIENT_QUOTA_ROOT = "#private&" + RECIPIENT;
+    private static final QuotaSize SMALL_SIZE = QuotaSize.size(1);
+    private static final QuotaSize LARGE_SIZE = QuotaSize.size(10000);
+
+    @Rule
+    public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    @Rule
+    public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+    @Rule
+    public SMTPMessageSender messageSender = new 
SMTPMessageSender(DEFAULT_DOMAIN);
+    
+    private TemporaryJamesServer jamesServer;
+
+    @Before
+    public void setup() throws Exception {
+        MailetContainer.Builder mailetContainer = 
TemporaryJamesServer.DEFAULT_MAILET_CONTAINER_CONFIGURATION
+                .putProcessor(ProcessorConfiguration.transport()
+                        .addMailet(MailetConfiguration.builder()
+                                .matcher(IsOverQuota.class)
+                                .mailet(Bounce.class)
+                                .addProperty("sender", BOUNCE_SENDER)
+                                .addProperty("message", OVER_QUOTA_MESSAGE)
+                                .addProperty("passThrough", "false"))
+                        .addMailetsFrom(CommonProcessors.transport())
+                        .build());
+
+        jamesServer = TemporaryJamesServer.builder()
+            .withBase(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
+            .withMailetContainer(mailetContainer)
+            .build(temporaryFolder);
+
+        DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+        dataProbe.addDomain(DEFAULT_DOMAIN);
+        dataProbe.addUser(FROM, PASSWORD);
+        dataProbe.addUser(RECIPIENT, PASSWORD);
+        dataProbe.addUser(BOUNCE_SENDER, PASSWORD);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        jamesServer.shutdown();
+    }
+
+    @Test
+    public void 
aBounceMessageShouldBeSentToTheSenderWhenRecipientAsReachedHisQuota() throws 
Exception {
+        QuotaProbe quotaProbes = jamesServer.getProbe(QuotaProbesImpl.class);
+        quotaProbes.setMaxStorage(RECIPIENT_QUOTA_ROOT, new 
SerializableQuotaValue<>(SMALL_SIZE));
+
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT)
+            .awaitSent(awaitAtMostOneMinute);
+
+        IMAPMessageReader messageReader = 
imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(FROM, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(awaitAtMostOneMinute);
+
+        String bounceMessage = messageReader.readFirstMessage();
+        assertThat(bounceMessage).contains(OVER_QUOTA_MESSAGE);
+    }
+
+    @Test
+    public void 
aBounceMessageShouldBeSentToTheRecipientWhenRecipientQuotaIsNotExceeded() 
throws Exception {
+        QuotaProbe quotaProbes = jamesServer.getProbe(QuotaProbesImpl.class);
+        quotaProbes.setMaxStorage(RECIPIENT_QUOTA_ROOT, new 
SerializableQuotaValue<>(LARGE_SIZE));
+
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessage(FROM, RECIPIENT)
+            .awaitSent(awaitAtMostOneMinute);
+
+        imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT)
+            .login(RECIPIENT, PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .awaitMessage(awaitAtMostOneMinute);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to