@Test public void setMessagesShouldMarkMessageAsForwardWhenIsForwardedPassed() 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(StandardCharsets.UTF_8)), new Date(), false, new Flags()); await(); String serializedMessageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isForwarded\" : true } } }, \"#0\"]]", serializedMessageId)) .when() .post("/jmap") .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId)); }
@Test public void setMessageWithUpdateShouldBeOKWhenKeywordsWithCustomFlagArePassed() 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(StandardCharsets.UTF_8)), new Date(), false, new Flags()); await(); String messageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"keywords\": {\"$Seen\": true, \"$Unknown\": true} } } }, \"#0\"]]", messageId)) .when() .post("/jmap") .then() .log().ifValidationFails() .statusCode(200) .spec(getSetMessagesUpdateOKResponseAssertions(messageId)); }
@Test public void setMessagesShouldMarkMessageAsAnsweredWhenIsAnsweredPassed() throws MailboxException { // Given mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, USER_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), new Date(), false, new Flags()); await(); String serializedMessageId = message.getMessageId().serialize(); // When given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isAnswered\" : true } } }, \"#0\"]]", serializedMessageId)) .when() .post("/jmap") // Then .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId)); }
@Test public void setMessagesShouldReturnUpdatedIdAndNoErrorWhenIsUnreadPassedToFalse() throws MailboxException { // Given mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, USER_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), new Date(), false, new Flags()); await(); String serializedMessageId = message.getMessageId().serialize(); // When given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : false } } }, \"#0\"]]", serializedMessageId)) .when() .post("/jmap") // Then .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId)); }
@Test public void setMessagesShouldReturnUpdatedIdAndNoErrorWhenIsUnreadPassed() throws MailboxException { // Given mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, USER_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.SEEN)); await(); String serializedMessageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : true } } }, \"#0\"]]", serializedMessageId)) // When .when() .post("/jmap") // Then .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId)); }
@Test public void setMessagesShouldReturnUpdatedIdAndNoErrorWhenIsFlaggedPassed() throws MailboxException { // Given mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, USER_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), new Date(), false, new Flags()); await(); String serializedMessageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isFlagged\" : true } } }, \"#0\"]]", serializedMessageId)) // When .when() .post("/jmap") // Then .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId)); }
@Test public void mailboxIdsShouldReturnUpdatedWhenNoChange() throws Exception { ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z"); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, MailboxPath.forUser(USERNAME, MailboxConstants.INBOX), new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags()); String messageToMoveId = message.getMessageId().serialize(); String mailboxId = message.getMailboxId().serialize(); String requestBody = "[" + " [" + " \"setMessages\"," + " {" + " \"update\": { \"" + messageToMoveId + "\" : {" + " \"mailboxIds\": [\"" + mailboxId + "\"]" + " }}" + " }," + " \"#0\"" + " ]" + "]"; given() .header("Authorization", accessToken.serialize()) .body(requestBody) .when() .post("/jmap") .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(messageToMoveId)); }
@Test public void updateShouldNotReturnErrorWithFlagsAndMailboxUpdate() throws Exception { String newMailboxName = "heartFolder"; String heartFolderId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, newMailboxName).serialize(); ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z"); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, MailboxPath.forUser(USERNAME, MailboxConstants.INBOX), new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags()); String messageToMoveId = message.getMessageId().serialize(); String requestBody = "[" + " [" + " \"setMessages\"," + " {" + " \"update\": { \"" + messageToMoveId + "\" : {" + " \"mailboxIds\": [\"" + heartFolderId + "\"]," + " \"isUnread\": true" + " }}" + " }," + " \"#0\"" + " ]" + "]"; given() .header("Authorization", accessToken.serialize()) .body(requestBody) .when() .post("/jmap") .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(messageToMoveId)); }
@Test public void setMessagesShouldNotChangeOriginDeletedFlag() 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(StandardCharsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.DELETED)); await(); String messageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"keywords\": {\"$Answered\": true, \"$Forwarded\": true} } } }, \"#0\"]]", messageId)) .when() .post("/jmap") .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(messageId)); List<MessageResult> messages = messageProbe.getMessages(message.getMessageId(), USERNAME); Flags expectedFlags = FlagsBuilder.builder() .add(Flag.ANSWERED, Flag.DELETED) .add(FORWARDED) .build(); assertThat(messages) .hasSize(1) .extracting(MessageResult::getFlags) .containsOnly(expectedFlags); }
@Test public void setMessagesShouldUpdateKeywordsWhenKeywordsArePassed() 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(StandardCharsets.UTF_8)), new Date(), false, new Flags()); await(); String serializedMessageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"keywords\": {\"$Seen\": true, \"$Flagged\": true} } } }, \"#0\"]]", serializedMessageId)) .when() .post("/jmap") .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId)); with() .header("Authorization", accessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [\"" + serializedMessageId + "\"]}, \"#0\"]]") .post("/jmap") .then() .log().ifValidationFails() .statusCode(200) .body(NAME, equalTo("messages")) .body(ARGUMENTS + ".list", hasSize(1)) .body(ARGUMENTS + ".list[0].keywords.$Seen", equalTo(true)) .body(ARGUMENTS + ".list[0].keywords.$Flagged", equalTo(true)); }
@Test public void setMessagesShouldAddForwardedFlagWhenKeywordsWithForwardedIsPassed() 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(StandardCharsets.UTF_8)), new Date(), false, new Flags()); await(); String serializedMessageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"keywords\": {\"$Seen\": true, \"$Forwarded\": true} } } }, \"#0\"]]", serializedMessageId)) .when() .post("/jmap") .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId)); with() .header("Authorization", accessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [\"" + serializedMessageId + "\"]}, \"#0\"]]") .post("/jmap") .then() .log().ifValidationFails() .statusCode(200) .body(NAME, equalTo("messages")) .body(ARGUMENTS + ".list", hasSize(1)) .body(ARGUMENTS + ".list[0].keywords.$Seen", equalTo(true)) .body(ARGUMENTS + ".list[0].keywords.$Forwarded", equalTo(true)); }
@Test public void setMessagesShouldReturnNewKeywordsWhenKeywordsArePassedToRemoveAndAddFlag() throws MailboxException { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); Flags currentFlags = FlagsBuilder.builder() .add(Flag.DRAFT, Flag.ANSWERED) .build(); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, USER_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), new Date(), false, currentFlags); await(); String messageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"keywords\": {\"$Answered\": true, \"$Flagged\": true} } } }, \"#0\"]]", messageId)) .when() .post("/jmap") .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(messageId)); with() .header("Authorization", accessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [\"" + messageId + "\"]}, \"#0\"]]") .post("/jmap") .then() .log().ifValidationFails() .statusCode(200) .body(NAME, equalTo("messages")) .body(ARGUMENTS + ".list", hasSize(1)) .body(ARGUMENTS + ".list[0].keywords.$Answered", equalTo(true)) .body(ARGUMENTS + ".list[0].keywords.$Flagged", equalTo(true)); }
@Test public void setMessagesShouldNotChangeOriginRecentFlag() throws MailboxException { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); Flags flags = FlagsBuilder.builder() .add(Flag.DELETED, Flag.RECENT) .build(); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, USER_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), new Date(), false, flags); await(); String messageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"keywords\": {\"$Answered\": true, \"$Forwarded\": true} } } }, \"#0\"]]", messageId)) .when() .post("/jmap") .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(messageId)); List<MessageResult> messages = messageProbe.getMessages(message.getMessageId(), USERNAME); Flags expectedFlags = FlagsBuilder.builder() .add(Flag.ANSWERED, Flag.DELETED, Flag.RECENT) .add(FORWARDED) .build(); assertThat(messages) .hasSize(1) .extracting(MessageResult::getFlags) .containsOnly(expectedFlags); }
@Test public void setMessagesShouldRemoveForwardedFlagWhenKeywordsWithoutForwardedIsPassed() throws MailboxException { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); Flags flags = FlagsBuilder.builder() .add(Flag.SEEN) .add(FORWARDED) .build(); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, USER_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), new Date(), false, flags); await(); String serializedMessageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"keywords\": {\"$Seen\": true} } } }, \"#0\"]]", serializedMessageId)) .when() .post("/jmap") .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId)); with() .header("Authorization", accessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [\"" + serializedMessageId + "\"]}, \"#0\"]]") .post("/jmap") .then() .log().ifValidationFails() .statusCode(200) .body(NAME, equalTo("messages")) .body(ARGUMENTS + ".list", hasSize(1)) .body(ARGUMENTS + ".list[0].keywords.$Seen", equalTo(true)); }
.then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(jmapMessageId));