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/04/01 03:32:58 UTC
[james-project] 07/14: JAMES-3129 Sending mail via JMAP: Add test
for Outbox & Sent counters
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 b927b4776b57a5a981e2cac71c105ee1ddade193
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 27 15:34:46 2020 +0700
JAMES-3129 Sending mail via JMAP: Add test for Outbox & Sent counters
---
.../methods/integration/SetMessagesMethodTest.java | 93 ++++++++++++++++++++++
.../org/apache/james/jmap/JmapCommonRequests.java | 10 ++-
2 files changed, 102 insertions(+), 1 deletion(-)
diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/SetMessagesMethodTest.java
index b82aa58..c2e8ff3 100644
--- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/SetMessagesMethodTest.java
@@ -30,6 +30,7 @@ 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.DOMAIN_ALIAS;
+import static org.apache.james.jmap.JMAPTestingConstants.FIRST_MAILBOX;
import static org.apache.james.jmap.JMAPTestingConstants.LOCALHOST_IP;
import static org.apache.james.jmap.JMAPTestingConstants.NAME;
import static org.apache.james.jmap.JMAPTestingConstants.SECOND_ARGUMENTS;
@@ -39,6 +40,7 @@ import static org.apache.james.jmap.JmapCommonRequests.getDraftId;
import static org.apache.james.jmap.JmapCommonRequests.getInboxId;
import static org.apache.james.jmap.JmapCommonRequests.getMailboxId;
import static org.apache.james.jmap.JmapCommonRequests.getOutboxId;
+import static org.apache.james.jmap.JmapCommonRequests.getSentId;
import static org.apache.james.jmap.JmapCommonRequests.getSetMessagesUpdateOKResponseAssertions;
import static org.apache.james.jmap.JmapURIBuilder.baseUri;
import static org.assertj.core.api.Assertions.assertThat;
@@ -79,6 +81,7 @@ import org.apache.james.core.Username;
import org.apache.james.core.quota.QuotaSizeLimit;
import org.apache.james.jmap.AccessToken;
import org.apache.james.jmap.HttpJmapAuthentication;
+import org.apache.james.jmap.JmapCommonRequests;
import org.apache.james.jmap.MessageAppender;
import org.apache.james.jmap.draft.JmapGuiceProbe;
import org.apache.james.jmap.draft.MessageIdProbe;
@@ -1047,6 +1050,96 @@ public abstract class SetMessagesMethodTest {
;
}
+ @Category(BasicFeature.class)
+ @Test
+ public void sendingAMailShouldLeadToAppropriateMailboxCountersOnOutbox() {
+ String messageCreationId = "creationId1337";
+ String fromAddress = USERNAME.asString();
+ String requestBody = "[" +
+ " [" +
+ " \"setMessages\"," +
+ " {" +
+ " \"create\": { \"" + messageCreationId + "\" : {" +
+ " \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+ " \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+ " \"subject\": \"Thank you for joining example.com!\"," +
+ " \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+ " \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+ " }}" +
+ " }," +
+ " \"#0\"" +
+ " ]" +
+ "]";
+
+ with()
+ .header("Authorization", accessToken.asString())
+ .body(requestBody)
+ .post("/jmap");
+
+ calmlyAwait.until(
+ () -> JmapCommonRequests.isAnyMessageFoundInRecipientsMailbox(accessToken, getSentId(accessToken)));
+
+ given()
+ .header("Authorization", accessToken.asString())
+ .body("[[\"getMailboxes\", {" +
+ " \"ids\": [\"" + getOutboxId(accessToken) + "\"], " +
+ " \"properties\" : [\"unreadMessages\", \"totalMessages\"]}, " +
+ "\"#0\"]]")
+ .log().ifValidationFails()
+ .when()
+ .post("/jmap")
+ .then()
+ .statusCode(200)
+ .body(NAME, equalTo("mailboxes"))
+ .body(FIRST_MAILBOX + ".totalMessages", equalTo(0))
+ .body(FIRST_MAILBOX + ".unreadMessages", equalTo(0));
+ }
+
+ @Category(BasicFeature.class)
+ @Test
+ public void sendingAMailShouldLeadToAppropriateMailboxCountersOnSent() {
+ String messageCreationId = "creationId1337";
+ String fromAddress = USERNAME.asString();
+ String requestBody = "[" +
+ " [" +
+ " \"setMessages\"," +
+ " {" +
+ " \"create\": { \"" + messageCreationId + "\" : {" +
+ " \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+ " \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+ " \"subject\": \"Thank you for joining example.com!\"," +
+ " \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+ " \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+ " }}" +
+ " }," +
+ " \"#0\"" +
+ " ]" +
+ "]";
+
+ with()
+ .header("Authorization", accessToken.asString())
+ .body(requestBody)
+ .post("/jmap");
+
+ calmlyAwait.until(
+ () -> JmapCommonRequests.isAnyMessageFoundInRecipientsMailbox(accessToken, getSentId(accessToken)));
+
+ given()
+ .header("Authorization", accessToken.asString())
+ .body("[[\"getMailboxes\", {" +
+ " \"ids\": [\"" + getSentId(accessToken) + "\"], " +
+ " \"properties\" : [\"unreadMessages\", \"totalMessages\"]}, " +
+ "\"#0\"]]")
+ .log().ifValidationFails()
+ .when()
+ .post("/jmap")
+ .then()
+ .statusCode(200)
+ .body(NAME, equalTo("mailboxes"))
+ .body(FIRST_MAILBOX + ".totalMessages", equalTo(1))
+ .body(FIRST_MAILBOX + ".unreadMessages", equalTo(0));
+ }
+
@Test
public void setMessagesShouldReturnCreatedMessageWithEmptySubjectWhenSubjectIsNull() {
String messageCreationId = "creationId1337";
diff --git a/server/testing/src/main/java/org/apache/james/jmap/JmapCommonRequests.java b/server/testing/src/main/java/org/apache/james/jmap/JmapCommonRequests.java
index 3ed86ad..72138fe 100644
--- a/server/testing/src/main/java/org/apache/james/jmap/JmapCommonRequests.java
+++ b/server/testing/src/main/java/org/apache/james/jmap/JmapCommonRequests.java
@@ -48,6 +48,10 @@ public class JmapCommonRequests {
return getMailboxId(accessToken, Role.OUTBOX);
}
+ public static String getSentId(AccessToken accessToken) {
+ return getMailboxId(accessToken, Role.SENT);
+ }
+
public static String getDraftId(AccessToken accessToken) {
return getMailboxId(accessToken, Role.DRAFTS);
}
@@ -89,10 +93,14 @@ public class JmapCommonRequests {
}
public static boolean isAnyMessageFoundInRecipientsMailbox(AccessToken recipientToken, MailboxId mailboxId) {
+ return isAnyMessageFoundInRecipientsMailbox(recipientToken, mailboxId.serialize());
+ }
+
+ public static boolean isAnyMessageFoundInRecipientsMailbox(AccessToken recipientToken, String serialize) {
try {
with()
.header("Authorization", recipientToken.asString())
- .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + mailboxId.serialize() + "\"]}}, \"#0\"]]")
+ .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + serialize + "\"]}}, \"#0\"]]")
.when()
.post("/jmap")
.then()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org