Repository: james-project Updated Branches: refs/heads/master 2db93fb01 -> d125ba97a
JAMES-2457 Add JMAP test for large mail handling Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/efdd8508 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/efdd8508 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/efdd8508 Branch: refs/heads/master Commit: efdd850877543afd2c75ae8ca04d10ff2e3c618c Parents: 2db93fb Author: Gautier DI FOLCO <gdifo...@linagora.com> Authored: Fri Jul 6 15:28:13 2018 +0200 Committer: Antoine Duprat <adup...@linagora.com> Committed: Thu Aug 23 13:57:29 2018 +0200 ---------------------------------------------------------------------- .../integration/SetMessagesMethodTest.java | 71 ++++++++++++++++++++ 1 file changed, 71 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/efdd8508/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java index 6f100b2..deb4245 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java @@ -120,6 +120,7 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.io.ByteStreams; @@ -136,6 +137,7 @@ public abstract class SetMessagesMethodTest { private static final String PASSWORD = "password"; private static final MailboxPath USER_MAILBOX = MailboxPath.forUser(USERNAME, "mailbox"); private static final String NOT_UPDATED = ARGUMENTS + ".notUpdated"; + private static final int BIG_MESSAGE_SIZE = 20 * 1024 * 1024; private AccessToken bobAccessToken; @@ -1353,6 +1355,75 @@ public abstract class SetMessagesMethodTest { } @Test + public void setMessagesWithABigBodyShouldReturnCreatedMessageWhenSendingMessage() { + String messageCreationId = "creationId1337"; + String fromAddress = USERNAME; + String body = Strings.repeat("d", BIG_MESSAGE_SIZE); + { + String requestBody = "[" + + " [" + + " \"setMessages\"," + + " {" + + " \"create\": { \"" + messageCreationId + "\" : {" + + " \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," + + " \"to\": [{ \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}]," + + " \"subject\": \"Thank you for joining example.com!\"," + + " \"textBody\": \"" + body + "\"," + + " \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" + + " }}" + + " }," + + " \"#0\"" + + " ]" + + "]"; + + given() + .header("Authorization", accessToken.serialize()) + .body(requestBody) + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messagesSet")) + .body(ARGUMENTS + ".notCreated", aMapWithSize(0)) + .body(ARGUMENTS + ".created", aMapWithSize(1)) + .body(ARGUMENTS + ".created", hasEntry(equalTo(messageCreationId), hasEntry(equalTo("textBody"), equalTo(body)))); + } + + calmlyAwait + .pollDelay(Duration.FIVE_HUNDRED_MILLISECONDS) + .atMost(30, TimeUnit.SECONDS).until(() -> hasANewMailWithBody(accessToken, body)); + } + + private boolean hasANewMailWithBody(AccessToken recipientToken, String body) { + try { + String inboxId = getMailboxId(accessToken, Role.INBOX); + String receivedMessageId = + with() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + inboxId + "\"]}}, \"#0\"]]") + .post("/jmap") + .then() + .extract() + .path(ARGUMENTS + ".messageIds[0]"); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessages\", {\"ids\": [\"" + receivedMessageId + "\"]}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messages")) + .body(ARGUMENTS + ".list", hasSize(1)) + .body(ARGUMENTS + ".list[0].textBody", equalTo(body)); + return true; + + } catch (AssertionError e) { + return false; + } + } + + @Test public void setMessagesShouldNotAllowCopyWhenOverQuota() throws MailboxException { QuotaProbe quotaProbe = jmapServer.getProbe(QuotaProbesImpl.class); String inboxQuotaRoot = quotaProbe.getQuotaRoot("#private", USERNAME, DefaultMailboxes.INBOX); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org