JAMES-2110 IT for getMessageList which supports filter by hasKeyword and notKeyword
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/eaedcd21 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/eaedcd21 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/eaedcd21 Branch: refs/heads/master Commit: eaedcd2182fbc39578f81eaf4a1ab07983ec6e06 Parents: 41e3d15 Author: quynhn <[email protected]> Authored: Tue Aug 15 16:49:13 2017 +0700 Committer: Raphael Ouazana <[email protected]> Committed: Thu Aug 24 15:47:28 2017 +0200 ---------------------------------------------------------------------- .../integration/GetMessageListMethodTest.java | 286 +++++++++++++++++-- 1 file changed, 268 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/eaedcd21/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java index 06bf60b..38ef074 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java @@ -29,15 +29,12 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; - import java.io.ByteArrayInputStream; import java.time.LocalDate; import java.time.ZoneId; import java.util.Date; - import javax.mail.Flags; -import org.apache.http.client.utils.URIBuilder; import org.apache.james.GuiceJamesServer; import org.apache.james.jmap.HttpJmapAuthentication; import org.apache.james.jmap.api.access.AccessToken; @@ -53,16 +50,19 @@ import org.apache.james.probe.DataProbe; import org.apache.james.util.date.ImapDateTimeFormatter; import org.apache.james.utils.DataProbeImpl; import org.apache.james.utils.JmapGuiceProbe; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.apache.http.client.utils.URIBuilder; import com.google.common.base.Charsets; import com.jayway.restassured.RestAssured; import com.jayway.restassured.builder.RequestSpecBuilder; import com.jayway.restassured.http.ContentType; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + public abstract class GetMessageListMethodTest { + private final static String FORWARDED = "$Forwarded"; private static final String NAME = "[0][0]"; private static final String ARGUMENTS = "[0][1]"; private static final ZoneId ZONE_ID = ZoneId.of("Europe/Paris"); @@ -140,7 +140,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListSetFlaggedFilterShouldWork() throws Exception { + public void getMessageListSetFlaggedFilterShouldResultFlaggedMessages() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -164,7 +164,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListUnsetFlaggedFilterShouldWork() throws Exception { + public void getMessageListUnsetFlaggedFilterShouldReturnNotFlaggedMessages() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -188,7 +188,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListReadFilterShouldWork() throws Exception { + public void getMessageListReadFilterShouldReturnOnlyReadMessages() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotRead = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -212,7 +212,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListUnreadFilterShouldWork() throws Exception { + public void getMessageListUnreadFilterShouldReturnOnlyUnreadMessages() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotRead = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -236,7 +236,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListSetDraftFilterShouldWork() throws Exception { + public void getMessageListSetDraftFilterShouldReturnOnlyDraftMessages() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotDraft = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -260,7 +260,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListUnsetDraftFilterShouldWork() throws Exception { + public void getMessageListUnsetDraftFilterShouldReturnOnlyNonDraftMessages() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotDraft = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -284,7 +284,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListSetAnsweredFilterShouldWork() throws Exception { + public void getMessageListSetAnsweredFilterShouldReturnOnlyAnsweredMessages() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotAnswered = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -308,7 +308,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListUnsetAnsweredFilterShouldWork() throws Exception { + public void getMessageListUnsetAnsweredFilterShouldReturnOnlyNotAnsweredMessages() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotAnswered = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -332,7 +332,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListANDOperatorShouldWork() throws Exception { + public void getMessageListANDOperatorShouldReturnMessagesWhichMatchAllConditions() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -362,7 +362,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListOROperatorShouldWork() throws Exception { + public void getMessageListOROperatorShouldReturnMessagesWhichMatchOneOfAllConditions() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -392,7 +392,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListNOTOperatorShouldWork() throws Exception { + public void getMessageListNOTOperatorShouldReturnMessagesWhichNotMatchAnyCondition() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -422,7 +422,7 @@ public abstract class GetMessageListMethodTest { } @Test - public void getMessageListNestedOperatorsShouldWork() throws Exception { + public void getMessageListNestedOperatorsShouldReturnMessagesWhichMatchConditions() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), @@ -1332,6 +1332,256 @@ public abstract class GetMessageListMethodTest { ; } + @Test + public void getMessageListHasKeywordFilterShouldReturnMessagesWithKeywords() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + + ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + ComposedMessageId messageFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags(Flags.Flag.FLAGGED)); + + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"hasKeyword\":\"$Flagged\"}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", allOf( + containsInAnyOrder(messageFlagged.getMessageId().serialize()), + not(containsInAnyOrder(messageNotFlagged.getMessageId().serialize())))); + } + + @Test + public void getMessageListHasKeywordFilterShouldReturnMessagesWithUserKeywords() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + + Flags flags = FlagsBuilder.builder() + .add(Flags.Flag.FLAGGED) + .add(FORWARDED) + .build(); + + ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + ComposedMessageId messageFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, flags); + + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"operator\":\"AND\",\"conditions\":[{\"hasKeyword\":\"$Flagged\"},{\"hasKeyword\":\"$Forwarded\"}]}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", allOf( + containsInAnyOrder(messageFlagged.getMessageId().serialize()), + not(containsInAnyOrder(messageNotFlagged.getMessageId().serialize())))); + } + + @Test + public void getMessageListNotKeywordFilterShouldReturnMessagesWithoutKeywords() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + + ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + ComposedMessageId messageFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags(Flags.Flag.FLAGGED)); + + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"notKeyword\":\"$Flagged\"}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", allOf( + containsInAnyOrder(messageNotFlagged.getMessageId().serialize()), + not(containsInAnyOrder(messageFlagged.getMessageId().serialize())))); + } + + @Test + public void getMessageListNotKeywordFilterShouldReturnMessagesWithoutUserKeywords() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + + Flags flags = FlagsBuilder.builder() + .add(Flags.Flag.FLAGGED) + .add(FORWARDED) + .build(); + + ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + ComposedMessageId messageFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, flags); + + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"operator\":\"AND\",\"conditions\":[{\"notKeyword\":\"$Flagged\"},{\"notKeyword\":\"$Forwarded\"}]}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", allOf( + containsInAnyOrder(messageNotFlagged.getMessageId().serialize()), + not(containsInAnyOrder(messageFlagged.getMessageId().serialize())))); + } + + @Test + public void getMessageListNotKeywordFilterShouldReturnMessagesWithoutKeywordsWhenMultipleNotKeywordAndFilterOperator() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + + Flags flags = FlagsBuilder.builder() + .add(FORWARDED) + .add(Flags.Flag.DRAFT) + .build(); + + ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags(Flags.Flag.FLAGGED)); + ComposedMessageId messageFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, flags); + + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"operator\":\"OR\",\"conditions\":[{\"notKeyword\":\"$Flagged\"},{\"notKeyword\":\"$Forwarded\"}]}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", allOf( + containsInAnyOrder(messageNotFlagged.getMessageId().serialize(), messageFlagged.getMessageId().serialize()))); + } + + @Test + public void getMessageListHasKeywordAndNotKeywordFilterShouldReturnMessagesWithAndWithoutKeywords() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + + ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + ComposedMessageId messageFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags(Flags.Flag.FLAGGED)); + + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"hasKeyword\":\"$Flagged\", \"notKeyword\":\"$Draft\"}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", allOf( + containsInAnyOrder(messageFlagged.getMessageId().serialize()), + not(containsInAnyOrder(messageNotFlagged.getMessageId().serialize())))); + } + + @Test + public void getMessageListHasKeywordShouldIgnoreDeleted() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + + ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + ComposedMessageId messageFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags(Flags.Flag.DELETED)); + + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"hasKeyword\":\"$Deleted\"}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", allOf( + containsInAnyOrder(messageFlagged.getMessageId().serialize(), messageNotFlagged.getMessageId().serialize()))); + } + + @Test + public void getMessageListHasKeywordShouldIgnoreRecent() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + + ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + ComposedMessageId messageFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags(Flags.Flag.RECENT)); + + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"hasKeyword\":\"$Recent\"}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", allOf( + containsInAnyOrder(messageFlagged.getMessageId().serialize(), messageNotFlagged.getMessageId().serialize()))); + } + + @Test + public void getMessageListNotKeywordShouldIgnoreDeleted() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + + ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + ComposedMessageId messageFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags(Flags.Flag.DELETED)); + + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"notKeyword\":\"$Deleted\"}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", allOf( + containsInAnyOrder(messageFlagged.getMessageId().serialize(), messageNotFlagged.getMessageId().serialize()))); + } + + @Test + public void getMessageListNotKeywordShouldIgnoreRecent() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + + ComposedMessageId messageNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + ComposedMessageId messageFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags(Flags.Flag.RECENT)); + + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"notKeyword\":\"$Recent\"}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", allOf( + containsInAnyOrder(messageFlagged.getMessageId().serialize(), messageNotFlagged.getMessageId().serialize()))); + } + private Date convertToDate(LocalDate localDate) { return Date.from(localDate.atStartOfDay(ZONE_ID).toInstant()); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
