JAMES-2218 Migrate Draft update/destroy tests to use cucumber + JMAP created draft message
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/45e7f3a4 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/45e7f3a4 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/45e7f3a4 Branch: refs/heads/master Commit: 45e7f3a4ff116a2f9b555e611f5696198aad9afd Parents: 29510c2 Author: benwa <btell...@linagora.com> Authored: Wed Nov 15 14:58:37 2017 +0700 Committer: Antoine Duprat <adup...@linagora.com> Committed: Thu Nov 16 12:28:58 2017 +0100 ---------------------------------------------------------------------- .../integration/SetMessagesMethodTest.java | 24 ----------- .../cucumber/GetMessagesMethodStepdefs.java | 11 +++-- .../cucumber/SetMessagesMethodStepdefs.java | 45 ++++++++++++++++++++ .../test/resources/cucumber/SetMessages.feature | 24 ++++++++++- 4 files changed, 76 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/45e7f3a4/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 ad99100..951d369 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 @@ -564,30 +564,6 @@ public abstract class SetMessagesMethodTest { } @Test - public void setMessagesShouldReturnAnErrorWhenKeywordsWithAddingDraftArePassed() throws MailboxException { - mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); - - ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, USER_MAILBOX, - new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.ANSWERED)); - await(); - - String messageId = message.getMessageId().serialize(); - - given() - .header("Authorization", accessToken.serialize()) - .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"keywords\": {\"$Draft\": true} } } }, \"#0\"]]", messageId)) - .when() - .post("/jmap") - .then() - .log().ifValidationFails() - .body(NOT_UPDATED, hasKey(messageId)) - .body(NOT_UPDATED + "[\""+messageId+"\"].type", equalTo("invalidProperties")) - .body(NOT_UPDATED + "[\""+messageId+"\"].properties[0]", equalTo("keywords")) - .body(NOT_UPDATED + "[\""+messageId+"\"].description", equalTo("keywords: Cannot add or remove draft flag")) - .body(ARGUMENTS + ".updated", hasSize(0)); - } - - @Test public void setMessagesShouldReturnAnErrorWhenKeywordsWithDeletedArePassed() throws MailboxException { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); http://git-wip-us.apache.org/repos/asf/james-project/blob/45e7f3a4/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java index f594b30..96df760 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java @@ -94,6 +94,10 @@ public class GetMessagesMethodStepdefs { return messageIdsByName.get(name); } + public MessageId addMessageId(String name, MessageId messageId) { + return messageIdsByName.put(name, messageId); + } + @Given("^the user has a message \"([^\"]*)\" in \"([^\"]*)\" and \"([^\"]*)\" mailboxes with subject \"([^\"]*)\", content \"([^\"]*)\"$") public void appendMessageInTwoMailboxes(String messageName, String mailbox1, String mailbox2, String subject, String content) throws Exception { MessageId id = appendMessage(mailbox1, ContentType.noContentType(), subject, content, NO_HEADERS); @@ -438,7 +442,7 @@ public class GetMessagesMethodStepdefs { askMessages(requestedMessageIds); } - @When("^\"(.*?)\" ask for messages \"(.*?)\"$") + @When("^\"(.*?)\" ask for (?:messages|message) \"(.*?)\"$") public void postWithAListOfIds(String user, List<String> ids) throws Throwable { userStepdefs.execWithUser(user, () -> postWithAListOfIds(ids)); } @@ -526,8 +530,9 @@ public class GetMessagesMethodStepdefs { } @Then("^the notFound list should contain \"([^\"]*)\"$") - public void assertNotFoundListContains(String ids) throws Exception { - assertThat(httpClient.jsonPath.<List<String>>read(ARGUMENTS + ".notFound")).contains(ids); + public void assertNotFoundListContains(String id) throws Exception { + MessageId messageId = messageIdsByName.get(id); + assertThat(httpClient.jsonPath.<List<String>>read(ARGUMENTS + ".notFound")).contains(messageId.serialize()); } @Then("^the notFound list should contain the requested message id$") http://git-wip-us.apache.org/repos/asf/james-project/blob/45e7f3a4/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java index 045893f..fc9370f 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java @@ -28,10 +28,12 @@ import java.util.stream.Collectors; import javax.inject.Inject; import javax.mail.Flags; +import org.apache.james.jmap.DefaultMailboxes; import org.apache.james.jmap.model.Keywords; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MessageId; +import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.modules.MailboxProbeImpl; import com.google.common.collect.ImmutableList; @@ -176,6 +178,49 @@ public class SetMessagesMethodStepdefs { userStepdefs.execWithUser(username, () -> setFlags(keywords, message)); } + @When("^\"([^\"]*)\" destroys message \"([^\"]*)\"") + public void destroyMessage(String username, String message) throws Throwable { + MessageId messageId = getMessagesMethodStepdefs.getMessageId(message); + userStepdefs.execWithUser(username, () -> { + httpClient.post("[" + + " [" + + " \"setMessages\","+ + " {" + + " \"destroy\": [ \"" + messageId.serialize() + "\" ]" + + " }," + + " \"#0\"" + + " ]" + + "]"); + mainStepdefs.awaitMethod.run(); + }); + } + + + @Given("^\"([^\"]*)\" creates a draft message \"([^\"]*)\"") + public void createDraft(String username, String message) throws Throwable { + userStepdefs.execWithUser(username, () -> { + Mailbox mailbox = mainStepdefs.mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, + username, + DefaultMailboxes.DRAFTS); + httpClient.post("[" + + " [" + + " \"setMessages\","+ + " {" + + " \"create\": { \"" + message + "\" : {" + + " \"subject\": \"subject\"," + + " \"keywords\": {\"$Draft\": true}," + + " \"mailboxIds\": [\"" + mailbox.getMailboxId().serialize() + "\"]" + + " }}" + + " }," + + " \"#0\"" + + " ]" + + "]"); + mainStepdefs.awaitMethod.run(); + String messageId = httpClient.jsonPath.read("[0][1].created." + message + ".id"); + getMessagesMethodStepdefs.addMessageId(message, mainStepdefs.messageIdFactory.fromString(messageId)); + }); + } + @When("^the user sets flags \"([^\"]*)\" on message \"([^\"]*)\"") public void setFlags(List<String> keywords, String message) throws Throwable { MessageId messageId = getMessagesMethodStepdefs.getMessageId(message); http://git-wip-us.apache.org/repos/asf/james-project/blob/45e7f3a4/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature index 60abace..2294513 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature @@ -100,4 +100,26 @@ Feature: SetMessages method on shared folders Given "b...@domain.tld" shares his mailbox "shared" with "al...@domain.tld" with "latires" rights And "b...@domain.tld" sets flags "$Flagged" on message "mBob" When "al...@domain.tld" sets flags "" on message "mBob" - Then message "mBob" is not updated \ No newline at end of file + Then message "mBob" is not updated + +# Updating draft + + Scenario: A user can update the flags on a draft + Given "b...@domain.tld" has a mailbox "Drafts" + And "b...@domain.tld" creates a draft message "mDraft" + When "b...@domain.tld" sets flags "$Draft,$Seen" on message "mDraft" + Then "b...@domain.tld" should see message "mDraft" with keywords $Draft,$Seen + + Scenario: A user can not remove a draft flag on a draft messages + Given "b...@domain.tld" has a mailbox "Drafts" + And "b...@domain.tld" creates a draft message "mDraft" + When "b...@domain.tld" sets flags "$Seen" on message "mDraft" + Then message "mDraft" is not updated + And "b...@domain.tld" should see message "mDraft" with keywords $Draft + + Scenario: A user can destroy a draft + Given "b...@domain.tld" has a mailbox "Drafts" + And "b...@domain.tld" creates a draft message "mDraft" + When "b...@domain.tld" destroys message "mDraft" + Then "b...@domain.tld" ask for message "mDraft" + And the notFound list should contain "mDraft" \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org