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:22 UTC
[03/47] james-project git commit: MAILBOX-359 Factorize tests for
UpdatedFlags ser-deserialization
MAILBOX-359 Factorize tests for UpdatedFlags 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/b458e405
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b458e405
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b458e405
Branch: refs/heads/master
Commit: b458e40508df877d7d87724073a6f2ba6f380e0d
Parents: 5383b12
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 24 15:34:47 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:37:57 2019 +0700
----------------------------------------------------------------------
.../json/FlagsUpdatedSerializationTest.java | 143 -------------------
.../james/event/json/dtos/UpdatedFlagsTest.java | 92 ++++++++++++
2 files changed, 92 insertions(+), 143 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/b458e405/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 12874ee..0fee8a15 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
@@ -296,148 +296,5 @@ class FlagsUpdatedSerializationTest {
"}").get())
.isInstanceOf(NoSuchElementException.class);
}
-
- @Nested
- class DeserializationErrorOnUpdatedFlags {
- @Nested
- class DeserializationErrorOnMoqSeq {
-
- @Test
- void flagsUpdatedShouldThrowWhenMoqSeqIsAString() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"FlagsUpdated\": {" +
- " \"path\": {" +
- " \"namespace\": 482," +
- " \"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\"]}" +
- " }" +
- " ]," +
- " \"user\": \"user\"" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void flagsUpdatedShouldThrowWhenMoqSeqIsNull() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"FlagsUpdated\": {" +
- " \"path\": {" +
- " \"namespace\": 482," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"mailboxId\": \"18\"," +
- " \"sessionId\": 42," +
- " \"updatedFlags\": [" +
- " {" +
- " \"uid\": 123456," +
- " \"modSeq\": null," +
- " \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
- " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
- " }" +
- " ]," +
- " \"user\": \"user\"" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
-
- @Test
- void flagsUpdatedShouldThrowWhenMoqSeqIsNotALongNumber() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"FlagsUpdated\": {" +
- " \"path\": {" +
- " \"namespace\": 482," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"mailboxId\": \"18\"," +
- " \"sessionId\": 42," +
- " \"updatedFlags\": [" +
- " {" +
- " \"uid\": 123456," +
- " \"modSeq\": 35.2567454," +
- " \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
- " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
- " }" +
- " ]," +
- " \"user\": \"user\"" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
- }
-
- @Nested
- class DeserializationErrorOnOldFlags {
- @Test
- void flagsUpdatedShouldThrowWhenOldFlagsIsNull() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"FlagsUpdated\": {" +
- " \"path\": {" +
- " \"namespace\": 482," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"mailboxId\": \"18\"," +
- " \"sessionId\": 42," +
- " \"updatedFlags\": [" +
- " {" +
- " \"uid\": 123456," +
- " \"modSeq\": \"35\"," +
- " \"oldFlags\": null," +
- " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
- " }" +
- " ]," +
- " \"user\": \"user\"" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
- }
-
- @Nested
- class DeserializationErrorOnNewFlags {
- @Test
- void flagsUpdatedShouldThrowWhenNewFlagsIsNull() {
- assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
- "{" +
- " \"FlagsUpdated\": {" +
- " \"path\": {" +
- " \"namespace\": 482," +
- " \"user\": \"user\"," +
- " \"name\": \"mailboxName\"" +
- " }," +
- " \"mailboxId\": \"18\"," +
- " \"sessionId\": 42," +
- " \"updatedFlags\": [" +
- " {" +
- " \"uid\": 123456," +
- " \"modSeq\": \"35\"," +
- " \"newFlags\": null," +
- " \"oldFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
- " }" +
- " ]," +
- " \"user\": \"user\"" +
- " }" +
- "}").get())
- .isInstanceOf(NoSuchElementException.class);
- }
- }
- }
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/b458e405/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java
new file mode 100644
index 0000000..31eda91
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/UpdatedFlagsTest.java
@@ -0,0 +1,92 @@
+/****************************************************************
+ * 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 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.Json;
+
+class UpdatedFlagsTest {
+ private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory());
+
+ @Test
+ void flagsUpdatedShouldThrowWhenMoqSeqIsAString() {
+ assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+ " {" +
+ " \"uid\": 123456," +
+ " \"modSeq\": \"35\"," +
+ " \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
+ " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
+ " }")))
+ .isInstanceOf(JsError.class);
+ }
+
+ @Test
+ void flagsUpdatedShouldThrowWhenMoqSeqIsNull() {
+ assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+ " {" +
+ " \"uid\": 123456," +
+ " \"modSeq\": null," +
+ " \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
+ " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
+ " }")))
+ .isInstanceOf(JsError.class);
+ }
+
+ @Test
+ void flagsUpdatedShouldThrowWhenMoqSeqIsNotAnInteger() {
+ assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+ " {" +
+ " \"uid\": 123456," +
+ " \"modSeq\": 35.2567454," +
+ " \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
+ " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
+ " }")))
+ .isInstanceOf(JsError.class);
+ }
+
+ @Test
+ void flagsUpdatedShouldThrowWhenOldFlagIsMissing() {
+ assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+ " {" +
+ " \"uid\": 123456," +
+ " \"modSeq\": 35," +
+ " \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
+ " }")))
+ .isInstanceOf(JsError.class);
+ }
+
+ @Test
+ void flagsUpdatedShouldThrowWhenNewFlagIsMissing() {
+ assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse(
+ " {" +
+ " \"uid\": 123456," +
+ " \"modSeq\": 35," +
+ " \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}" +
+ " }")))
+ .isInstanceOf(JsError.class);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org