You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/01/08 08:00:28 UTC
[09/47] james-project git commit: MAILBOX-359 Factorize tests for
MailboxId ser-deserialization
MAILBOX-359 Factorize tests for MailboxId 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/e64e8e1d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e64e8e1d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e64e8e1d
Branch: refs/heads/master
Commit: e64e8e1d24cc0473ce37771acda398d77504fa18
Parents: 21eff06
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 13:23:08 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700
----------------------------------------------------------------------
.../event/json/AddedSerializationTest.java | 71 +------
.../event/json/ExpungedSerializationTest.java | 71 +------
.../json/FlagsUpdatedSerializationTest.java | 75 +-------
...MailboxACLUpdatedEventSerializationTest.java | 183 +++++++------------
.../json/MailboxAddedSerializationTest.java | 51 ------
.../json/MailboxDeletionSerializationTest.java | 53 +-----
.../json/MailboxRenamedSerializationTest.java | 33 +---
.../james/event/json/dtos/MailboxIdTest.java | 71 +++++++
8 files changed, 158 insertions(+), 450 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/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 a299389..3af5c28 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
@@ -568,78 +568,16 @@ class AddedSerializationTest {
.isInstanceOf(NoSuchElementException.class);
}
- @Nested
- class DeserializationErrorOnMailboxId {
- @Test
- void addedShouldThrowWhenMissingMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"Added\": {" +
- " \"path\": {" +
- " \"namespace\": \"#private\"," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"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 addedShouldThrowWhenNullMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"Added\": {" +
- " \"path\": {" +
- " \"namespace\": \"#private\"," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"mailboxId\": null," +
- " \"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 addedShouldThrowWhenMailboxIdIsANumber() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void addedShouldThrowWhenMissingMailboxId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"Added\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
" \"user\": \"user\"," +
" \"name\": \"mailboxName\"" +
" }," +
- " \"mailboxId\": 18," +
" \"added\": {" +
" \"123456\": {" +
" \"uid\": 123456," +
@@ -657,7 +595,6 @@ class AddedSerializationTest {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
- }
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/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 3d60dab..2aee596 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
@@ -567,78 +567,16 @@ class ExpungedSerializationTest {
.isInstanceOf(NoSuchElementException.class);
}
- @Nested
- class DeserializationErrorOnMailboxId {
- @Test
- void expungedShouldThrowWhenMissingMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"Expunged\": {" +
- " \"path\": {" +
- " \"namespace\": \"#private\"," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"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 expungedShouldThrowWhenNullMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"Expunged\": {" +
- " \"path\": {" +
- " \"namespace\": \"#private\"," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"mailboxId\": null," +
- " \"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 expungedShouldThrowWhenMailboxIdIsANumber() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void expungedShouldThrowWhenMissingMailboxId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"Expunged\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
" \"user\": \"user\"," +
" \"name\": \"mailboxName\"" +
" }," +
- " \"mailboxId\": 18," +
" \"expunged\": {" +
" \"123456\": {" +
" \"uid\": 123456," +
@@ -656,7 +594,6 @@ class ExpungedSerializationTest {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
- }
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
index 091a259..abef4bd 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/FlagsUpdatedSerializationTest.java
@@ -495,82 +495,16 @@ class FlagsUpdatedSerializationTest {
.isInstanceOf(NoSuchElementException.class);
}
- @Nested
- class DeserializationErrorOnMailboxId {
- @Test
- void flagsUpdatedShouldThrowWhenMissingMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"FlagsUpdated\": {" +
- " \"path\": {" +
- " \"namespace\": \"#private\"," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"sessionId\": 42," +
- " \"updatedFlags\": [" +
- " {" +
- " \"uid\": 123456," +
- " \"modSeq\": 35," +
- " \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
- " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
- " }," +
- " {" +
- " \"uid\": 654321," +
- " \"modSeq\": 36," +
- " \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
- " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
- " }" +
- " ]," +
- " \"user\": \"user\"" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void flagsUpdatedShouldThrowWhenNullMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"FlagsUpdated\": {" +
- " \"path\": {" +
- " \"namespace\": \"#private\"," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"mailboxId\": null," +
- " \"sessionId\": 42," +
- " \"updatedFlags\": [" +
- " {" +
- " \"uid\": 123456," +
- " \"modSeq\": 35," +
- " \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
- " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
- " }," +
- " {" +
- " \"uid\": 654321," +
- " \"modSeq\": 36," +
- " \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
- " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
- " }" +
- " ]," +
- " \"user\": \"user\"" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void flagsUpdatedShouldThrowWhenMailboxIdIsANumber() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void flagsUpdatedShouldThrowWhenMissingMailboxId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"FlagsUpdated\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
" \"user\": \"user\"," +
" \"name\": \"mailboxName\"" +
" }," +
- " \"mailboxId\": 18," +
" \"sessionId\": 42," +
" \"updatedFlags\": [" +
" {" +
@@ -590,7 +524,6 @@ class FlagsUpdatedSerializationTest {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
- }
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
index 45f7605..0855c64 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
@@ -309,13 +309,10 @@ class MailboxACLUpdatedEventSerializationTest {
.isInstanceOf(NoSuchElementException.class);
}
- @Nested
- class DeserializationErrorOnACLDiff {
-
- @Test
- void mailboxACLUpdatedShouldThrowWhenMissingACLDiff() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMissingACLDiff() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"MailboxACLUpdated\":{" +
" \"mailboxPath\":{" +
" \"namespace\":\"#private\"," +
@@ -326,8 +323,7 @@ class MailboxACLUpdatedEventSerializationTest {
" \"user\":\"user\"" +
" }" +
"}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
+ .isInstanceOf(NoSuchElementException.class);
}
@Nested
@@ -728,55 +724,11 @@ class MailboxACLUpdatedEventSerializationTest {
}
}
}
- }
-
- @Nested
- class DeserializationErrorOnMailboxId {
- @Test
- void mailboxACLUpdatedShouldThrowWhenMissingMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"MailboxACLUpdated\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"bob\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"aclDiff\":{" +
- " \"oldACL\":{}," +
- " \"newACL\":{\"$any\":\"ar\"}}," +
- " \"sessionId\":6," +
- " \"user\":\"user\"" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void mailboxACLUpdatedShouldThrowWhenNullMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"MailboxACLUpdated\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"bob\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"aclDiff\":{" +
- " \"oldACL\":{}," +
- " \"newACL\":{\"$any\":\"ar\"}}," +
- " \"mailboxId\":null," +
- " \"sessionId\":6," +
- " \"user\":\"user\"" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
- @Test
- void mailboxACLUpdatedShouldThrowWhenMailboxIdIsANumber() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMissingMailboxId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"MailboxACLUpdated\":{" +
" \"mailboxPath\":{" +
" \"namespace\":\"#private\"," +
@@ -786,13 +738,11 @@ class MailboxACLUpdatedEventSerializationTest {
" \"aclDiff\":{" +
" \"oldACL\":{}," +
" \"newACL\":{\"$any\":\"ar\"}}," +
- " \"mailboxId\":123," +
" \"sessionId\":6," +
" \"user\":\"user\"" +
" }" +
"}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
+ .isInstanceOf(NoSuchElementException.class);
}
@Nested
@@ -804,20 +754,20 @@ class MailboxACLUpdatedEventSerializationTest {
void mailboxACLUpdatedShouldThrowWhenNameSpaceIsNotAString() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
- " \"MailboxACLUpdated\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":230192.06," +
- " \"user\":\"bob\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"aclDiff\":{" +
- " \"oldACL\":{}," +
- " \"newACL\":{\"$any\":\"ar\"}}," +
- " \"mailboxId\":\"123\"," +
- " \"sessionId\":6," +
- " \"user\":\"user\"" +
- " }" +
- "}").get())
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":230192.06," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"123\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
.isInstanceOf(NoSuchElementException.class);
}
}
@@ -828,20 +778,20 @@ class MailboxACLUpdatedEventSerializationTest {
void mailboxACLUpdatedShouldThrowWhenUserIsNotAString() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
- " \"MailboxACLUpdated\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":230192.06," +
- " \"user\":180806," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"aclDiff\":{" +
- " \"oldACL\":{}," +
- " \"newACL\":{\"$any\":\"ar\"}}," +
- " \"mailboxId\":\"123\"," +
- " \"sessionId\":6," +
- " \"user\":\"user\"" +
- " }" +
- "}").get())
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":230192.06," +
+ " \"user\":180806," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"123\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
.isInstanceOf(NoSuchElementException.class);
}
}
@@ -853,20 +803,20 @@ class MailboxACLUpdatedEventSerializationTest {
void mailboxACLUpdatedShouldThrowWhenNullMailboxName() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
- " \"MailboxACLUpdated\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":230192.06," +
- " \"user\":180806," +
- " \"name\":null" +
- " }," +
- " \"aclDiff\":{" +
- " \"oldACL\":{}," +
- " \"newACL\":{\"$any\":\"ar\"}}," +
- " \"mailboxId\":\"123\"," +
- " \"sessionId\":6," +
- " \"user\":\"user\"" +
- " }" +
- "}").get())
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":230192.06," +
+ " \"user\":180806," +
+ " \"name\":null" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"123\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
.isInstanceOf(NoSuchElementException.class);
}
@@ -874,23 +824,24 @@ class MailboxACLUpdatedEventSerializationTest {
void mailboxACLUpdatedShouldThrowWhenMailboxNameIdIsANumber() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
- " \"MailboxACLUpdated\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":230192.06," +
- " \"user\":\"bob\"," +
- " \"name\":160205" +
- " }," +
- " \"aclDiff\":{" +
- " \"oldACL\":{}," +
- " \"newACL\":{\"$any\":\"ar\"}}," +
- " \"mailboxId\":\"123\"," +
- " \"sessionId\":6," +
- " \"user\":\"user\"" +
- " }" +
- "}").get())
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":230192.06," +
+ " \"user\":\"bob\"," +
+ " \"name\":160205" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"123\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
.isInstanceOf(NoSuchElementException.class);
}
}
}
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
index c491c9f..4ee0db7 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxAddedSerializationTest.java
@@ -275,56 +275,5 @@ class MailboxAddedSerializationTest {
"}").get())
.isInstanceOf(NoSuchElementException.class);
}
-
- @Test
- void fromJsonShouldRejectLongMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
- " \"MailboxAdded\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"bob\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"mailboxId\":18," +
- " \"user\":\"user\"," +
- " \"sessionId\":18" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void fromJsonShouldRejectNullMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
- " \"MailboxAdded\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"bob\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"mailboxId\":null," +
- " \"user\":\"user\"," +
- " \"sessionId\":18" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void fromJsonShouldRejectInvalidMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
- " \"MailboxAdded\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"bob\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"mailboxId\":\"invalid\"," +
- " \"user\":\"user\"," +
- " \"sessionId\":18" +
- " }" +
- "}").get())
- .isInstanceOf(NumberFormatException.class);
- }
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
index e0ae086..fc7a708 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxDeletionSerializationTest.java
@@ -470,12 +470,10 @@ class MailboxDeletionSerializationTest {
}
}
- @Nested
- class DeserializationErrorOnMailboxId {
- @Test
- void mailboxAddedShouldThrowWhenMissingMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void mailboxAddedShouldThrowWhenMissingMailboxId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"MailboxDeletion\":{" +
" \"sessionId\":3652," +
" \"user\":\"user\"," +
@@ -490,49 +488,6 @@ class MailboxDeletionSerializationTest {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void mailboxAddedShouldThrowWhenNullMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"MailboxDeletion\":{" +
- " \"sessionId\":3652," +
- " \"user\":\"user\"," +
- " \"path\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"user\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"quotaRoot\":\"user@domain\"," +
- " \"deletedMessageCount\":60," +
- " \"totalDeletedSize\":100," +
- " \"mailboxId\":null" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void mailboxAddedShouldThrowWhenMailboxIdIsANumber() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"MailboxDeletion\":{" +
- " \"sessionId\":3652," +
- " \"user\":\"user\"," +
- " \"path\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"user\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"quotaRoot\":\"user@domain\"," +
- " \"deletedMessageCount\":60," +
- " \"totalDeletedSize\":100," +
- " \"mailboxId\":789" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
index b19b20c..7ef472d 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxRenamedSerializationTest.java
@@ -329,12 +329,10 @@ class MailboxRenamedSerializationTest {
.isInstanceOf(NoSuchElementException.class);
}
- @Nested
- class DeserializationErrorOnMailBoxId {
- @Test
- void mailboxRenamedDeSerializeShouldThrowWhenNumberMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void mailboxRenamedDeSerializeShouldThrowWhenMissingMailboxId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"MailboxRenamed\":{" +
" \"sessionId\":123456789," +
" \"user\":\"user\"," +
@@ -352,29 +350,6 @@ class MailboxRenamedSerializationTest {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void mailboxRenamedDeSerializeShouldThrowWhenNullMailboxId() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"MailboxRenamed\":{" +
- " \"sessionId\":123456789," +
- " \"user\":\"user\"," +
- " \"path\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"user\"," +
- " \"name\":\"oldMailboxName\"" +
- " }," +
- " \"newPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"user\"," +
- " \"name\":\"newMailboxName\"" +
- " }" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/e64e8e1d/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.java
new file mode 100644
index 0000000..d54505c
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxIdTest.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 MailboxIdTest {
+ private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+ @Test
+ void mailboxIdShouldBeWellSerialized() {
+ assertThat(JSON_SERIALIZE.mailboxIdWrites().writes(TestId.of(18)))
+ .isEqualTo(new JsString("18"));
+ }
+
+ @Test
+ void mailboxIdShouldBeWellDeSerialized() {
+ assertThat(JSON_SERIALIZE.mailboxIdReads().reads(new JsString("18")))
+ .isEqualTo(new JsSuccess<>(TestId.of(18), new JsPath(List.empty())));
+ }
+
+ @Test
+ void mailboxIdDeserializationShouldReturnErrorWhenNumber() {
+ assertThat(JSON_SERIALIZE.mailboxIdReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+ .isInstanceOf(JsError.class);
+ }
+
+ @Test
+ void mailboxIdDeserializationShouldReturnErrorWhenNull() {
+ assertThat(JSON_SERIALIZE.mailboxIdReads().reads(JsNull$.MODULE$))
+ .isInstanceOf(JsError.class);
+ }
+
+ @Test
+ void mailboxIdDeserializationShouldThrowWhenInvalid() {
+ assertThatThrownBy(() -> JSON_SERIALIZE.mailboxIdReads().reads(new JsString("invalid")))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org