Skip to content

Commit

Permalink
MAILBOX-359 Factorize tests for SessionId ser-deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa committed Jan 8, 2019
1 parent 7637419 commit 8ca8a33
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 377 deletions.
Expand Up @@ -35,7 +35,7 @@ import play.api.libs.json.{JsError, JsNull, JsNumber, JsObject, JsResult, JsStri

import scala.collection.JavaConverters._

private sealed trait Event {
sealed trait Event {
def toJava: JavaEvent
}

Expand Down Expand Up @@ -190,7 +190,7 @@ private object ScalaConverter {
}
}

private class JsonSerialize(mailboxIdFactory: MailboxId.Factory, messageIdFactory: MessageId.Factory) {
class JsonSerialize(mailboxIdFactory: MailboxId.Factory, messageIdFactory: MessageId.Factory) {
implicit val systemFlagsWrites: Writes[SystemFlag] = Writes.enumNameWrites
implicit val userWriters: Writes[User] = (user: User) => JsString(user.asString)
implicit val quotaRootWrites: Writes[QuotaRoot] = quotaRoot => JsString(quotaRoot.getValue)
Expand Down
Expand Up @@ -510,72 +510,10 @@ void addedShouldBeWellDeSerialized() {

@Nested
class DeserializationErrors {

@Nested
class DeserializationErrorOnSessionId {
@Test
void addedShouldThrowWhenMissingSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"Added\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
" \"user\": \"user\"," +
" \"name\": \"mailboxName\"" +
" }," +
" \"mailboxId\": \"18\"," +
" \"added\": {" +
" \"123456\": {" +
" \"uid\": 123456," +
" \"modSeq\": 35," +
" \"flags\": {" +
" \"systemFlags\":[\"Answered\",\"Draft\"], " +
" \"userFlags\":[\"User Custom Flag\"]}," +
" \"size\": 45, " +
" \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
" \"messageId\": \"42\"" +
" }" +
" }," +
" \"user\": \"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}

@Test
void addedShouldThrowWhenNullSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"Added\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
" \"user\": \"user\"," +
" \"name\": \"mailboxName\"" +
" }," +
" \"mailboxId\": \"18\"," +
" \"added\": {" +
" \"123456\": {" +
" \"uid\": 123456," +
" \"modSeq\": 35," +
" \"flags\": {" +
" \"systemFlags\":[\"Answered\",\"Draft\"], " +
" \"userFlags\":[\"User Custom Flag\"]}," +
" \"size\": 45, " +
" \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
" \"messageId\": \"42\"" +
" }" +
" }," +
" \"sessionId\": null," +
" \"user\": \"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}

@Test
void addedShouldThrowWhenStringSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
@Test
void addedShouldThrowWhenMissingSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"Added\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
Expand All @@ -595,12 +533,10 @@ void addedShouldThrowWhenStringSessionId() {
" \"messageId\": \"42\"" +
" }" +
" }," +
" \"sessionId\": \"42\"," +
" \"user\": \"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}
}

@Nested
Expand Down
Expand Up @@ -509,72 +509,10 @@ void expungedShouldBeWellDeSerialized() {

@Nested
class DeserializationErrors {

@Nested
class DeserializationErrorOnSessionId {
@Test
void expungedShouldThrowWhenMissingSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"Expunged\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
" \"user\": \"user\"," +
" \"name\": \"mailboxName\"" +
" }," +
" \"mailboxId\": \"18\"," +
" \"expunged\": {" +
" \"123456\": {" +
" \"uid\": 123456," +
" \"modSeq\": 35," +
" \"flags\": {" +
" \"systemFlags\":[\"Answered\",\"Draft\"], " +
" \"userFlags\":[\"User Custom Flag\"]}," +
" \"size\": 45, " +
" \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
" \"messageId\": \"42\"" +
" }" +
" }," +
" \"user\": \"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}

@Test
void expungedShouldThrowWhenNullSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"Expunged\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
" \"user\": \"user\"," +
" \"name\": \"mailboxName\"" +
" }," +
" \"mailboxId\": \"18\"," +
" \"expunged\": {" +
" \"123456\": {" +
" \"uid\": 123456," +
" \"modSeq\": 35," +
" \"flags\": {" +
" \"systemFlags\":[\"Answered\",\"Draft\"], " +
" \"userFlags\":[\"User Custom Flag\"]}," +
" \"size\": 45, " +
" \"internalDate\": \"2018-12-14T09:41:51.541Z\"," +
" \"messageId\": \"42\"" +
" }" +
" }," +
" \"sessionId\": null," +
" \"user\": \"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}

@Test
void expungedShouldThrowWhenStringSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
@Test
void expungedShouldThrowWhenMissingSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"Expunged\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
Expand All @@ -594,12 +532,10 @@ void expungedShouldThrowWhenStringSessionId() {
" \"messageId\": \"42\"" +
" }" +
" }," +
" \"sessionId\": \"42\"," +
" \"user\": \"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}
}

@Nested
Expand Down
Expand Up @@ -433,84 +433,17 @@ void flagsUpdatedShouldBeWellDeSerialized() {

@Nested
class DeserializationError {

@Nested
class DeserializationErrorOnSessionId {
@Test
void flagsUpdatedShouldThrowWhenMissingSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"FlagsUpdated\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
" \"user\": \"user\"," +
" \"name\": \"mailboxName\"" +
" }," +
" \"mailboxId\": \"18\"," +
" \"updatedFlags\": [" +
" {" +
" \"uid\": 123456," +
" \"modSeq\": 35," +
" \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
" \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
" }," +
" {" +
" \"uid\": 654321," +
" \"modSeq\": 36," +
" \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
" \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
" }" +
" ]," +
" \"user\": \"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}

@Test
void flagsUpdatedShouldThrowWhenNullSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"FlagsUpdated\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
" \"user\": \"user\"," +
" \"name\": \"mailboxName\"" +
" }," +
" \"mailboxId\": \"18\"," +
" \"sessionId\": null," +
" \"updatedFlags\": [" +
" {" +
" \"uid\": 123456," +
" \"modSeq\": 35," +
" \"oldFlags\": {\"systemFlags\":[\"Deleted\",\"Seen\"],\"userFlags\":[\"Old Flag 1\"]}," +
" \"newFlags\": {\"systemFlags\":[\"Answered\",\"Draft\"],\"userFlags\":[\"New Flag 1\"]}" +
" }," +
" {" +
" \"uid\": 654321," +
" \"modSeq\": 36," +
" \"oldFlags\": {\"systemFlags\":[\"Flagged\",\"Recent\"],\"userFlags\":[\"Old Flag 2\"]}," +
" \"newFlags\": {\"systemFlags\":[\"Answered\",\"Seen\"],\"userFlags\":[\"New Flag 2\"]}" +
" }" +
" ]," +
" \"user\": \"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}

@Test
void flagsUpdatedShouldThrowWhenStringSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
@Test
void flagsUpdatedShouldThrowWhenMissingSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"FlagsUpdated\": {" +
" \"path\": {" +
" \"namespace\": \"#private\"," +
" \"user\": \"user\"," +
" \"name\": \"mailboxName\"" +
" }," +
" \"mailboxId\": \"18\"," +
" \"sessionId\": \"42\"," +
" \"updatedFlags\": [" +
" {" +
" \"uid\": 123456," +
Expand All @@ -529,7 +462,6 @@ void flagsUpdatedShouldThrowWhenStringSessionId() {
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}
}

@Nested
Expand Down
Expand Up @@ -270,54 +270,10 @@ void mailboxACLUpdatedShouldBeWellDeSerializedWithNullUser() {

@Nested
class DeserializationErrors {

@Nested
class DeserializationErrorOnSessionId {
@Test
void mailboxACLUpdatedShouldThrowWhenMissingSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"MailboxACLUpdated\":{" +
" \"mailboxPath\":{" +
" \"namespace\":\"#private\"," +
" \"user\":\"bob\"," +
" \"name\":\"mailboxName\"" +
" }," +
" \"aclDiff\":{" +
" \"oldACL\":{}," +
" \"newACL\":{\"$any\":\"ar\"}}," +
" \"mailboxId\":\"23\"," +
" \"user\":\"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}

@Test
void mailboxACLUpdatedShouldThrowWhenNullSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"MailboxACLUpdated\":{" +
" \"mailboxPath\":{" +
" \"namespace\":\"#private\"," +
" \"user\":\"bob\"," +
" \"name\":\"mailboxName\"" +
" }," +
" \"aclDiff\":{" +
" \"oldACL\":{}," +
" \"newACL\":{\"$any\":\"ar\"}}," +
" \"mailboxId\":\"23\"," +
" \"sessionId\":null," +
" \"user\":\"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}

@Test
void mailboxACLUpdatedShouldThrowWhenStringSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
@Test
void mailboxACLUpdatedShouldThrowWhenMissingSessionId() {
assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
"{" +
" \"MailboxACLUpdated\":{" +
" \"mailboxPath\":{" +
" \"namespace\":\"#private\"," +
Expand All @@ -328,12 +284,10 @@ void mailboxACLUpdatedShouldThrowWhenStringSessionId() {
" \"oldACL\":{}," +
" \"newACL\":{\"$any\":\"ar\"}}," +
" \"mailboxId\":\"23\"," +
" \"sessionId\":\"123\"," +
" \"user\":\"user\"" +
" }" +
"}").get())
.isInstanceOf(NoSuchElementException.class);
}
.isInstanceOf(NoSuchElementException.class);
}

@Nested
Expand Down

0 comments on commit 8ca8a33

Please sign in to comment.