MAILBOX-359 Factorize tests for MessageMetaData ser-deserialization
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c6aebcc7 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c6aebcc7 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c6aebcc7 Branch: refs/heads/master Commit: c6aebcc7dc82fdd6012cbae4e38d137a01bfddba Parents: ba9ff0d Author: Benoit Tellier <btell...@linagora.com> Authored: Mon Dec 24 15:17:44 2018 +0700 Committer: Benoit Tellier <btell...@linagora.com> Committed: Tue Jan 8 14:37:57 2019 +0700 ---------------------------------------------------------------------- .../event/json/AddedSerializationTest.java | 595 +----------------- .../event/json/ExpungedSerializationTest.java | 596 +------------------ .../james/event/json/dtos/MessageIdTest.java | 71 +++ .../event/json/dtos/MessageMetaDataTest.java | 348 +++++++++++ 4 files changed, 461 insertions(+), 1149 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/c6aebcc7/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java index 8246e77..327d5ba 100644 --- a/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/AddedSerializationTest.java @@ -139,112 +139,6 @@ class AddedSerializationTest { } @Nested - class WithInternalDate { - - @Test - void addedShouldDeserializeWhenInternalDateIsInGoodISOFormat() { - SortedMap<MessageUid, MessageMetaData> added = ImmutableSortedMap.of( - MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:51Z")), MESSAGE_ID)); - MailboxListener.Added eventRoundToMillis = new MailboxListener.Added(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, added); - - assertThat(EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51+00:00\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isEqualTo(eventRoundToMillis); - } - - @Test - void addedShouldDeserializeWhenInternalDateIsMissingMilliSeconds() { - SortedMap<MessageUid, MessageMetaData> added = ImmutableSortedMap.of( - MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:51Z")), MESSAGE_ID)); - MailboxListener.Added eventRoundToMillis = new MailboxListener.Added(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, added); - - assertThat(EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isEqualTo(eventRoundToMillis); - } - - @Test - void addedShouldDeserializeWhenInternalDateIsMissingSeconds() { - SortedMap<MessageUid, MessageMetaData> added = ImmutableSortedMap.of( - MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:00Z")), MESSAGE_ID)); - MailboxListener.Added eventRoundToMinute = new MailboxListener.Added(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, added); - - assertThat(EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isEqualTo(eventRoundToMinute); - } - } - - @Nested class DeserializationErrors { @Test void addedShouldThrowWhenMissingSessionId() { @@ -358,12 +252,10 @@ class AddedSerializationTest { .isInstanceOf(NoSuchElementException.class); } - @Nested - class DeserializationErrorOnAddedMap { - @Test - void addedShouldThrowWhenMapKeyIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + + @Test + void addedShouldThrowWhenMapKeyIsNull() { + assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( + "{" + " \"Added\": {" + " \"path\": {" + " \"namespace\": \"#private\"," + @@ -377,469 +269,24 @@ class AddedSerializationTest { " }" + "}").get()) .isInstanceOf(NoSuchElementException.class); - } - - @Test - void addedShouldThrowWhenMessageUidIsMissing() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": null" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Nested - class DeserializationErrorOnModSeq { - - @Test - void addedShouldThrowWhenModSeqIsAString() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": \"35\"," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void addedShouldThrowWhenModSeqIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": null" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": null," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - } - - @Nested - class DeserializationErrorOnSize { - - @Test - void addedShouldThrowWhenSizeIsAString() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": \"45\", " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void addedShouldThrowWhenSizeIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": null, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - } - - @Nested - class DeserializationErrorOnMessageId { - - @Test - void addedShouldThrowWhenMessageIdIsANumber() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": 42" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void addedShouldThrowWhenMessageIdIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": null" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - } - - @Nested - class DeserializationErrorOnInternalDate { - @Test - void addedShouldThrowWhenInternalDateIsNotInISOFormatBecauseOfMissingTWord() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14 12:52:36+07:00\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void addedShouldThrowWhenInternalDateContainsOnlyDate() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void addedShouldThrowWhenInternalDateIsMissingHourPart() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14TZ\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void addedShouldThrowWhenInternalDateIsMissingTimeZone() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void addedShouldThrowWhenInternalDateIsMissingHours() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void addedShouldThrowWhenInternalDateIsEmpty() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void addedShouldThrowWhenInternalDateIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": null," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - } + } - @Test - void addedShouldThrowWhenFlagsIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Added\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"added\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": null," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } + @Test + void addedShouldThrowWhenMissingAdded() { + assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( + "{" + + " \"Added\": {" + + " \"path\": {" + + " \"namespace\": \"#private\"," + + " \"user\": \"user\"," + + " \"name\": \"mailboxName\"" + + " }," + + " \"mailboxId\": \"18\"," + + " \"sessionId\": 42," + + " \"user\": \"user\"" + + " }" + + "}").get()) + .isInstanceOf(NoSuchElementException.class); } } } http://git-wip-us.apache.org/repos/asf/james-project/blob/c6aebcc7/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java index 2f1ca46..0e46b59 100644 --- a/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/ExpungedSerializationTest.java @@ -139,112 +139,6 @@ class ExpungedSerializationTest { } @Nested - class WithInternalDate { - - @Test - void expungedShouldDeserializeWhenInternalDateIsInGoodISOFormat() { - Map<MessageUid, MessageMetaData> Expunged = ImmutableMap.of( - MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:51Z")), MESSAGE_ID)); - MailboxListener.Expunged eventRoundToMillis = new MailboxListener.Expunged(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, Expunged); - - assertThat(EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51+00:00\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isEqualTo(eventRoundToMillis); - } - - @Test - void expungedShouldDeserializeWhenInternalDateIsMissingMilliSeconds() { - Map<MessageUid, MessageMetaData> Expunged = ImmutableMap.of( - MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:51Z")), MESSAGE_ID)); - MailboxListener.Expunged eventRoundToMillis = new MailboxListener.Expunged(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, Expunged); - - assertThat(EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isEqualTo(eventRoundToMillis); - } - - @Test - void expungedShouldDeserializeWhenInternalDateIsMissingSeconds() { - Map<MessageUid, MessageMetaData> Expunged = ImmutableMap.of( - MESSAGE_UID, new MessageMetaData(MESSAGE_UID, MOD_SEQ, FLAGS, SIZE, Date.from(Instant.parse("2018-12-14T09:41:00Z")), MESSAGE_ID)); - MailboxListener.Expunged eventRoundToMinute = new MailboxListener.Expunged(SESSION_ID, USER, MAILBOX_PATH, MAILBOX_ID, Expunged); - - assertThat(EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isEqualTo(eventRoundToMinute); - } - } - - @Nested class DeserializationErrors { @Test void expungedShouldThrowWhenMissingSessionId() { @@ -358,12 +252,10 @@ class ExpungedSerializationTest { .isInstanceOf(NoSuchElementException.class); } - @Nested - class DeserializationErrorOnExpungedMap { - @Test - void expungedShouldThrowWhenMapKeyIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + + @Test + void expungedShouldThrowWhenMapKeyIsNull() { + assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( + "{" + " \"Expunged\": {" + " \"path\": {" + " \"namespace\": \"#private\"," + @@ -377,470 +269,24 @@ class ExpungedSerializationTest { " }" + "}").get()) .isInstanceOf(NoSuchElementException.class); - } - - @Test - void expungedShouldThrowWhenMessageUidIsMissing() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": null" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Nested - class DeserializationErrorOnModSeq { - - @Test - void expungedShouldThrowWhenModSeqIsAString() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": \"35\"," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void expungedShouldThrowWhenModSeqIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": null" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": null," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - } - - - @Nested - class DeserializationErrorOnSize { - - @Test - void expungedShouldThrowWhenSizeIsAString() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": \"45\", " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void expungedShouldThrowWhenSizeIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": null, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - } - - @Nested - class DeserializationErrorOnMessageId { - - @Test - void expungedShouldThrowWhenMessageIdIsANumber() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": 42" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void expungedShouldThrowWhenMessageIdIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": null" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - } - - @Nested - class DeserializationErrorOnInternalDate { - @Test - void expungedShouldThrowWhenInternalDateIsNotInISOFormatBecauseOfMissingTWord() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14 12:52:36+07:00\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void expungedShouldThrowWhenInternalDateContainsOnlyDate() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void expungedShouldThrowWhenInternalDateIsMissingHourPart() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14TZ\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void expungedShouldThrowWhenInternalDateIsMissingTimeZone() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void expungedShouldThrowWhenInternalDateIsMissingHours() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void expungedShouldThrowWhenInternalDateIsEmpty() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": \"\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void expungedShouldThrowWhenInternalDateIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": {" + - " \"systemFlags\":[\"Answered\",\"Draft\"], " + - " \"userFlags\":[\"User Custom Flag\"]}," + - " \"size\": 45, " + - " \"internalDate\": null," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - } + } - @Test - void addedShouldThrowWhenFlagsIsNull() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"Expunged\": {" + - " \"path\": {" + - " \"namespace\": \"#private\"," + - " \"user\": \"user\"," + - " \"name\": \"mailboxName\"" + - " }," + - " \"mailboxId\": \"18\"," + - " \"expunged\": {" + - " \"123456\": {" + - " \"uid\": 123456," + - " \"modSeq\": 35," + - " \"flags\": null," + - " \"size\": 45, " + - " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + - " \"messageId\": \"42\"" + - " }" + - " }," + - " \"sessionId\": 42," + - " \"user\": \"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } + @Test + void expungedShouldThrowWhenMissingExpunged() { + assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( + "{" + + " \"Expunged\": {" + + " \"path\": {" + + " \"namespace\": \"#private\"," + + " \"user\": \"user\"," + + " \"name\": \"mailboxName\"" + + " }," + + " \"mailboxId\": \"18\"," + + " \"sessionId\": 42," + + " \"user\": \"user\"" + + " }" + + "}").get()) + .isInstanceOf(NoSuchElementException.class); } } } http://git-wip-us.apache.org/repos/asf/james-project/blob/c6aebcc7/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java new file mode 100644 index 0000000..21426fa --- /dev/null +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageIdTest.java @@ -0,0 +1,71 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.event.json.dtos; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.apache.james.event.json.JsonSerialize; +import org.apache.james.mailbox.model.TestId; +import org.apache.james.mailbox.model.TestMessageId; +import org.junit.jupiter.api.Test; + +import play.api.libs.json.JsError; +import play.api.libs.json.JsNull$; +import play.api.libs.json.JsNumber; +import play.api.libs.json.JsPath; +import play.api.libs.json.JsString; +import play.api.libs.json.JsSuccess; +import scala.collection.immutable.List; +import scala.math.BigDecimal; + +class MessageIdTest { + private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory()); + + @Test + void messageIdShouldBeWellSerialized() { + assertThat(JSON_SERIALIZE.messageIdWrites().writes(TestMessageId.of(18))) + .isEqualTo(new JsString("18")); + } + + @Test + void messageIdShouldBeWellDeSerialized() { + assertThat(JSON_SERIALIZE.messageIdReads().reads(new JsString("18"))) + .isEqualTo(new JsSuccess<>(TestMessageId.of(18), new JsPath(List.empty()))); + } + + @Test + void messageIdDeserializationShouldReturnErrorWhenNumber() { + assertThat(JSON_SERIALIZE.messageIdReads().reads(new JsNumber(BigDecimal.valueOf(18)))) + .isInstanceOf(JsError.class); + } + + @Test + void messageIdDeserializationShouldReturnErrorWhenNull() { + assertThat(JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$)) + .isInstanceOf(JsError.class); + } + + @Test + void messageIdDeserializationShouldThrowWhenInvalid() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageIdReads().reads(new JsString("invalid"))) + .isInstanceOf(IllegalArgumentException.class); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/c6aebcc7/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java new file mode 100644 index 0000000..b8169b5 --- /dev/null +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageMetaDataTest.java @@ -0,0 +1,348 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.event.json.dtos; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.time.Instant; +import java.util.NoSuchElementException; + +import org.apache.james.event.json.JsonSerialize; +import org.apache.james.mailbox.model.TestId; +import org.apache.james.mailbox.model.TestMessageId; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import play.api.libs.json.Json; + +class MessageMetaDataTest { + private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory()); + + @Nested + class StructureTest { + @Test + void deserializeShouldThrowWhenNoFlags() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"modSeq\": 35," + + " \"size\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deserializeShouldThrowWhenNoUid() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"modSeq\": 35," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"size\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deserializeShouldThrowWhenNoModSeq() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"size\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deserializeShouldThrowWhenNoSize() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"modSeq\": 35," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deserializeShouldThrowWhenNoInternalDate() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"modSeq\": 35," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"size\": 45, " + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deserializeShouldThrowWhenNoMessageId() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"modSeq\": 35," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"size\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51.541Z\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + } + + @Nested + class ModSeqTest { + @Test + void deserializeShouldThrowWhenNullModSeq() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"modSeq\": null," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"size\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deserializeShouldThrowWhenStringModSeq() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"modSeq\": \"42\"," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"size\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + } + + @Nested + class SizeTest { + @Test + void deserializeShouldThrowWhenNullSize() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": null," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deserializeShouldThrowWhenStringSize() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": \"42\"," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51.541Z\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + } + + @Nested + class DeserializationErrorOnInternalDate { + @Test + void deSerializeShouldThrowWhenInternalDateIsNotInISOFormatBecauseOfMissingTWord() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": 42," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": \"2018-12-14 12:52:36+07:00\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deSerializeShouldThrowWhenInternalDateContainsOnlyDate() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": 42," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": \"2018-12-14\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deSerializeShouldThrowWhenInternalDateIsMissingHourPart() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": 42," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": \"2018-12-14TZ\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deSerializeShouldThrowWhenInternalDateIsMissingTimeZone() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": 42," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51.541\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deSerializeShouldThrowWhenInternalDateIsMissingHours() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": 42," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": \"2018-12-14Z\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deSerializeShouldThrowWhenInternalDateIsEmpty() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": 42," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": \"\"," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deSerializeShouldThrowWhenInternalDateIsNull() { + assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": 42," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": null," + + " \"messageId\": \"42\"" + + "}")) + .get()) + .isInstanceOf(NoSuchElementException.class); + } + + @Test + void deSerializeShouldParseValidISOInstants() { + assertThat(JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": 42," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51+00:00\"," + + " \"messageId\": \"42\"" + + "}")) + .get() + .internalDate()) + .isEqualTo(Instant.parse("2018-12-14T09:41:51Z")); + } + + @Test + void deSerializeShouldParseWhenInternalDateIsMissingMilliSeconds() { + assertThat(JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + " \"uid\": 123456," + + " \"size\": 42," + + " \"flags\": {" + + " \"systemFlags\":[\"Answered\",\"Draft\"], " + + " \"userFlags\":[\"User Custom Flag\"]}," + + " \"modSeq\": 45, " + + " \"internalDate\": \"2018-12-14T09:41:51+00:00\"," + + " \"messageId\": \"42\"" + + "}")) + .get() + .internalDate()) + .isEqualTo(Instant.parse("2018-12-14T09:41:51Z")); + } + } +} \ 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