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:24 UTC
[05/47] james-project git commit: MAILBOX-359 Factorize tests for
User ser-deserialization
MAILBOX-359 Factorize tests for User 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/21eff068
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/21eff068
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/21eff068
Branch: refs/heads/master
Commit: 21eff0689931e3c454d2dfbc91b82473ee80c440
Parents: 8ca8a33
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 13:11:31 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 | 54 +------
.../json/MailboxAddedSerializationTest.java | 34 ----
.../json/MailboxDeletionSerializationTest.java | 53 +-----
.../json/MailboxRenamedSerializationTest.java | 60 +------
.../json/MessageMoveEventSerializationTest.java | 84 ----------
...QuotaUsageUpdatedEventSerializationTest.java | 161 +++++--------------
.../james/event/json/dtos/SessionIdTest.java | 4 +-
.../apache/james/event/json/dtos/UserTest.java | 90 +++++++++++
11 files changed, 156 insertions(+), 601 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/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 82afcd2..a299389 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
@@ -539,12 +539,10 @@ class AddedSerializationTest {
.isInstanceOf(NoSuchElementException.class);
}
- @Nested
- class DeserializationErrorOnUser {
- @Test
- void addedShouldThrowWhenMissingUser() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void addedShouldThrowWhenMissingUser() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"Added\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
@@ -568,67 +566,6 @@ class AddedSerializationTest {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void addedShouldThrowWhenUserIsNotAString() {
- 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\": 596" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void addedShouldThrowWhenUserIsNotWellFormatted() {
- 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@user@anotherUser\"" +
- " }" +
- "}").get())
- .isInstanceOf(IllegalArgumentException.class);
- }
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/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 85987f5..3d60dab 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
@@ -538,12 +538,10 @@ class ExpungedSerializationTest {
.isInstanceOf(NoSuchElementException.class);
}
- @Nested
- class DeserializationErrorOnUser {
- @Test
- void expungedShouldThrowWhenMissingUser() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void expungedShouldThrowWhenMissingUser() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"Expunged\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
@@ -567,67 +565,6 @@ class ExpungedSerializationTest {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void expungedShouldThrowWhenUserIsNotAString() {
- 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\": 596" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void expungedShouldThrowWhenUserIsNotWellFormatted() {
- 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@user@anotherUser\"" +
- " }" +
- "}").get())
- .isInstanceOf(IllegalArgumentException.class);
- }
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/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 76fdba3..091a259 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
@@ -464,12 +464,10 @@ class FlagsUpdatedSerializationTest {
.isInstanceOf(NoSuchElementException.class);
}
- @Nested
- class DeserializationErrorOnUser {
- @Test
- void flagsUpdatedShouldThrowWhenMissingUser() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void flagsUpdatedShouldThrowWhenMissingUser() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"FlagsUpdated\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
@@ -495,71 +493,6 @@ class FlagsUpdatedSerializationTest {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void flagsUpdatedShouldThrowWhenUserIsNotAString() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"FlagsUpdated\": {" +
- " \"path\": {" +
- " \"namespace\": \"#private\"," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"mailboxId\": \"18\"," +
- " \"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\": 4569" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void flagsUpdatedShouldThrowWhenUserIsNotWellFormatted() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"FlagsUpdated\": {" +
- " \"path\": {" +
- " \"namespace\": \"#private\"," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"mailboxId\": \"18\"," +
- " \"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@user@anotherUser\"" +
- " }" +
- "}").get())
- .isInstanceOf(IllegalArgumentException.class);
- }
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/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 da5b509..45f7605 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
@@ -290,13 +290,10 @@ class MailboxACLUpdatedEventSerializationTest {
.isInstanceOf(NoSuchElementException.class);
}
- @Nested
- class DeserializationErrorOnUser {
-
- @Test
- void mailboxACLUpdatedShouldThrowWhenMissingUser() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMissingUser() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"MailboxACLUpdated\":{" +
" \"mailboxPath\":{" +
" \"namespace\":\"#private\"," +
@@ -309,48 +306,7 @@ class MailboxACLUpdatedEventSerializationTest {
" \"sessionId\":6" +
" }" +
"}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void mailboxACLUpdatedShouldThrowWhenUserIsNotAString() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"MailboxACLUpdated\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"aclDiff\":{" +
- " \"oldACL\":{}," +
- " \"newACL\":{\"$any\":\"ar\"}}," +
- " \"mailboxId\":\"23\"," +
- " \"sessionId\":6," +
- " \"user\":12345" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void mailboxACLUpdatedShouldThrowWhenUserIsNotWellFormatted() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"MailboxACLUpdated\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"aclDiff\":{" +
- " \"oldACL\":{}," +
- " \"newACL\":{\"$any\":\"ar\"}}," +
- " \"mailboxId\":\"23\"," +
- " \"sessionId\":6," +
- " \"user\":\"user@domain@secondDomain\"" +
- " }" +
- "}").get())
- .isInstanceOf(IllegalArgumentException.class);
- }
+ .isInstanceOf(NoSuchElementException.class);
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/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 f880328..c491c9f 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
@@ -326,39 +326,5 @@ class MailboxAddedSerializationTest {
"}").get())
.isInstanceOf(NumberFormatException.class);
}
-
- @Test
- void fromJsonShouldRejectLongUser() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
- " \"MailboxAdded\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"bob\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"mailboxId\":\"18\"," +
- " \"user\":15," +
- " \"sessionId\":18" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void fromJsonShouldRejectNullUser() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
- " \"MailboxAdded\":{" +
- " \"mailboxPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"bob\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"mailboxId\":\"18\"," +
- " \"user\":null," +
- " \"sessionId\":18" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/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 4c92630..e0ae086 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
@@ -297,35 +297,12 @@ class MailboxDeletionSerializationTest {
.isInstanceOf(NoSuchElementException.class);
}
- @Nested
- class DeserializationErrorOnUser {
- @Test
- void mailboxAddedShouldThrowWhenMissingUser() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"MailboxDeletion\":{" +
- " \"sessionId\":3652," +
- " \"path\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"user\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"quotaRoot\":\"user@domain\"," +
- " \"deletedMessageCount\":60," +
- " \"totalDeletedSize\":100," +
- " \"mailboxId\":\"789\"" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void mailboxAddedShouldThrowWhenUserIsNotAString() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void mailboxAddedShouldThrowWhenMissingUser() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"MailboxDeletion\":{" +
" \"sessionId\":3652," +
- " \"user\":5489515," +
" \"path\":{" +
" \"namespace\":\"#private\"," +
" \"user\":\"user\"," +
@@ -338,28 +315,6 @@ class MailboxDeletionSerializationTest {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void mailboxAddedShouldThrowWhenUserIsNotWellFormatted() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"MailboxDeletion\":{" +
- " \"sessionId\":3652," +
- " \"user\":\"user@domain@secondDomain\"," +
- " \"path\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"user\"," +
- " \"name\":\"mailboxName\"" +
- " }," +
- " \"quotaRoot\":\"user@domain\"," +
- " \"deletedMessageCount\":60," +
- " \"totalDeletedSize\":100," +
- " \"mailboxId\":\"789\"" +
- " }" +
- "}").get())
- .isInstanceOf(IllegalArgumentException.class);
- }
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/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 e5ffc7e..b19b20c 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
@@ -284,13 +284,10 @@ class MailboxRenamedSerializationTest {
@Nested
class DeserializationErrors {
-
- @Nested
- class DeserializationErrorOnUser {
- @Test
- void mailboxRenamedDeSerializeShouldThrowWhenNullUser() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
+ @Test
+ void mailboxRenamedDeSerializeShouldThrowWhenMissingUser() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
" \"MailboxRenamed\":{" +
" \"sessionId\":123456789," +
" \"path\":{" +
@@ -307,55 +304,6 @@ class MailboxRenamedSerializationTest {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void mailboxRenamedDeSerializeShouldThrowWhenEmptyUser() {
- String eventWithEmptyUser =
- "{" +
- " \"MailboxRenamed\":{" +
- " \"sessionId\":123456789," +
- " \"user\":\"\"," +
- " \"path\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"user\"," +
- " \"name\":\"oldMailboxName\"" +
- " }," +
- " \"mailboxId\":\"123456\"," +
- " \"newPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"user\"," +
- " \"name\":\"newMailboxName\"" +
- " }" +
- " }" +
- "}";
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(eventWithEmptyUser).get())
- .isInstanceOf(IllegalArgumentException.class);
- }
-
- @Test
- void mailboxRenamedDeSerializeShouldThrowWhenBadUser() {
- String eventWithBadUser =
- "{" +
- " \"MailboxRenamed\":{" +
- " \"sessionId\":123456789," +
- " \"user\":\"user@user@user\"," +
- " \"path\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"user\"," +
- " \"name\":\"oldMailboxName\"" +
- " }," +
- " \"mailboxId\":\"123456\"," +
- " \"newPath\":{" +
- " \"namespace\":\"#private\"," +
- " \"user\":\"user\"," +
- " \"name\":\"newMailboxName\"" +
- " }" +
- " }" +
- "}";
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(eventWithBadUser).get())
- .isInstanceOf(IllegalArgumentException.class);
- }
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
index f3008dc..6e09af1 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MessageMoveEventSerializationTest.java
@@ -70,39 +70,6 @@ class MessageMoveEventSerializationTest {
@Nested
class ValidPayloads {
@Nested
- class NoVirtualHosting {
- private final Event event = MessageMoveEvent.builder()
- .user(User.fromUsername("bob"))
- .messageId(TestMessageId.of(42))
- .messageMoves(
- MessageMoves.builder()
- .previousMailboxIds(TestId.of(18), TestId.of(24))
- .targetMailboxIds(TestId.of(36))
- .build())
- .build();
- private final String json = "{" +
- " \"MessageMoveEvent\": {" +
- " \"user\": \"bob\"," +
- " \"previousMailboxIds\": [\"18\", \"24\"]," +
- " \"targetMailboxIds\": [\"36\"]," +
- " \"messageIds\": [\"42\"]" +
- " }" +
- "}";
-
- @Test
- void messageMoveEventShouldBeWellSerialized() {
- assertThatJson(EVENT_SERIALIZER.toJson(event))
- .isEqualTo(json);
- }
-
- @Test
- void messageMoveEventShouldBeWellDeSerialized() {
- assertThat(EVENT_SERIALIZER.fromJson(json).get())
- .isEqualTo(event);
- }
- }
-
- @Nested
class EmptyTargetMailboxIds {
private final Event event = MessageMoveEvent.builder()
.user(User.fromUsername("bob"))
@@ -201,57 +168,6 @@ class MessageMoveEventSerializationTest {
@Nested
class InvalidPayloads {
- @Test
- void emptyUserShouldBeRejected() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
- " \"MessageMoveEvent\": {" +
- " \"user\": \"\"," +
- " \"previousMailboxIds\": [\"18\", \"24\"]," +
- " \"targetMailboxIds\": [\"36\"]," +
- " \"messageIds\": [\"42\"]" +
- " }" +
- "}").get())
- .isInstanceOf(IllegalArgumentException.class);
- }
-
- @Test
- void basUsersShouldBeRejected() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
- " \"MessageMoveEvent\": {" +
- " \"user\": \"bob@domain.tld@bad\"," +
- " \"previousMailboxIds\": [\"18\", \"24\"]," +
- " \"targetMailboxIds\": [\"36\"]," +
- " \"messageIds\": [\"42\"]" +
- " }" +
- "}").get())
- .isInstanceOf(IllegalArgumentException.class);
- }
-
- @Test
- void nonStringUserShouldBeRejected() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
- " \"MessageMoveEvent\": {" +
- " \"user\": 42," +
- " \"previousMailboxIds\": [\"18\", \"24\"]," +
- " \"targetMailboxIds\": [\"36\"]," +
- " \"messageIds\": [\"42\"]" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void nullUserShouldBeRejected() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson("{" +
- " \"MessageMoveEvent\": {" +
- " \"user\": null," +
- " \"previousMailboxIds\": [\"18\", \"24\"]," +
- " \"targetMailboxIds\": [\"36\"]," +
- " \"messageIds\": [\"42\"]" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
@Test
void nullPreviousMailboxIdsShouldBeRejected() {
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
index 9b940fb..b76b53b 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java
@@ -67,132 +67,49 @@ class QuotaUsageUpdatedEventSerializationTest {
private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory());
- @Nested
- class WithUser {
-
- @Nested
- class WithValidUser {
-
- @Nested
- class WithUserContainsOnlyUsername {
-
- private final MailboxListener.QuotaUsageUpdatedEvent eventWithUserContainsUsername = new MailboxListener.QuotaUsageUpdatedEvent(
- User.fromUsername("onlyUsername"),
- QUOTA_ROOT,
- QUOTA_COUNT,
- QUOTA_SIZE,
- INSTANT);
- private final String quotaUsageUpdatedEvent =
- "{" +
- "\"QuotaUsageUpdatedEvent\":{" +
- "\"quotaRoot\":\"foo\"," +
- "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
- "\"time\":\"2018-11-13T12:00:55Z\"," +
- "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
- "\"user\":\"onlyUsername\"" +
- "}" +
- "}";
-
- @Test
- void fromJsonShouldReturnQuotaEvent() {
- assertThat(EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
- .isEqualTo(eventWithUserContainsUsername);
- }
-
- @Test
- void toJsonShouldReturnQuotaEventJson() {
- assertThatJson(EVENT_SERIALIZER.toJson(eventWithUserContainsUsername))
- .isEqualTo(quotaUsageUpdatedEvent);
- }
- }
-
- @Nested
- class WithUserContainsUsernameAndDomain {
-
- private final MailboxListener.QuotaUsageUpdatedEvent eventWithUserContainsUsernameAndDomain = new MailboxListener.QuotaUsageUpdatedEvent(
- User.fromUsername("user@domain"),
- QUOTA_ROOT,
- QUOTA_COUNT,
- QUOTA_SIZE,
- INSTANT);
- private final String quotaUsageUpdatedEvent =
- "{" +
- "\"QuotaUsageUpdatedEvent\":{" +
- "\"quotaRoot\":\"foo\"," +
- "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
- "\"time\":\"2018-11-13T12:00:55Z\"," +
- "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
- "\"user\":\"user@domain\"" +
- "}" +
- "}";
-
- @Test
- void fromJsonShouldReturnQuotaEvent() {
- assertThat(EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
- .isEqualTo(eventWithUserContainsUsernameAndDomain);
- }
-
- @Test
- void toJsonShouldReturnQuotaEventJson() {
- assertThatJson(EVENT_SERIALIZER.toJson(eventWithUserContainsUsernameAndDomain))
- .isEqualTo(quotaUsageUpdatedEvent);
- }
- }
- }
-
- @Nested
- class WithInvalidUser {
-
- @Test
- void fromJsonShouldThrowWhenEmptyUser() {
- String quotaUsageUpdatedEvent =
- "{" +
- "\"QuotaUsageUpdatedEvent\":{" +
- "\"quotaRoot\":\"foo\"," +
- "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
- "\"time\":\"2018-11-13T12:00:55Z\"," +
- "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
- "\"user\":\"\"" +
- "}" +
- "}";
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent))
- .isInstanceOf(IllegalArgumentException.class);
- }
-
+ private final MailboxListener.QuotaUsageUpdatedEvent eventWithUserContainsUsername = new MailboxListener.QuotaUsageUpdatedEvent(
+ User.fromUsername("onlyUsername"),
+ QUOTA_ROOT,
+ QUOTA_COUNT,
+ QUOTA_SIZE,
+ INSTANT);
+ private final String quotaUsageUpdatedEvent =
+ "{" +
+ "\"QuotaUsageUpdatedEvent\":{" +
+ "\"quotaRoot\":\"foo\"," +
+ "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
+ "\"time\":\"2018-11-13T12:00:55Z\"," +
+ "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
+ "\"user\":\"onlyUsername\"" +
+ "}" +
+ "}";
- @Test
- void fromJsonShouldThrowResultWhenUserIsNull() {
- String quotaUsageUpdatedEvent =
- "{" +
- "\"QuotaUsageUpdatedEvent\":{" +
- "\"quotaRoot\":\"foo\"," +
- "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
- "\"time\":\"2018-11-13T12:00:55Z\"," +
- "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}" +
- "}" +
- "}";
+ @Test
+ void fromJsonShouldReturnQuotaEvent() {
+ assertThat(EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
+ .isEqualTo(eventWithUserContainsUsername);
+ }
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
- .isInstanceOf(NoSuchElementException.class);
- }
+ @Test
+ void toJsonShouldReturnQuotaEventJson() {
+ assertThatJson(EVENT_SERIALIZER.toJson(eventWithUserContainsUsername))
+ .isEqualTo(quotaUsageUpdatedEvent);
+ }
- @Test
- void fromJsonShouldThrowWhenUserIsInvalid() {
- String quotaUsageUpdatedEvent =
- "{" +
- "\"QuotaUsageUpdatedEvent\":{" +
- "\"quotaRoot\":\"foo\"," +
- "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
- "\"time\":\"2018-11-13T12:00:55Z\"," +
- "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," +
- "\"user\":\"@domain\"" +
- "}" +
- "}";
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent))
- .isInstanceOf(IllegalArgumentException.class);
- }
- }
+ @Test
+ void fromJsonShouldThrowResultWhenUserIsMissing() {
+ String quotaUsageUpdatedEvent =
+ "{" +
+ "\"QuotaUsageUpdatedEvent\":{" +
+ "\"quotaRoot\":\"foo\"," +
+ "\"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," +
+ "\"time\":\"2018-11-13T12:00:55Z\"," +
+ "\"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}" +
+ "}" +
+ "}";
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get())
+ .isInstanceOf(NoSuchElementException.class);
}
@Nested
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
index 49ad7eb..11e3eed 100644
--- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/SessionIdTest.java
@@ -41,8 +41,8 @@ class SessionIdTest {
@Test
void sessionIdShouldBeWellSerialized() {
- assertThat(JSON_SERIALIZE.sessionIdWrites().writes(MailboxSession.SessionId.of(18)).toString())
- .isEqualTo("18");
+ assertThat(JSON_SERIALIZE.sessionIdWrites().writes(MailboxSession.SessionId.of(18)))
+ .isEqualTo(new JsNumber(BigDecimal.valueOf(18)));
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/21eff068/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java
new file mode 100644
index 0000000..25d277e
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UserTest.java
@@ -0,0 +1,90 @@
+/****************************************************************
+ * 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.core.User;
+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 UserTest {
+ private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+ @Test
+ void userShouldBeWellSerialized() {
+ assertThat(JSON_SERIALIZE.userWriters().writes(User.fromUsername("bob")))
+ .isEqualTo(new JsString("bob"));
+ }
+
+ @Test
+ void userShouldBeWellDeSerialized() {
+ assertThat(JSON_SERIALIZE.userReads().reads(new JsString("bob")))
+ .isEqualTo(new JsSuccess<>(User.fromUsername("bob"), new JsPath(List.empty())));
+ }
+
+ @Test
+ void userShouldBeWellSerializedWhenVirtualHosting() {
+ assertThat(JSON_SERIALIZE.userWriters().writes(User.fromUsername("bob@domain")))
+ .isEqualTo(new JsString("bob@domain"));
+ }
+
+ @Test
+ void userShouldBeWellDeSerializedWhenVirtualHosting() {
+ assertThat(JSON_SERIALIZE.userReads().reads(new JsString("bob@domain")))
+ .isEqualTo(new JsSuccess<>(User.fromUsername("bob@domain"), new JsPath(List.empty())));
+ }
+
+ @Test
+ void userDeserializationShouldReturnErrorWhenNumber() {
+ assertThat(JSON_SERIALIZE.userReads().reads(new JsNumber(BigDecimal.valueOf(18))))
+ .isInstanceOf(JsError.class);
+ }
+
+ @Test
+ void userDeserializationShouldReturnErrorWhenNull() {
+ assertThat(JSON_SERIALIZE.userReads().reads(JsNull$.MODULE$))
+ .isInstanceOf(JsError.class);
+ }
+
+ @Test
+ void userDeserializationShouldThrowWhenBadUsername() {
+ assertThatThrownBy(() -> JSON_SERIALIZE.userReads().reads(new JsString("bob@bad@bad")))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void userDeserializationShouldThrowWhenEmpty() {
+ assertThatThrownBy(() -> JSON_SERIALIZE.userReads().reads(new JsString("")))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org