MAILBOX-359 Use a fixture for the serializers
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/38ebe826 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/38ebe826 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/38ebe826 Branch: refs/heads/master Commit: 38ebe82603cb19909f1c1e074c34e963b513ad34 Parents: 19710d4 Author: Benoit Tellier <[email protected]> Authored: Mon Dec 24 16:06:21 2018 +0700 Committer: Benoit Tellier <[email protected]> Committed: Tue Jan 8 14:39:20 2019 +0700 ---------------------------------------------------------------------- .../event/json/AddedSerializationTest.java | 3 +- .../event/json/ExpungedSerializationTest.java | 3 +- .../json/FlagsUpdatedSerializationTest.java | 4 +- ...MailboxACLUpdatedEventSerializationTest.java | 89 +------------------- .../json/MailboxAddedSerializationTest.java | 7 +- .../json/MailboxDeletionSerializationTest.java | 4 +- .../json/MailboxRenamedSerializationTest.java | 4 +- .../json/MessageMoveEventSerializationTest.java | 3 +- ...QuotaUsageUpdatedEventSerializationTest.java | 6 +- .../james/event/json/SerializerFixture.java | 28 ++++++ .../james/event/json/dtos/ACLDiffTest.java | 55 ++++++++---- .../apache/james/event/json/dtos/FlagsTest.java | 56 ++++++------ .../james/event/json/dtos/MailboxIdTest.java | 20 ++--- .../james/event/json/dtos/MailboxPathTest.java | 31 +++---- .../james/event/json/dtos/MessageIdTest.java | 17 ++-- .../event/json/dtos/MessageMetaDataTest.java | 44 +++++----- .../james/event/json/dtos/MessageUidTest.java | 16 ++-- .../james/event/json/dtos/QuotaRootTest.java | 31 +++---- .../james/event/json/dtos/SessionIdTest.java | 19 ++--- .../james/event/json/dtos/UpdatedFlagsTest.java | 16 ++-- .../apache/james/event/json/dtos/UserTest.java | 29 +++---- 21 files changed, 191 insertions(+), 294 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 327d5ba..7760523 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 @@ -20,6 +20,7 @@ package org.apache.james.event.json; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -92,8 +93,6 @@ class AddedSerializationTest { " }" + "}"; - private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); - @Test void addedShouldBeWellSerialized() { assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_ADDED_EVENT)) http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 0e46b59..85e0365 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 @@ -20,6 +20,7 @@ package org.apache.james.event.json; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -92,8 +93,6 @@ class ExpungedSerializationTest { " }" + "}"; - private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); - @Test void expungedShouldBeWellSerialized() { assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_EXPUNGED_EVENT)) http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 0fee8a15..941a5de 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 @@ -20,6 +20,7 @@ package org.apache.james.event.json; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -37,7 +38,6 @@ import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.TestId; -import org.apache.james.mailbox.model.TestMessageId; import org.apache.james.mailbox.model.UpdatedFlags; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -120,8 +120,6 @@ class FlagsUpdatedSerializationTest { " }" + "}"; - private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); - @Test void flagsUpdatedShouldBeWellSerialized() { assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_EVENT)) http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 a4cefb3..8feb069 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 @@ -20,6 +20,7 @@ package org.apache.james.event.json; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -33,7 +34,6 @@ import org.apache.james.mailbox.model.MailboxACL; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxPath; 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; @@ -42,7 +42,6 @@ class MailboxACLUpdatedEventSerializationTest { private static final User USER = User.fromUsername("user"); private static final MailboxACL.EntryKey ENTRY_KEY = org.apache.james.mailbox.model.MailboxACL.EntryKey.createGroupEntryKey("any", false); private static final MailboxACL.Rfc4314Rights RIGHTS = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Administer, MailboxACL.Right.Read); - private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); private static final MailboxACL MAILBOX_ACL = new MailboxACL( new MailboxACL.Entry(ENTRY_KEY, RIGHTS), new MailboxACL.Entry(MailboxACL.EntryKey.createUserEntryKey("alice", true), @@ -84,92 +83,6 @@ class MailboxACLUpdatedEventSerializationTest { } @Nested - class EmptyRightInMailboxACL { - - private final String jsonNullRight = - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{\"$any\":\"\"}," + - " \"newACL\":{}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}"; - - private final MailboxACL mailboxACL = new MailboxACL( - new MailboxACL.Entry(ENTRY_KEY, new MailboxACL.Rfc4314Rights())); - - private final MailboxListener.MailboxACLUpdated mailboxACLUpdated = new MailboxListener.MailboxACLUpdated( - MailboxSession.SessionId.of(6), - USER, - new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"), - ACLDiff.computeDiff(mailboxACL, MailboxACL.EMPTY), - TestId.of(23)); - - @Test - void mailboxACLUpdatedShouldBeWellSerializedWithNullRight() { - assertThatJson(EVENT_SERIALIZER.toJson(mailboxACLUpdated)) - .isEqualTo(jsonNullRight); - } - - @Test - void mailboxACLUpdatedShouldBeWellDeSerializedWithNullUser() { - assertThat(EVENT_SERIALIZER.fromJson(jsonNullRight).get()) - .isEqualTo(mailboxACLUpdated); - } - } - - @Nested - class DoubleRightInMailboxACL { - - private final String jsonDoubleRight = - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{\"$any\":\"aa\"}," + - " \"newACL\":{}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}"; - - private final MailboxACL mailboxACL = new MailboxACL( - new MailboxACL.Entry(ENTRY_KEY, new MailboxACL.Rfc4314Rights(MailboxACL.Right.Administer))); - - private final MailboxListener.MailboxACLUpdated mailboxACLUpdated = new MailboxListener.MailboxACLUpdated( - MailboxSession.SessionId.of(6), - USER, - new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"), - ACLDiff.computeDiff(mailboxACL, MailboxACL.EMPTY), - TestId.of(23)); - - @Test - void mailboxACLUpdatedShouldBeWellSerializedWithNullRight() { - assertThatJson(EVENT_SERIALIZER.toJson(mailboxACLUpdated)) - .isNotEqualTo(jsonDoubleRight); - } - - @Test - void mailboxACLUpdatedShouldBeWellDeSerializedWithNullUser() { - assertThat(EVENT_SERIALIZER.fromJson(jsonDoubleRight).get()) - .isEqualTo(mailboxACLUpdated); - } - } - - @Nested class DeserializationErrors { @Test void mailboxACLUpdatedShouldThrowWhenMissingSessionId() { http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 51c87e7..d8e58b1 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 @@ -20,6 +20,7 @@ package org.apache.james.event.json; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -31,22 +32,16 @@ import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxPath; 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; class MailboxAddedSerializationTest { - private static final User USER = User.fromUsername("user"); - - private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); - private static final MailboxListener.MailboxAdded EVENT_1 = new MailboxListener.MailboxAdded( MailboxSession.SessionId.of(42), USER, new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"), TestId.of(18)); - private static final String JSON_1 = "{" + " \"MailboxAdded\":{" + " \"mailboxPath\":{" + http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 1f76c5b..313dc33 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 @@ -20,6 +20,7 @@ package org.apache.james.event.json; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER; import static org.apache.james.mailbox.model.MailboxConstants.USER_NAMESPACE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -36,7 +37,6 @@ import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.QuotaRoot; 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; @@ -75,8 +75,6 @@ class MailboxDeletionSerializationTest { " }" + "}"; - private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); - @Test void mailboxAddedShouldBeWellSerialized() { assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_MAILBOX_DELETION_EVENT)) http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 1989186..de65db2 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 @@ -20,6 +20,7 @@ package org.apache.james.event.json; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER; import static org.apache.james.mailbox.model.MailboxConstants.USER_NAMESPACE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -32,7 +33,6 @@ import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxPath; 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; @@ -71,8 +71,6 @@ class MailboxRenamedSerializationTest { " }" + "}"; - private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); - @Test void mailboxRenamedShouldBeWellSerialized() { assertThatJson(EVENT_SERIALIZER.toJson(DEFAULT_MAILBOX_RENAMED_EVENT)) http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 6e09af1..8110215 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 @@ -20,6 +20,7 @@ package org.apache.james.event.json; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -35,8 +36,6 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; class MessageMoveEventSerializationTest { - private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); - private static final Event EVENT = MessageMoveEvent.builder() .user(User.fromUsername("[email protected]")) .messageId(TestMessageId.of(42)) http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 f0cbe7f..0e97545 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 @@ -20,6 +20,7 @@ package org.apache.james.event.json; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -33,8 +34,6 @@ import org.apache.james.core.quota.QuotaSize; import org.apache.james.mailbox.MailboxListener; import org.apache.james.mailbox.model.Quota; import org.apache.james.mailbox.model.QuotaRoot; -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; @@ -51,9 +50,6 @@ class QuotaUsageUpdatedEventSerializationTest { .computedLimit(QuotaSize.size(10000)) .build(); private static final Instant INSTANT = Instant.parse("2018-11-13T12:00:55Z"); - - private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); - private final MailboxListener.QuotaUsageUpdatedEvent eventWithUserContainsUsername = new MailboxListener.QuotaUsageUpdatedEvent( User.fromUsername("onlyUsername"), QUOTA_ROOT, http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java new file mode 100644 index 0000000..5d9bcaf --- /dev/null +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java @@ -0,0 +1,28 @@ +/**************************************************************** + * 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; + +import org.apache.james.mailbox.model.TestId; +import org.apache.james.mailbox.model.TestMessageId; + +public interface SerializerFixture { + JsonSerialize DTO_JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory()); + EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); +} http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java index 8288261..e0aca09 100644 --- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java @@ -19,15 +19,18 @@ package org.apache.james.event.json.dtos; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; 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.apache.james.mailbox.acl.ACLDiff; +import org.apache.james.mailbox.exception.UnsupportedRightException; +import org.apache.james.mailbox.model.MailboxACL; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import com.google.common.collect.ImmutableMap; + import play.api.libs.json.JsError; import play.api.libs.json.JsNull$; import play.api.libs.json.JsNumber; @@ -36,18 +39,38 @@ import play.api.libs.json.Json; import scala.math.BigDecimal; class ACLDiffTest { - private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory()); - @Test void deSerializeShouldThrowWhenNewACLIsMissing() { - assertThat(JSON_SERIALIZE.aclDiffReads().reads(Json.parse( + assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse( "{\"oldACL\":{}}"))) .isInstanceOf(JsError.class); } @Test + void deSerializeShouldAcceptDoubleRight() { + assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse( + "{\"oldACL\":{\"$any\":\"aa\"},\"newACL\":{}}")) + .get().toJava()) + .isEqualTo(new ACLDiff(new MailboxACL(ImmutableMap.of( + new MailboxACL.EntryKey("any", MailboxACL.NameType.group, false), + new MailboxACL.Rfc4314Rights(MailboxACL.Right.Administer))), + new MailboxACL())); + } + + @Test + void deSerializeShouldAcceptEmptyRight() { + assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse( + "{\"oldACL\":{\"$any\":\"\"},\"newACL\":{}}")) + .get().toJava()) + .isEqualTo(new ACLDiff(new MailboxACL(ImmutableMap.of( + new MailboxACL.EntryKey("any", MailboxACL.NameType.group, false), + new MailboxACL.Rfc4314Rights())), + new MailboxACL())); + } + + @Test void deSerializeShouldThrowWhenOldACLIsMissing() { - assertThat(JSON_SERIALIZE.aclDiffReads().reads(Json.parse( + assertThat(DTO_JSON_SERIALIZE.aclDiffReads().reads(Json.parse( "{\"newACL\":{}}"))) .isInstanceOf(JsError.class); } @@ -56,31 +79,31 @@ class ACLDiffTest { class EntryKeyTest { @Test void deSerializeShouldThrowWhenNotIncludedNameInEntryKey() { - assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("$"))) + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("$"))) .isInstanceOf(IllegalStateException.class); } @Test void deSerializeShouldThrowWhenNameInEntryKeyIsEmpty() { - assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString(""))) + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString(""))) .isInstanceOf(IllegalArgumentException.class); } @Test void deSerializeShouldThrowWhenNameInEntryKeyIsNotWellFormatted() { - assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("-"))) + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("-"))) .isInstanceOf(StringIndexOutOfBoundsException.class); } @Test void deSerializeShouldThrowWhenNameInEntryKeyIsNull() { - assertThat(JSON_SERIALIZE.aclEntryKeyReads().reads(JsNull$.MODULE$)) + assertThat(DTO_JSON_SERIALIZE.aclEntryKeyReads().reads(JsNull$.MODULE$)) .isInstanceOf(JsError.class); } @Test void deSerializeShouldThrowWhenNameInEntryKeyIsNotString() { - assertThat(JSON_SERIALIZE.aclEntryKeyReads().reads(new JsNumber(BigDecimal.valueOf(18)))) + assertThat(DTO_JSON_SERIALIZE.aclEntryKeyReads().reads(new JsNumber(BigDecimal.valueOf(18)))) .isInstanceOf(JsError.class); } } @@ -89,19 +112,19 @@ class ACLDiffTest { class RightTest { @Test void deSerializeShouldThrowWhenUnsupportedRightInNewACL() { - assertThat(JSON_SERIALIZE.aclDiffReads().reads(new JsString("\"unsupported\""))) - .isInstanceOf(JsError.class); + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.aclRightsReads().reads(new JsString("\"unsupported\""))) + .isInstanceOf(UnsupportedRightException.class); } @Test void deSerializeShouldThrowWhenNull() { - assertThat(JSON_SERIALIZE.aclDiffReads().reads(JsNull$.MODULE$)) + assertThat(DTO_JSON_SERIALIZE.aclRightsReads().reads(JsNull$.MODULE$)) .isInstanceOf(JsError.class); } @Test void deSerializeShouldThrowWhenRightIsNotString() { - assertThat(JSON_SERIALIZE.aclDiffReads().reads(new JsNumber(BigDecimal.valueOf(18)))) + assertThat(DTO_JSON_SERIALIZE.aclRightsReads().reads(new JsNumber(BigDecimal.valueOf(18)))) .isInstanceOf(JsError.class); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java index a41c245..9e70b7d 100644 --- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/FlagsTest.java @@ -20,6 +20,7 @@ package org.apache.james.event.json.dtos; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -28,19 +29,14 @@ import java.util.NoSuchElementException; import javax.mail.Flags; import org.apache.james.event.json.DTOs; -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.Json; class FlagsTest { - private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory()); - @Test void emptyFlagsShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( + assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( new Flags())) .toString()) .isEqualTo("{\"systemFlags\":[],\"userFlags\":[]}"); @@ -48,7 +44,7 @@ class FlagsTest { @Test void answeredShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( + assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( new Flags(Flags.Flag.ANSWERED))) .toString()) .isEqualTo("{\"systemFlags\":[\"Answered\"],\"userFlags\":[]}"); @@ -56,7 +52,7 @@ class FlagsTest { @Test void deletedShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( + assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( new Flags(Flags.Flag.DELETED))) .toString()) .isEqualTo("{\"systemFlags\":[\"Deleted\"],\"userFlags\":[]}"); @@ -64,7 +60,7 @@ class FlagsTest { @Test void draftShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( + assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( new Flags(Flags.Flag.DRAFT))) .toString()) .isEqualTo("{\"systemFlags\":[\"Draft\"],\"userFlags\":[]}"); @@ -72,7 +68,7 @@ class FlagsTest { @Test void flaggedShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( + assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( new Flags(Flags.Flag.FLAGGED))) .toString()) .isEqualTo("{\"systemFlags\":[\"Flagged\"],\"userFlags\":[]}"); @@ -80,7 +76,7 @@ class FlagsTest { @Test void recentShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( + assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( new Flags(Flags.Flag.RECENT))) .toString()) .isEqualTo("{\"systemFlags\":[\"Recent\"],\"userFlags\":[]}"); @@ -88,7 +84,7 @@ class FlagsTest { @Test void seenShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( + assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( new Flags(Flags.Flag.SEEN))) .toString()) .isEqualTo("{\"systemFlags\":[\"Seen\"],\"userFlags\":[]}"); @@ -96,7 +92,7 @@ class FlagsTest { @Test void userFlagShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( + assertThatJson(DTO_JSON_SERIALIZE.flagWrites().writes(DTOs.Flags$.MODULE$.fromJavaFlags( new Flags("user flag"))) .toString()) .isEqualTo("{\"systemFlags\":[],\"userFlags\":[\"user flag\"]}"); @@ -105,7 +101,7 @@ class FlagsTest { @Test void emptyFlagsShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[]}")) .get())) .isEqualTo(new Flags()); } @@ -113,7 +109,7 @@ class FlagsTest { @Test void answeredShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Answered\"],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Answered\"],\"userFlags\":[]}")) .get())) .isEqualTo(new Flags(Flags.Flag.ANSWERED)); } @@ -121,7 +117,7 @@ class FlagsTest { @Test void deletedShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Deleted\"],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Deleted\"],\"userFlags\":[]}")) .get())) .isEqualTo(new Flags(Flags.Flag.DELETED)); } @@ -129,7 +125,7 @@ class FlagsTest { @Test void draftShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Draft\"],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Draft\"],\"userFlags\":[]}")) .get())) .isEqualTo(new Flags(Flags.Flag.DRAFT)); } @@ -137,7 +133,7 @@ class FlagsTest { @Test void flaggedShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Flagged\"],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Flagged\"],\"userFlags\":[]}")) .get())) .isEqualTo(new Flags(Flags.Flag.FLAGGED)); } @@ -145,7 +141,7 @@ class FlagsTest { @Test void recentShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Recent\"],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Recent\"],\"userFlags\":[]}")) .get())) .isEqualTo(new Flags(Flags.Flag.RECENT)); } @@ -153,7 +149,7 @@ class FlagsTest { @Test void seenShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Seen\"],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"Seen\"],\"userFlags\":[]}")) .get())) .isEqualTo(new Flags(Flags.Flag.SEEN)); } @@ -161,7 +157,7 @@ class FlagsTest { @Test void userFlagShouldBeWellDeSerialized() { assertThat(DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[\"user flag\"]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[\"user flag\"]}")) .get())) .isEqualTo(new Flags("user flag")); } @@ -169,7 +165,7 @@ class FlagsTest { @Test void deserializeShouldThrowWhenUnknownSystemFlag() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"unknown\"],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"unknown\"],\"userFlags\":[]}")) .get())) .isInstanceOf(NoSuchElementException.class); } @@ -177,7 +173,7 @@ class FlagsTest { @Test void deserializeShouldThrowWhenBadCaseSystemFlag() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"AnSwErEd\"],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[\"AnSwErEd\"],\"userFlags\":[]}")) .get())) .isInstanceOf(NoSuchElementException.class); } @@ -185,7 +181,7 @@ class FlagsTest { @Test void deserializeShouldThrowWhenNullSystemFlag() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":null,\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":null,\"userFlags\":[]}")) .get())) .isInstanceOf(NoSuchElementException.class); } @@ -193,7 +189,7 @@ class FlagsTest { @Test void deserializeShouldThrowWhenSystemFlagContainsNullElements() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[null,\"Draft\"],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[null,\"Draft\"],\"userFlags\":[]}")) .get())) .isInstanceOf(NoSuchElementException.class); } @@ -201,7 +197,7 @@ class FlagsTest { @Test void deserializeShouldThrowWhenSystemFlagContainsNotStringElements() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[42,\"Draft\"],\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[42,\"Draft\"],\"userFlags\":[]}")) .get())) .isInstanceOf(NoSuchElementException.class); } @@ -209,7 +205,7 @@ class FlagsTest { @Test void deserializeShouldThrowWhenUserFlagsContainsNullElements() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[null, \"a\"]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[null, \"a\"]}")) .get())) .isInstanceOf(NoSuchElementException.class); } @@ -217,7 +213,7 @@ class FlagsTest { @Test void deserializeShouldThrowWhenUserFlagsContainsNonStringElements() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[42, \"a\"]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[],\"userFlags\":[42, \"a\"]}")) .get())) .isInstanceOf(NoSuchElementException.class); } @@ -225,7 +221,7 @@ class FlagsTest { @Test void deserializeShouldThrowWhenNoUserFlags() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"systemFlags\":[]}")) .get())) .isInstanceOf(NoSuchElementException.class); } @@ -233,7 +229,7 @@ class FlagsTest { @Test void deserializeShouldThrowWhenNoSystemFlags() { assertThatThrownBy(() -> DTOs.Flags$.MODULE$.toJavaFlags( - JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"userFlags\":[]}")) + DTO_JSON_SERIALIZE.flagsReads().reads(Json.parse("{\"userFlags\":[]}")) .get())) .isInstanceOf(NoSuchElementException.class); } http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 index d54505c..aa4a436 100644 --- 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 @@ -19,53 +19,47 @@ package org.apache.james.event.json.dtos; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; 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))) + assertThat(DTO_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()))); + assertThat(DTO_JSON_SERIALIZE.mailboxIdReads().reads(new JsString("18")).get()) + .isEqualTo(TestId.of(18)); } @Test void mailboxIdDeserializationShouldReturnErrorWhenNumber() { - assertThat(JSON_SERIALIZE.mailboxIdReads().reads(new JsNumber(BigDecimal.valueOf(18)))) + assertThat(DTO_JSON_SERIALIZE.mailboxIdReads().reads(new JsNumber(BigDecimal.valueOf(18)))) .isInstanceOf(JsError.class); } @Test void mailboxIdDeserializationShouldReturnErrorWhenNull() { - assertThat(JSON_SERIALIZE.mailboxIdReads().reads(JsNull$.MODULE$)) + assertThat(DTO_JSON_SERIALIZE.mailboxIdReads().reads(JsNull$.MODULE$)) .isInstanceOf(JsError.class); } @Test void mailboxIdDeserializationShouldThrowWhenInvalid() { - assertThatThrownBy(() -> JSON_SERIALIZE.mailboxIdReads().reads(new JsString("invalid"))) + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.mailboxIdReads().reads(new JsString("invalid"))) .isInstanceOf(IllegalArgumentException.class); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java index 613f5a9..a47e582 100644 --- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MailboxPathTest.java @@ -20,14 +20,12 @@ package org.apache.james.event.json.dtos; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; import static org.assertj.core.api.Assertions.assertThat; import org.apache.james.event.json.DTOs; -import org.apache.james.event.json.JsonSerialize; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxPath; -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; @@ -36,11 +34,10 @@ import play.api.libs.json.Json; class MailboxPathTest { private static final String MAILBOX_NAME = "mailboxName"; private static final MailboxPath MAILBOX_PATH = new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", MAILBOX_NAME); - private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory()); @Test void mailboxPathShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(MAILBOX_PATH)).toString()) + assertThatJson(DTO_JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava(MAILBOX_PATH)).toString()) .isEqualTo( "{" + " \"namespace\":\"#private\"," + @@ -51,7 +48,7 @@ class MailboxPathTest { @Test void mailboxPathWithNullUserShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava( + assertThatJson(DTO_JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava( new MailboxPath(MailboxConstants.USER_NAMESPACE, null, MAILBOX_NAME))).toString()) .isEqualTo( "{" + @@ -62,7 +59,7 @@ class MailboxPathTest { @Test void mailboxPathWithEmptyNamespaceShouldBeWellSerialized() { - assertThatJson(JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava( + assertThatJson(DTO_JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava( new MailboxPath("", "user", MAILBOX_NAME))).toString()) .isEqualTo( "{" + @@ -74,7 +71,7 @@ class MailboxPathTest { @Test void mailboxPathWithShouldBeWellDeSerialized() { - assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"user\":\"user\"," + " \"name\":\"mailboxName\"" + @@ -85,7 +82,7 @@ class MailboxPathTest { @Test void mailboxPathWithNullUserShouldBeWellDeSerialized() { - assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"user\":null," + " \"name\":\"mailboxName\"" + @@ -96,7 +93,7 @@ class MailboxPathTest { @Test void mailboxPathWithNoUserShouldBeWellDeSerialized() { - assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"name\":\"mailboxName\"" + "}")).get()) @@ -106,7 +103,7 @@ class MailboxPathTest { @Test void mailboxPathDeserializationShouldFailWhenNoNamespace() { - assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"user\":\"user\"," + " \"name\":\"mailboxName\"" + "}")) @@ -116,7 +113,7 @@ class MailboxPathTest { @Test void mailboxPathDeserializationShouldFailWhenNullNamespace() { - assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":null," + " \"user\":\"user\"," + " \"name\":\"mailboxName\"" + @@ -127,7 +124,7 @@ class MailboxPathTest { @Test void mailboxPathDeserializationShouldFailWhenLongNamespace() { - assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":18," + " \"user\":\"user\"," + " \"name\":\"mailboxName\"" + @@ -137,7 +134,7 @@ class MailboxPathTest { @Test void mailboxPathDeserializationShouldFailWhenLongUser() { - assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"user\":42," + " \"name\":\"mailboxName\"" + @@ -147,7 +144,7 @@ class MailboxPathTest { @Test void mailboxPathDeserializationShouldFailWhenMissingMailboxName() { - assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"user\":\"user\"" + "}"))) @@ -156,7 +153,7 @@ class MailboxPathTest { @Test void mailboxPathDeserializationShouldFailWhenNullMailboxName() { - assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"user\":\"user\"," + " \"name\":null" + @@ -166,7 +163,7 @@ class MailboxPathTest { @Test void mailboxPathDeserializationShouldFailWhenLongMailboxName() { - assertThat(JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"user\":\"user\"," + " \"name\":42" + http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 index 21426fa..ef2c241 100644 --- 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 @@ -19,11 +19,10 @@ package org.apache.james.event.json.dtos; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; 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; @@ -37,35 +36,33 @@ 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))) + assertThat(DTO_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()))); + assertThat(DTO_JSON_SERIALIZE.messageIdReads().reads(new JsString("18")).get()) + .isEqualTo(TestMessageId.of(18)); } @Test void messageIdDeserializationShouldReturnErrorWhenNumber() { - assertThat(JSON_SERIALIZE.messageIdReads().reads(new JsNumber(BigDecimal.valueOf(18)))) + assertThat(DTO_JSON_SERIALIZE.messageIdReads().reads(new JsNumber(BigDecimal.valueOf(18)))) .isInstanceOf(JsError.class); } @Test void messageIdDeserializationShouldReturnErrorWhenNull() { - assertThat(JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$)) + assertThat(DTO_JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$)) .isInstanceOf(JsError.class); } @Test void messageIdDeserializationShouldThrowWhenInvalid() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageIdReads().reads(new JsString("invalid"))) + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageIdReads().reads(new JsString("invalid"))) .isInstanceOf(IllegalArgumentException.class); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 index b8169b5..d351ac6 100644 --- 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 @@ -19,28 +19,24 @@ package org.apache.james.event.json.dtos; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; 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("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"modSeq\": 35," + " \"size\": 45, " + @@ -53,7 +49,7 @@ class MessageMetaDataTest { @Test void deserializeShouldThrowWhenNoUid() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"modSeq\": 35," + " \"flags\": {" + " \"systemFlags\":[\"Answered\",\"Draft\"], " + @@ -68,7 +64,7 @@ class MessageMetaDataTest { @Test void deserializeShouldThrowWhenNoModSeq() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"flags\": {" + " \"systemFlags\":[\"Answered\",\"Draft\"], " + @@ -83,7 +79,7 @@ class MessageMetaDataTest { @Test void deserializeShouldThrowWhenNoSize() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"modSeq\": 35," + " \"flags\": {" + @@ -98,7 +94,7 @@ class MessageMetaDataTest { @Test void deserializeShouldThrowWhenNoInternalDate() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"modSeq\": 35," + " \"flags\": {" + @@ -113,7 +109,7 @@ class MessageMetaDataTest { @Test void deserializeShouldThrowWhenNoMessageId() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"modSeq\": 35," + " \"flags\": {" + @@ -131,7 +127,7 @@ class MessageMetaDataTest { class ModSeqTest { @Test void deserializeShouldThrowWhenNullModSeq() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"modSeq\": null," + " \"flags\": {" + @@ -147,7 +143,7 @@ class MessageMetaDataTest { @Test void deserializeShouldThrowWhenStringModSeq() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"modSeq\": \"42\"," + " \"flags\": {" + @@ -166,7 +162,7 @@ class MessageMetaDataTest { class SizeTest { @Test void deserializeShouldThrowWhenNullSize() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": null," + " \"flags\": {" + @@ -182,7 +178,7 @@ class MessageMetaDataTest { @Test void deserializeShouldThrowWhenStringSize() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": \"42\"," + " \"flags\": {" + @@ -201,7 +197,7 @@ class MessageMetaDataTest { class DeserializationErrorOnInternalDate { @Test void deSerializeShouldThrowWhenInternalDateIsNotInISOFormatBecauseOfMissingTWord() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": 42," + " \"flags\": {" + @@ -217,7 +213,7 @@ class MessageMetaDataTest { @Test void deSerializeShouldThrowWhenInternalDateContainsOnlyDate() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": 42," + " \"flags\": {" + @@ -233,7 +229,7 @@ class MessageMetaDataTest { @Test void deSerializeShouldThrowWhenInternalDateIsMissingHourPart() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": 42," + " \"flags\": {" + @@ -249,7 +245,7 @@ class MessageMetaDataTest { @Test void deSerializeShouldThrowWhenInternalDateIsMissingTimeZone() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": 42," + " \"flags\": {" + @@ -265,7 +261,7 @@ class MessageMetaDataTest { @Test void deSerializeShouldThrowWhenInternalDateIsMissingHours() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": 42," + " \"flags\": {" + @@ -281,7 +277,7 @@ class MessageMetaDataTest { @Test void deSerializeShouldThrowWhenInternalDateIsEmpty() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": 42," + " \"flags\": {" + @@ -297,7 +293,7 @@ class MessageMetaDataTest { @Test void deSerializeShouldThrowWhenInternalDateIsNull() { - assertThatThrownBy(() -> JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": 42," + " \"flags\": {" + @@ -313,7 +309,7 @@ class MessageMetaDataTest { @Test void deSerializeShouldParseValidISOInstants() { - assertThat(JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": 42," + " \"flags\": {" + @@ -330,7 +326,7 @@ class MessageMetaDataTest { @Test void deSerializeShouldParseWhenInternalDateIsMissingMilliSeconds() { - assertThat(JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + + assertThat(DTO_JSON_SERIALIZE.messageMetaDataReads().reads(Json.parse("{" + " \"uid\": 123456," + " \"size\": 42," + " \"flags\": {" + http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java index 55f2a25..e6a2ce3 100644 --- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/MessageUidTest.java @@ -19,12 +19,10 @@ package org.apache.james.event.json.dtos; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; import static org.assertj.core.api.Assertions.assertThat; -import org.apache.james.event.json.JsonSerialize; import org.apache.james.mailbox.MessageUid; -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; @@ -37,29 +35,27 @@ import scala.collection.immutable.List; import scala.math.BigDecimal; class MessageUidTest { - private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory()); - @Test void messageUidShouldBeWellSerialized() { - assertThat(JSON_SERIALIZE.messageUidWrites().writes(MessageUid.of(18))) + assertThat(DTO_JSON_SERIALIZE.messageUidWrites().writes(MessageUid.of(18))) .isEqualTo(new JsNumber(BigDecimal.valueOf(18))); } @Test void messageUidShouldBeWellDeSerialized() { - assertThat(JSON_SERIALIZE.messageUidReads().reads(new JsNumber(BigDecimal.valueOf(18)))) - .isEqualTo(new JsSuccess<>(MessageUid.of(18), new JsPath(List.empty()))); + assertThat(DTO_JSON_SERIALIZE.messageUidReads().reads(new JsNumber(BigDecimal.valueOf(18))).get()) + .isEqualTo(MessageUid.of(18)); } @Test void messageUidShouldReturnErrorWhenString() { - assertThat(JSON_SERIALIZE.messageUidReads().reads(new JsString("18"))) + assertThat(DTO_JSON_SERIALIZE.messageUidReads().reads(new JsString("18"))) .isInstanceOf(JsError.class); } @Test void messageUidShouldReturnErrorWhenNull() { - assertThat(JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$)) + assertThat(DTO_JSON_SERIALIZE.messageIdReads().reads(JsNull$.MODULE$)) .isInstanceOf(JsError.class); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java index 53076a2..4ba88b4 100644 --- a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/QuotaRootTest.java @@ -19,74 +19,67 @@ package org.apache.james.event.json.dtos; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; import org.apache.james.core.Domain; -import org.apache.james.event.json.JsonSerialize; import org.apache.james.mailbox.model.QuotaRoot; -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 QuotaRootTest { - private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory()); - @Test void quotaRootWithDomainShouldBeWellSerialized() { - assertThat(JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("[email protected]", Optional.of(Domain.of("domain.tld"))))) + assertThat(DTO_JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("[email protected]", Optional.of(Domain.of("domain.tld"))))) .isEqualTo(new JsString("[email protected]")); } @Test void quotaRootWithDomainShouldBeWellDeSerialized() { - assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsString("[email protected]"))) - .isEqualTo(new JsSuccess<>(QuotaRoot.quotaRoot("[email protected]", Optional.of(Domain.of("domain.tld"))), new JsPath(List.empty()))); + assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(new JsString("[email protected]")).get()) + .isEqualTo(QuotaRoot.quotaRoot("[email protected]", Optional.of(Domain.of("domain.tld")))); } @Test void quotaRootShouldBeWellSerialized() { - assertThat(JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("bob", Optional.empty()))) + assertThat(DTO_JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("bob", Optional.empty()))) .isEqualTo(new JsString("bob")); } @Test void quotaRootShouldBeWellDeSerialized() { - assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsString("bob"))) - .isEqualTo(new JsSuccess<>(QuotaRoot.quotaRoot("bob", Optional.empty()), new JsPath(List.empty()))); + assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(new JsString("bob")).get()) + .isEqualTo(QuotaRoot.quotaRoot("bob", Optional.empty())); } @Test void emptyQuotaRootShouldBeWellSerialized() { - assertThat(JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("", Optional.empty()))) + assertThat(DTO_JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("", Optional.empty()))) .isEqualTo(new JsString("")); } @Test void emptyQuotaRootShouldBeWellDeSerialized() { - assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsString(""))) - .isEqualTo(new JsSuccess<>(QuotaRoot.quotaRoot("", Optional.empty()), new JsPath(List.empty()))); + assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(new JsString("")).get()) + .isEqualTo(QuotaRoot.quotaRoot("", Optional.empty())); } @Test void emptyQuotaRootShouldReturnErrorWhenNull() { - assertThat(JSON_SERIALIZE.quotaRootReads().reads(JsNull$.MODULE$)) + assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(JsNull$.MODULE$)) .isInstanceOf(JsError.class); } @Test void emptyQuotaRootShouldReturnErrorWhenNotString() { - assertThat(JSON_SERIALIZE.quotaRootReads().reads(new JsNumber(BigDecimal.valueOf(18)))) + assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(new JsNumber(BigDecimal.valueOf(18)))) .isInstanceOf(JsError.class); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 11e3eed..d0ec1ab 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 @@ -19,47 +19,40 @@ package org.apache.james.event.json.dtos; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; import static org.assertj.core.api.Assertions.assertThat; -import org.apache.james.event.json.JsonSerialize; import org.apache.james.mailbox.MailboxSession; -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 SessionIdTest { - private static final JsonSerialize JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory()); - @Test void sessionIdShouldBeWellSerialized() { - assertThat(JSON_SERIALIZE.sessionIdWrites().writes(MailboxSession.SessionId.of(18))) + assertThat(DTO_JSON_SERIALIZE.sessionIdWrites().writes(MailboxSession.SessionId.of(18))) .isEqualTo(new JsNumber(BigDecimal.valueOf(18))); } @Test void sessionIdShouldBeWellDeSerialized() { - assertThat(JSON_SERIALIZE.sessionIdReads().reads(new JsNumber(BigDecimal.valueOf(18)))) - .isEqualTo(new JsSuccess<>(MailboxSession.SessionId.of(18), new JsPath(List.empty()))); + assertThat(DTO_JSON_SERIALIZE.sessionIdReads().reads(new JsNumber(BigDecimal.valueOf(18))).get()) + .isEqualTo(MailboxSession.SessionId.of(18)); } @Test void sessionIdShouldReturnErrorWhenString() { - assertThat(JSON_SERIALIZE.sessionIdReads().reads(new JsString("18"))) + assertThat(DTO_JSON_SERIALIZE.sessionIdReads().reads(new JsString("18"))) .isInstanceOf(JsError.class); } @Test void sessionIdShouldReturnErrorWhenNull() { - assertThat(JSON_SERIALIZE.sessionIdReads().reads(JsNull$.MODULE$)) + assertThat(DTO_JSON_SERIALIZE.sessionIdReads().reads(JsNull$.MODULE$)) .isInstanceOf(JsError.class); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 index 31eda91..e9f91a3 100644 --- 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 @@ -19,22 +19,18 @@ package org.apache.james.event.json.dtos; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; 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( + assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( " {" + " \"uid\": 123456," + " \"modSeq\": \"35\"," + @@ -46,7 +42,7 @@ class UpdatedFlagsTest { @Test void flagsUpdatedShouldThrowWhenMoqSeqIsNull() { - assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( + assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( " {" + " \"uid\": 123456," + " \"modSeq\": null," + @@ -58,7 +54,7 @@ class UpdatedFlagsTest { @Test void flagsUpdatedShouldThrowWhenMoqSeqIsNotAnInteger() { - assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( + assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( " {" + " \"uid\": 123456," + " \"modSeq\": 35.2567454," + @@ -70,7 +66,7 @@ class UpdatedFlagsTest { @Test void flagsUpdatedShouldThrowWhenOldFlagIsMissing() { - assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( + assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( " {" + " \"uid\": 123456," + " \"modSeq\": 35," + @@ -81,7 +77,7 @@ class UpdatedFlagsTest { @Test void flagsUpdatedShouldThrowWhenNewFlagIsMissing() { - assertThat(JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( + assertThat(DTO_JSON_SERIALIZE.updatedFlagsReads().reads(Json.parse( " {" + " \"uid\": 123456," + " \"modSeq\": 35," + http://git-wip-us.apache.org/repos/asf/james-project/blob/38ebe826/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 index 25d277e..2e1d69e 100644 --- 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 @@ -19,72 +19,65 @@ package org.apache.james.event.json.dtos; +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; 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"))) + assertThat(DTO_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()))); + assertThat(DTO_JSON_SERIALIZE.userReads().reads(new JsString("bob")).get()) + .isEqualTo(User.fromUsername("bob")); } @Test void userShouldBeWellSerializedWhenVirtualHosting() { - assertThat(JSON_SERIALIZE.userWriters().writes(User.fromUsername("bob@domain"))) + assertThat(DTO_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()))); + assertThat(DTO_JSON_SERIALIZE.userReads().reads(new JsString("bob@domain")).get()) + .isEqualTo(User.fromUsername("bob@domain")); } @Test void userDeserializationShouldReturnErrorWhenNumber() { - assertThat(JSON_SERIALIZE.userReads().reads(new JsNumber(BigDecimal.valueOf(18)))) + assertThat(DTO_JSON_SERIALIZE.userReads().reads(new JsNumber(BigDecimal.valueOf(18)))) .isInstanceOf(JsError.class); } @Test void userDeserializationShouldReturnErrorWhenNull() { - assertThat(JSON_SERIALIZE.userReads().reads(JsNull$.MODULE$)) + assertThat(DTO_JSON_SERIALIZE.userReads().reads(JsNull$.MODULE$)) .isInstanceOf(JsError.class); } @Test void userDeserializationShouldThrowWhenBadUsername() { - assertThatThrownBy(() -> JSON_SERIALIZE.userReads().reads(new JsString("bob@bad@bad"))) + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.userReads().reads(new JsString("bob@bad@bad"))) .isInstanceOf(IllegalArgumentException.class); } @Test void userDeserializationShouldThrowWhenEmpty() { - assertThatThrownBy(() -> JSON_SERIALIZE.userReads().reads(new JsString(""))) + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.userReads().reads(new JsString(""))) .isInstanceOf(IllegalArgumentException.class); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
