Repository: james-project Updated Branches: refs/heads/master 1c294ddc0 -> 662fa4a95
JAMES-1790 blobId deserves a real type Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7be2166e Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7be2166e Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7be2166e Branch: refs/heads/master Commit: 7be2166ecb1fe3e7ed0711b67b5b506b14366d0d Parents: a8d2de9 Author: Matthieu Baechler <matthieu.baech...@linagora.com> Authored: Tue Jul 5 17:01:32 2016 +0200 Committer: Antoine Duprat <adup...@linagora.com> Committed: Fri Jul 8 14:24:55 2016 +0200 ---------------------------------------------------------------------- .../org/apache/james/jmap/model/Attachment.java | 12 ++-- .../org/apache/james/jmap/model/BlobId.java | 58 +++++++++++++++++++ .../org/apache/james/jmap/model/Message.java | 28 +++++----- .../apache/james/jmap/model/MessageFactory.java | 4 +- .../org/apache/james/jmap/model/SubMessage.java | 12 ++-- .../james/jmap/json/ParsingWritingObjects.java | 3 +- .../SetMessagesCreationProcessorTest.java | 3 +- .../apache/james/jmap/model/AttachmentTest.java | 21 +++---- .../org/apache/james/jmap/model/BlobIdTest.java | 49 ++++++++++++++++ .../james/jmap/model/MailboxMessageTest.java | 59 +++++++++----------- .../jmap/model/SetMessagesResponseTest.java | 4 +- .../james/jmap/model/SubMailboxMessageTest.java | 8 +-- 12 files changed, 180 insertions(+), 81 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Attachment.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Attachment.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Attachment.java index 2cbed7f..2a62684 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Attachment.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Attachment.java @@ -38,7 +38,7 @@ public class Attachment { @JsonPOJOBuilder(withPrefix = "") public static class Builder { - private String blobId; + private BlobId blobId; private String type; private String name; private Long size; @@ -47,7 +47,7 @@ public class Attachment { private Long width; private Long height; - public Builder blobId(String blobId) { + public Builder blobId(BlobId blobId) { this.blobId = blobId; return this; } @@ -88,14 +88,14 @@ public class Attachment { } public Attachment build() { - Preconditions.checkState(!Strings.isNullOrEmpty(blobId), "'blobId' is mandatory"); + Preconditions.checkState(blobId != null, "'blobId' is mandatory"); Preconditions.checkState(!Strings.isNullOrEmpty(type), "'type' is mandatory"); Preconditions.checkState(size != null, "'size' is mandatory"); return new Attachment(blobId, type, Optional.ofNullable(name), size, Optional.ofNullable(cid), isInline, Optional.ofNullable(width), Optional.ofNullable(height)); } } - private final String blobId; + private final BlobId blobId; private final String type; private final Optional<String> name; private final long size; @@ -104,7 +104,7 @@ public class Attachment { private final Optional<Long> width; private final Optional<Long> height; - @VisibleForTesting Attachment(String blobId, String type, Optional<String> name, long size, Optional<String> cid, boolean isInline, Optional<Long> width, Optional<Long> height) { + @VisibleForTesting Attachment(BlobId blobId, String type, Optional<String> name, long size, Optional<String> cid, boolean isInline, Optional<Long> width, Optional<Long> height) { this.blobId = blobId; this.type = type; this.name = name; @@ -115,7 +115,7 @@ public class Attachment { this.height = height; } - public String getBlobId() { + public BlobId getBlobId() { return blobId; } http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/BlobId.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/BlobId.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/BlobId.java new file mode 100644 index 0000000..578c09f --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/BlobId.java @@ -0,0 +1,58 @@ +/**************************************************************** + * 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.jmap.model; + +import java.util.Objects; + +import com.fasterxml.jackson.annotation.JsonValue; +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; + +public class BlobId { + + public static BlobId of(String rawValue) { + Preconditions.checkArgument(!Strings.isNullOrEmpty(rawValue), "'rawValue' is mandatory"); + return new BlobId(rawValue); + } + + private final String rawValue; + + private BlobId(String rawValue) { + this.rawValue = rawValue; + } + + @JsonValue + public String getRawValue() { + return rawValue; + } + + @Override + public final boolean equals(Object obj) { + if (obj instanceof BlobId) { + BlobId other = (BlobId) obj; + return Objects.equals(this.rawValue, other.rawValue); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hashCode(this.rawValue); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java index 94b8517..2121843 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Message.java @@ -48,7 +48,7 @@ public class Message { @JsonPOJOBuilder(withPrefix = "") public static class Builder { private MessageId id; - private String blobId; + private BlobId blobId; private String threadId; private ImmutableList<String> mailboxIds; private String inReplyToMessageId; @@ -69,7 +69,7 @@ public class Message { private String textBody; private String htmlBody; private final ImmutableList.Builder<Attachment> attachments; - private final ImmutableMap.Builder<String, SubMessage> attachedMessages; + private final ImmutableMap.Builder<BlobId, SubMessage> attachedMessages; private Builder() { to = ImmutableList.builder(); @@ -85,7 +85,7 @@ public class Message { return this; } - public Builder blobId(String blobId) { + public Builder blobId(BlobId blobId) { this.blobId = blobId; return this; } @@ -194,14 +194,14 @@ public class Message { return this; } - public Builder attachedMessages(Map<String, SubMessage> attachedMessages) { + public Builder attachedMessages(Map<BlobId, SubMessage> attachedMessages) { this.attachedMessages.putAll(attachedMessages); return this; } public Message build() { Preconditions.checkState(id != null, "'id' is mandatory"); - Preconditions.checkState(!Strings.isNullOrEmpty(blobId), "'blobId' is mandatory"); + Preconditions.checkState(blobId != null, "'blobId' is mandatory"); Preconditions.checkState(!Strings.isNullOrEmpty(threadId), "'threadId' is mandatory"); Preconditions.checkState(mailboxIds != null, "'mailboxIds' is mandatory"); Preconditions.checkState(headers != null, "'headers' is mandatory"); @@ -210,7 +210,7 @@ public class Message { Preconditions.checkState(date != null, "'date' is mandatory"); Preconditions.checkState(!Strings.isNullOrEmpty(preview), "'preview' is mandatory"); ImmutableList<Attachment> attachments = this.attachments.build(); - ImmutableMap<String, SubMessage> attachedMessages = this.attachedMessages.build(); + ImmutableMap<BlobId, SubMessage> attachedMessages = this.attachedMessages.build(); Preconditions.checkState(areAttachedMessagesKeysInAttachments(attachments, attachedMessages), "'attachedMessages' keys must be in 'attachements'"); boolean hasAttachment = !attachments.isEmpty(); @@ -219,12 +219,12 @@ public class Message { } } - protected static boolean areAttachedMessagesKeysInAttachments(ImmutableList<Attachment> attachments, ImmutableMap<String, SubMessage> attachedMessages) { + protected static boolean areAttachedMessagesKeysInAttachments(ImmutableList<Attachment> attachments, ImmutableMap<BlobId, SubMessage> attachedMessages) { return attachedMessages.isEmpty() || attachedMessages.keySet().stream() .anyMatch(inAttachments(attachments)); } - private static Predicate<String> inAttachments(ImmutableList<Attachment> attachments) { + private static Predicate<BlobId> inAttachments(ImmutableList<Attachment> attachments) { return (key) -> { return attachments.stream() .map(Attachment::getBlobId) @@ -233,7 +233,7 @@ public class Message { } private final MessageId id; - private final String blobId; + private final BlobId blobId; private final String threadId; private final ImmutableList<String> mailboxIds; private final Optional<String> inReplyToMessageId; @@ -256,11 +256,11 @@ public class Message { private final Optional<String> textBody; private final Optional<String> htmlBody; private final ImmutableList<Attachment> attachments; - private final ImmutableMap<String, SubMessage> attachedMessages; + private final ImmutableMap<BlobId, SubMessage> attachedMessages; - @VisibleForTesting Message(MessageId id, String blobId, String threadId, ImmutableList<String> mailboxIds, Optional<String> inReplyToMessageId, boolean isUnread, boolean isFlagged, boolean isAnswered, boolean isDraft, boolean hasAttachment, ImmutableMap<String, String> headers, Optional<Emailer> from, + @VisibleForTesting Message(MessageId id, BlobId blobId, String threadId, ImmutableList<String> mailboxIds, Optional<String> inReplyToMessageId, boolean isUnread, boolean isFlagged, boolean isAnswered, boolean isDraft, boolean hasAttachment, ImmutableMap<String, String> headers, Optional<Emailer> from, ImmutableList<Emailer> to, ImmutableList<Emailer> cc, ImmutableList<Emailer> bcc, ImmutableList<Emailer> replyTo, String subject, ZonedDateTime date, long size, String preview, Optional<String> textBody, Optional<String> htmlBody, ImmutableList<Attachment> attachments, - ImmutableMap<String, SubMessage> attachedMessages) { + ImmutableMap<BlobId, SubMessage> attachedMessages) { this.id = id; this.blobId = blobId; this.threadId = threadId; @@ -291,7 +291,7 @@ public class Message { return id; } - public String getBlobId() { + public BlobId getBlobId() { return blobId; } @@ -379,7 +379,7 @@ public class Message { return attachments; } - public ImmutableMap<String, SubMessage> getAttachedMessages() { + public ImmutableMap<BlobId, SubMessage> getAttachedMessages() { return attachedMessages; } http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java index a430627..d23215e 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java @@ -62,7 +62,7 @@ public class MessageFactory { MessageId messageId = uidToMessageId.apply(im.getId()); return Message.builder() .id(messageId) - .blobId(String.valueOf(im.getId())) + .blobId(BlobId.of(String.valueOf(im.getId()))) .threadId(messageId.serialize()) .mailboxIds(ImmutableList.of(im.getMailboxId())) .inReplyToMessageId(getHeaderAsSingleValue(im, "in-reply-to")) @@ -159,7 +159,7 @@ public class MessageFactory { private Attachment fromMailboxAttachment(MessageAttachment attachment) { return Attachment.builder() - .blobId(attachment.getAttachmentId().getId()) + .blobId(BlobId.of(attachment.getAttachmentId().getId())) .type(attachment.getAttachment().getType()) .size(attachment.getAttachment().getSize()) .name(attachment.getName().orNull()) http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SubMessage.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SubMessage.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SubMessage.java index 38e68a9..cbaf1cd 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SubMessage.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SubMessage.java @@ -52,7 +52,7 @@ public class SubMessage { private String textBody; private String htmlBody; private final ImmutableList.Builder<Attachment> attachments; - private final ImmutableMap.Builder<String, SubMessage> attachedMessages; + private final ImmutableMap.Builder<BlobId, SubMessage> attachedMessages; private Builder() { to = ImmutableList.builder(); @@ -118,7 +118,7 @@ public class SubMessage { return this; } - public Builder attachedMessages(Map<String, SubMessage> attachedMessages) { + public Builder attachedMessages(Map<BlobId, SubMessage> attachedMessages) { this.attachedMessages.putAll(attachedMessages); return this; } @@ -128,7 +128,7 @@ public class SubMessage { Preconditions.checkState(!Strings.isNullOrEmpty(subject), "'subject' is mandatory"); Preconditions.checkState(date != null, "'date' is mandatory"); ImmutableList<Attachment> attachments = this.attachments.build(); - ImmutableMap<String, SubMessage> attachedMessages = this.attachedMessages.build(); + ImmutableMap<BlobId, SubMessage> attachedMessages = this.attachedMessages.build(); Preconditions.checkState(Message.areAttachedMessagesKeysInAttachments(attachments, attachedMessages), "'attachedMessages' keys must be in 'attachements'"); return new SubMessage(headers, Optional.ofNullable(from), to.build(), cc.build(), bcc.build(), replyTo.build(), subject, date, Optional.ofNullable(textBody), Optional.ofNullable(htmlBody), @@ -148,10 +148,10 @@ public class SubMessage { private final Optional<String> textBody; private final Optional<String> htmlBody; private final ImmutableList<Attachment> attachments; - private final ImmutableMap<String, SubMessage> attachedMessages; + private final ImmutableMap<BlobId, SubMessage> attachedMessages; @VisibleForTesting SubMessage(ImmutableMap<String, String> headers, Optional<Emailer> from, ImmutableList<Emailer> to, ImmutableList<Emailer> cc, ImmutableList<Emailer> bcc, ImmutableList<Emailer> replyTo, String subject, ZonedDateTime date, Optional<String> textBody, - Optional<String> htmlBody, ImmutableList<Attachment> attachments, ImmutableMap<String, SubMessage> attachedMessages) { + Optional<String> htmlBody, ImmutableList<Attachment> attachments, ImmutableMap<BlobId, SubMessage> attachedMessages) { super(); this.headers = headers; this.from = from; @@ -211,7 +211,7 @@ public class SubMessage { return attachments; } - public ImmutableMap<String, SubMessage> getAttachedMessages() { + public ImmutableMap<BlobId, SubMessage> getAttachedMessages() { return attachedMessages; } http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java index b0ea677..7723d8a 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java @@ -22,6 +22,7 @@ package org.apache.james.jmap.json; import java.time.ZoneId; import java.time.ZonedDateTime; +import org.apache.james.jmap.model.BlobId; import org.apache.james.jmap.model.Emailer; import org.apache.james.jmap.model.Message; import org.apache.james.jmap.model.MessageId; @@ -34,7 +35,7 @@ public interface ParsingWritingObjects { public interface Common { MessageId MESSAGE_ID = MessageId.of("username|mailbox|1"); - String BLOB_ID = "myBlobId"; + BlobId BLOB_ID = BlobId.of("myBlobId"); String THREAD_ID = "myThreadId"; ImmutableList<String> MAILBOX_IDS = ImmutableList.of("mailboxId1", "mailboxId2"); String IN_REPLY_TO_MESSAGE_ID = "myInReplyToMessageId"; http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java index 7f32174..12eba05 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java @@ -34,6 +34,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; import org.apache.james.jmap.methods.ValueWithId.MessageWithId; +import org.apache.james.jmap.model.BlobId; import org.apache.james.jmap.model.CreationMessage; import org.apache.james.jmap.model.CreationMessage.DraftEmailer; import org.apache.james.jmap.model.CreationMessageId; @@ -89,7 +90,7 @@ public class SetMessagesCreationProcessorTest { private static final Message FAKE_OUTBOX_MESSAGE = Message.builder() .id(MessageId.of(OUTBOX_MESSAGE_ID)) - .blobId("anything") + .blobId(BlobId.of("anything")) .threadId("anything") .mailboxId(OUTBOX_ID.serialize()) .headers(ImmutableMap.of()) http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java index 92b3194..c6a433a 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java @@ -33,34 +33,29 @@ public class AttachmentTest { @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenTypeIsNull() { - Attachment.builder().blobId("blobId").build(); + Attachment.builder().blobId(BlobId.of("blobId")).build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenNameIsNull() { - Attachment.builder().blobId("blobId").type("type").build(); + Attachment.builder().blobId(BlobId.of("blobId")).type("type").build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenSizeIsNull() { - Attachment.builder().blobId("blobId").type("type").name("name").build(); - } - - @Test(expected=IllegalStateException.class) - public void buildShouldThrowWhenBlobIdIsEmpty() { - Attachment.builder().blobId("").type("type").name("name").size(123).build(); + Attachment.builder().blobId(BlobId.of("blobId")).type("type").name("name").build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenTypeIsEmpty() { - Attachment.builder().blobId("blobId").type("").name("name").size(123).build(); + Attachment.builder().blobId(BlobId.of("blobId")).type("").name("name").size(123).build(); } @Test public void buildShouldWorkWhenMandatoryFieldsArePresent() { - Attachment expected = new Attachment("blobId", "type", Optional.empty(), 123, Optional.empty(), false, Optional.empty(), Optional.empty()); + Attachment expected = new Attachment(BlobId.of("blobId"), "type", Optional.empty(), 123, Optional.empty(), false, Optional.empty(), Optional.empty()); Attachment tested = Attachment.builder() - .blobId("blobId") + .blobId(BlobId.of("blobId")) .type("type") .size(123) .build(); @@ -69,9 +64,9 @@ public class AttachmentTest { @Test public void buildShouldWorkWithAllFieldsSet() { - Attachment expected = new Attachment("blobId", "type", Optional.of("name"), 123, Optional.of("cid"), true, Optional.of(456L), Optional.of(789L)); + Attachment expected = new Attachment(BlobId.of("blobId"), "type", Optional.of("name"), 123, Optional.of("cid"), true, Optional.of(456L), Optional.of(789L)); Attachment tested = Attachment.builder() - .blobId("blobId") + .blobId(BlobId.of("blobId")) .type("type") .name("name") .size(123) http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/BlobIdTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/BlobIdTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/BlobIdTest.java new file mode 100644 index 0000000..bf04a1e --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/BlobIdTest.java @@ -0,0 +1,49 @@ +/**************************************************************** + * 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.jmap.model; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +public class BlobIdTest { + + @Test + public void shouldNotAllowEmptyString() { + assertThatThrownBy(() -> BlobId.of("")).isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void shouldNotAllowNullInput() { + assertThatThrownBy(() -> BlobId.of(null)).isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void shouldCreateInstanceWhenSimpleString() { + assertThat(BlobId.of("simple string")).extracting(BlobId::getRawValue).containsExactly("simple string"); + } + + @Test + public void shouldRespectJavaBeanContract() { + EqualsVerifier.forClass(BlobId.class).verify(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java index b11edcf..0293808 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java @@ -73,73 +73,68 @@ public class MailboxMessageTest { } @Test(expected=IllegalStateException.class) - public void buildShouldThrowWhenBlobIdIsEmpty() { - Message.builder().id(MessageId.of("user|box|1")).blobId("").build(); - } - - @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenThreadIdIsNull() { - Message.builder().id(MessageId.of("user|box|1")).blobId("blobId").build(); + Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenThreadIdIsEmpty() { - Message.builder().id(MessageId.of("user|box|1")).blobId("blobId").threadId("").build(); + Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("").build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenMailboxIdsIsNull() { - Message.builder().id(MessageId.of("user|box|1")).blobId("blobId").threadId("threadId").build(); + Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenHeadersIsNull() { - Message.builder().id(MessageId.of("user|box|1")).blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).build(); + Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenSubjectIsNull() { - Message.builder().id(MessageId.of("user|box|1")).blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()).build(); + Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()).build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenSubjectIsEmpty() { - Message.builder().id(MessageId.of("user|box|1")).blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()) + Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()) .subject("").build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenSizeIsNull() { - Message.builder().id(MessageId.of("user|box|1")).blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()) + Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()) .subject("subject").build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenDateIsNull() { - Message.builder().id(MessageId.of("user|box|1")).blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()) + Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()) .subject("subject").size(123).build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenPreviewIsNull() { - Message.builder().id(MessageId.of("user|box|1")).blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()) + Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()) .subject("subject").size(123).date(ZonedDateTime.now()).build(); } @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenPreviewIsEmpty() { - Message.builder().id(MessageId.of("user|box|1")).blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()) + Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()) .subject("subject").size(123).date(ZonedDateTime.now()).preview("").build(); } @Test public void buildShouldWorkWhenMandatoryFieldsArePresent() { ZonedDateTime currentDate = ZonedDateTime.now(); - Message expected = new Message(MessageId.of("user|box|1"), "blobId", "threadId", ImmutableList.of("mailboxId"), Optional.empty(), false, false, false, false, false, ImmutableMap.of("key", "value"), Optional.empty(), + Message expected = new Message(MessageId.of("user|box|1"), BlobId.of("blobId"), "threadId", ImmutableList.of("mailboxId"), Optional.empty(), false, false, false, false, false, ImmutableMap.of("key", "value"), Optional.empty(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), "subject", currentDate, 123, "preview", Optional.empty(), Optional.empty(), ImmutableList.of(), ImmutableMap.of()); Message tested = Message.builder() .id(MessageId.of("user|box|1")) - .blobId("blobId") + .blobId(BlobId.of("blobId")) .threadId("threadId") .mailboxIds(ImmutableList.of("mailboxId")) .headers(ImmutableMap.of("key", "value")) @@ -153,17 +148,17 @@ public class MailboxMessageTest { @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenAttachedMessageIsNotMatchingAttachments() { - Attachment simpleAttachment = Attachment.builder().blobId("blobId").type("type").name("name").size(123).build(); + Attachment simpleAttachment = Attachment.builder().blobId(BlobId.of("blobId")).type("type").name("name").size(123).build(); ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment); SubMessage simpleMessage = SubMessage.builder() .headers(ImmutableMap.of("key", "value")) .subject("subject") .date(ZonedDateTime.now()) .build(); - ImmutableMap<String, SubMessage> attachedMessages = ImmutableMap.of("differentBlobId", simpleMessage); + ImmutableMap<BlobId, SubMessage> attachedMessages = ImmutableMap.of(BlobId.of("differentBlobId"), simpleMessage); Message.builder() .id(MessageId.of("user|box|1")) - .blobId("blobId") + .blobId(BlobId.of("blobId")) .threadId("threadId") .mailboxIds(ImmutableList.of("mailboxId")) .headers(ImmutableMap.of("key", "value")) @@ -184,17 +179,17 @@ public class MailboxMessageTest { ImmutableList<Emailer> bcc = ImmutableList.of(Emailer.builder().name("bcc").email("bcc@domain").build()); ImmutableList<Emailer> replyTo = ImmutableList.of(Emailer.builder().name("replyTo").email("replyTo@domain").build()); ZonedDateTime currentDate = ZonedDateTime.now(); - Attachment simpleAttachment = Attachment.builder().blobId("blobId").type("type").name("name").size(123).build(); + Attachment simpleAttachment = Attachment.builder().blobId(BlobId.of("blobId")).type("type").name("name").size(123).build(); ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment); SubMessage simpleMessage = SubMessage.builder() .headers(ImmutableMap.of("key", "value")) .subject("subject") .date(currentDate) .build(); - ImmutableMap<String, SubMessage> attachedMessages = ImmutableMap.of("blobId", simpleMessage); + ImmutableMap<BlobId, SubMessage> attachedMessages = ImmutableMap.of(BlobId.of("blobId"), simpleMessage); Message expected = new Message( MessageId.of("user|box|1"), - "blobId", + BlobId.of("blobId"), "threadId", ImmutableList.of("mailboxId"), Optional.of("inReplyToMessageId"), @@ -219,7 +214,7 @@ public class MailboxMessageTest { attachedMessages); Message tested = Message.builder() .id(MessageId.of("user|box|1")) - .blobId("blobId") + .blobId(BlobId.of("blobId")) .threadId("threadId") .mailboxIds(ImmutableList.of("mailboxId")) .inReplyToMessageId("inReplyToMessageId") @@ -322,7 +317,7 @@ public class MailboxMessageTest { Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x)); Message expected = Message.builder() .id(MessageId.of("user|box|0")) - .blobId("0") + .blobId(BlobId.of("0")) .threadId("user|box|0") .mailboxIds(ImmutableList.of(MAILBOX_ID.serialize())) .inReplyToMessageId("<snt124-w2664003139c1e520cf4f6787...@phx.gbl>") @@ -411,7 +406,7 @@ public class MailboxMessageTest { testMail.setModSeq(MOD_SEQ); String payload = "payload"; - String blodId = "id1"; + BlobId blodId = BlobId.of("id1"); String type = "content"; Attachment expectedAttachment = Attachment.builder() .blobId(blodId) @@ -423,7 +418,7 @@ public class MailboxMessageTest { Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(MessageAttachment.builder() .attachment(org.apache.james.mailbox.store.mail.model.Attachment.builder() - .attachmentId(AttachmentId.from(blodId)) + .attachmentId(AttachmentId.from(blodId.getRawValue())) .bytes(payload.getBytes()) .type(type) .build()) @@ -440,7 +435,7 @@ public class MailboxMessageTest { public void buildShouldThrowWhenOneAttachedMessageIsNotInAttachments() throws Exception { Message.builder() .id(MessageId.of("user|box|1")) - .blobId("blodId") + .blobId(BlobId.of("blobId")) .threadId("threadId") .mailboxIds(ImmutableList.of("mailboxId")) .headers(ImmutableMap.of("key", "value")) @@ -448,7 +443,7 @@ public class MailboxMessageTest { .size(1) .date(ZonedDateTime.now()) .preview("preview") - .attachedMessages(ImmutableMap.of("key", SubMessage.builder() + .attachedMessages(ImmutableMap.of(BlobId.of("key"), SubMessage.builder() .headers(ImmutableMap.of("key", "value")) .subject("subject") .date(ZonedDateTime.now()) @@ -460,7 +455,7 @@ public class MailboxMessageTest { public void buildShouldNotThrowWhenOneAttachedMessageIsInAttachments() throws Exception { Message.builder() .id(MessageId.of("user|box|1")) - .blobId("blodId") + .blobId(BlobId.of("blobId")) .threadId("threadId") .mailboxIds(ImmutableList.of("mailboxId")) .headers(ImmutableMap.of("key", "value")) @@ -469,11 +464,11 @@ public class MailboxMessageTest { .date(ZonedDateTime.now()) .preview("preview") .attachments(ImmutableList.of(Attachment.builder() - .blobId("key") + .blobId(BlobId.of("key")) .size(1) .type("type") .build())) - .attachedMessages(ImmutableMap.of("key", SubMessage.builder() + .attachedMessages(ImmutableMap.of(BlobId.of("key"), SubMessage.builder() .headers(ImmutableMap.of("key", "value")) .subject("subject") .date(ZonedDateTime.now()) http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java index 631fa96..24402a9 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java @@ -56,7 +56,7 @@ public class SetMessagesResponseTest { ImmutableMap<CreationMessageId, Message> created = ImmutableMap.of(CreationMessageId.of("user|created|1"), Message.builder() .id(MessageId.of("user|created|1")) - .blobId("blobId") + .blobId(BlobId.of("blobId")) .threadId("threadId") .mailboxIds(ImmutableList.of("mailboxId")) .headers(ImmutableMap.of("key", "value")) @@ -106,7 +106,7 @@ public class SetMessagesResponseTest { private ImmutableMap<CreationMessageId, Message> buildMessage(CreationMessageId messageId) { return ImmutableMap.of(messageId, Message.builder() .id(MessageId.of(messageId.getId())) - .blobId("blobId") + .blobId(BlobId.of("blobId")) .threadId("threadId") .mailboxIds(ImmutableList.of()) .headers(ImmutableMap.of()) http://git-wip-us.apache.org/repos/asf/james-project/blob/7be2166e/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SubMailboxMessageTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SubMailboxMessageTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SubMailboxMessageTest.java index dc0ada9..daa2a8a 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SubMailboxMessageTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SubMailboxMessageTest.java @@ -64,14 +64,14 @@ public class SubMailboxMessageTest { @Test(expected=IllegalStateException.class) public void buildShouldThrowWhenAttachedMessageIsNotMatchingAttachments() { - Attachment simpleAttachment = Attachment.builder().blobId("blobId").type("type").name("name").size(123).build(); + Attachment simpleAttachment = Attachment.builder().blobId(BlobId.of("blobId")).type("type").name("name").size(123).build(); ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment); SubMessage simpleMessage = SubMessage.builder() .headers(ImmutableMap.of("key", "value")) .subject("subject") .date(ZonedDateTime.now()) .build(); - ImmutableMap<String, SubMessage> attachedMessages = ImmutableMap.of("differentBlobId", simpleMessage); + ImmutableMap<BlobId, SubMessage> attachedMessages = ImmutableMap.of(BlobId.of("differentBlobId"), simpleMessage); SubMessage.builder() .headers(ImmutableMap.of("key", "value")) .subject("subject") @@ -89,14 +89,14 @@ public class SubMailboxMessageTest { ImmutableList<Emailer> bcc = ImmutableList.of(Emailer.builder().name("bcc").email("bcc@domain").build()); ImmutableList<Emailer> replyTo = ImmutableList.of(Emailer.builder().name("replyTo").email("replyTo@domain").build()); ZonedDateTime currentDate = ZonedDateTime.now(); - Attachment simpleAttachment = Attachment.builder().blobId("blobId").type("type").name("name").size(123).build(); + Attachment simpleAttachment = Attachment.builder().blobId(BlobId.of("blobId")).type("type").name("name").size(123).build(); ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment); SubMessage simpleMessage = SubMessage.builder() .headers(ImmutableMap.of("key", "value")) .subject("subject") .date(currentDate) .build(); - ImmutableMap<String, SubMessage> attachedMessages = ImmutableMap.of("blobId", simpleMessage); + ImmutableMap<BlobId, SubMessage> attachedMessages = ImmutableMap.of(BlobId.of("blobId"), simpleMessage); SubMessage expected = new SubMessage( ImmutableMap.of("key", "value"), Optional.of(from), --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org