MAILBOX-359 Factorize tests for ACLDiffTest 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/19710d41 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/19710d41 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/19710d41 Branch: refs/heads/master Commit: 19710d410fc1274b8cdaaeba93b0715a3a22cb31 Parents: b458e40 Author: Benoit Tellier <btell...@linagora.com> Authored: Mon Dec 24 15:58:44 2018 +0700 Committer: Benoit Tellier <btell...@linagora.com> Committed: Tue Jan 8 14:37:57 2019 +0700 ---------------------------------------------------------------------- ...MailboxACLUpdatedEventSerializationTest.java | 402 ------------------- .../james/event/json/dtos/ACLDiffTest.java | 108 +++++ 2 files changed, 108 insertions(+), 402 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/19710d41/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 7176c91..a4cefb3 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 @@ -29,7 +29,6 @@ import org.apache.james.core.User; import org.apache.james.mailbox.MailboxListener; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.acl.ACLDiff; -import org.apache.james.mailbox.exception.UnsupportedRightException; import org.apache.james.mailbox.model.MailboxACL; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxPath; @@ -38,8 +37,6 @@ import org.apache.james.mailbox.model.TestMessageId; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import com.fasterxml.jackson.core.JsonParseException; - class MailboxACLUpdatedEventSerializationTest { private static final User USER = User.fromUsername("user"); @@ -230,405 +227,6 @@ class MailboxACLUpdatedEventSerializationTest { .isInstanceOf(NoSuchElementException.class); } - @Nested - class DeserializationErrorOnOldACL { - - @Test - void mailboxACLUpdatedShouldThrowWhenMissingOldACLinACLDiff() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"newACL\":{\"$any\":\"ar\"}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Nested - class DeserializationErrorOnOldACLEntryKey { - - @Test - void mailboxACLUpdatedShouldThrowWhenNotIncludedNameInEntryKey() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{\"$\":\"ar\"}}," + - " \"newACL\":{}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(IllegalStateException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsNotString() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{1234:\"ar\"}}," + - " \"newACL\":{}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(JsonParseException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsEmpty() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{\"\":\"ar\"}}," + - " \"newACL\":{}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenNullEntryKey() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{null:\"ar\"}}," + - " \"newACL\":{}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(JsonParseException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenEntryKeyIsNotWellFormatted() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{\"-\":\"ar\"}}," + - " \"newACL\":{}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(StringIndexOutOfBoundsException.class); - } - } - - @Nested - class DeserializationErrorOnOldACLRight { - - @Test - void mailboxACLUpdatedShouldThrowWhenUnsupportedRightInMailboxACL() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{\"$any\":\"unsupported\"}," + - " \"newACL\":{\"$any\":\"a\"}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(UnsupportedRightException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenNullRightInMailboxACL() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{\"$any\":null}}," + - " \"newACL\":{}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenRightIsNotStringInMailboxACL() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{\"$any\":1234}}," + - " \"newACL\":{}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - } - } - - @Nested - class DeserializationErrorOnNewACL { - - @Test - void mailboxACLUpdatedShouldThrowWhenMissingNewACLinACLDiff() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Nested - class DeserializationErrorOnNewACLEntryKey { - - @Test - void mailboxACLUpdatedShouldThrowWhenNotIncludedNameInEntryKey() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{}," + - " \"newACL\":{\"$\":\"ar\"}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(IllegalStateException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsNotString() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{}," + - " \"newACL\":{1234:\"ar\"}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(JsonParseException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsEmpty() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{}," + - " \"newACL\":{\"\":\"ar\"}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenNullEntryKey() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{}," + - " \"newACL\":{null:\"ar\"}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(JsonParseException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenEntryKeyIsNotWellFormatted() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{}," + - " \"newACL\":{\"-\":\"ar\"}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(StringIndexOutOfBoundsException.class); - } - } - - @Nested - class DeserializationErrorOnNewACLRight { - - @Test - void mailboxACLUpdatedShouldThrowWhenUnsupportedRightInNewACL() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{\"$any\":\"a\"}," + - " \"newACL\":{\"$any\":\"unsupported\"}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(UnsupportedRightException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenNullRightInMailboxACL() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{}," + - " \"newACL\":{\"$any\":null}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - - @Test - void mailboxACLUpdatedShouldThrowWhenRightIsNotString() { - assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( - "{" + - " \"MailboxACLUpdated\":{" + - " \"mailboxPath\":{" + - " \"namespace\":\"#private\"," + - " \"user\":\"bob\"," + - " \"name\":\"mailboxName\"" + - " }," + - " \"aclDiff\":{" + - " \"oldACL\":{}," + - " \"newACL\":{\"$any\":1234}}," + - " \"mailboxId\":\"23\"," + - " \"sessionId\":6," + - " \"user\":\"user\"" + - " }" + - "}").get()) - .isInstanceOf(NoSuchElementException.class); - } - } - } - @Test void mailboxACLUpdatedShouldThrowWhenMissingMailboxId() { assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson( http://git-wip-us.apache.org/repos/asf/james-project/blob/19710d41/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 new file mode 100644 index 0000000..8288261 --- /dev/null +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/ACLDiffTest.java @@ -0,0 +1,108 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.event.json.dtos; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.apache.james.event.json.JsonSerialize; +import org.apache.james.mailbox.model.TestId; +import org.apache.james.mailbox.model.TestMessageId; +import org.junit.jupiter.api.Nested; +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.JsString; +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( + "{\"oldACL\":{}}"))) + .isInstanceOf(JsError.class); + } + + @Test + void deSerializeShouldThrowWhenOldACLIsMissing() { + assertThat(JSON_SERIALIZE.aclDiffReads().reads(Json.parse( + "{\"newACL\":{}}"))) + .isInstanceOf(JsError.class); + } + + @Nested + class EntryKeyTest { + @Test + void deSerializeShouldThrowWhenNotIncludedNameInEntryKey() { + assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("$"))) + .isInstanceOf(IllegalStateException.class); + } + + @Test + void deSerializeShouldThrowWhenNameInEntryKeyIsEmpty() { + assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString(""))) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void deSerializeShouldThrowWhenNameInEntryKeyIsNotWellFormatted() { + assertThatThrownBy(() -> JSON_SERIALIZE.aclEntryKeyReads().reads(new JsString("-"))) + .isInstanceOf(StringIndexOutOfBoundsException.class); + } + + @Test + void deSerializeShouldThrowWhenNameInEntryKeyIsNull() { + assertThat(JSON_SERIALIZE.aclEntryKeyReads().reads(JsNull$.MODULE$)) + .isInstanceOf(JsError.class); + } + + @Test + void deSerializeShouldThrowWhenNameInEntryKeyIsNotString() { + assertThat(JSON_SERIALIZE.aclEntryKeyReads().reads(new JsNumber(BigDecimal.valueOf(18)))) + .isInstanceOf(JsError.class); + } + } + + @Nested + class RightTest { + @Test + void deSerializeShouldThrowWhenUnsupportedRightInNewACL() { + assertThat(JSON_SERIALIZE.aclDiffReads().reads(new JsString("\"unsupported\""))) + .isInstanceOf(JsError.class); + } + + @Test + void deSerializeShouldThrowWhenNull() { + assertThat(JSON_SERIALIZE.aclDiffReads().reads(JsNull$.MODULE$)) + .isInstanceOf(JsError.class); + } + + @Test + void deSerializeShouldThrowWhenRightIsNotString() { + assertThat(JSON_SERIALIZE.aclDiffReads().reads(new JsNumber(BigDecimal.valueOf(18)))) + .isInstanceOf(JsError.class); + } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org