You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/12/06 02:34:31 UTC
[james-project] 21/21: JAMES-2991 Add tests for hasAttachment
compute property
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 86ca49225c0e0165b539f20a799cd0cfdab56595
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Wed Dec 4 11:15:55 2019 +0700
JAMES-2991 Add tests for hasAttachment compute property
---
.../apache/james/jmap/draft/model/PreviewDTO.java | 3 +-
...mputeMessageFastViewProjectionListenerTest.java | 61 ++++++++++++++++------
.../emptyBodyMessageWithOneAttachment.eml | 52 ++++++++++++++++++
3 files changed, 99 insertions(+), 17 deletions(-)
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/PreviewDTO.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/PreviewDTO.java
index 2c2eb08..0cea9b4 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/PreviewDTO.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/PreviewDTO.java
@@ -32,7 +32,8 @@ import com.google.common.base.Preconditions;
public class PreviewDTO {
private static final String NO_BODY_AS_STRING = "(Empty)";
- private static final PreviewDTO NO_BODY = PreviewDTO.of(NO_BODY_AS_STRING);
+
+ public static final PreviewDTO NO_BODY = PreviewDTO.of(NO_BODY_AS_STRING);
public static PreviewDTO from(Optional<Preview> preview) {
return preview.map(Preview::getValue)
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListenerTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListenerTest.java
index 51f2858..e407db8 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListenerTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/ComputeMessageFastViewProjectionListenerTest.java
@@ -26,13 +26,11 @@ import static org.mockito.Mockito.spy;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.util.Optional;
import org.apache.james.core.Username;
import org.apache.james.jmap.api.model.Preview;
import org.apache.james.jmap.api.projections.MessageFastViewPrecomputedProperties;
import org.apache.james.jmap.api.projections.MessageFastViewProjection;
-import org.apache.james.jmap.draft.model.PreviewDTO;
import org.apache.james.jmap.draft.model.message.view.MessageFullViewFactory;
import org.apache.james.jmap.draft.utils.JsoupHtmlTextExtractor;
import org.apache.james.jmap.memory.projections.MemoryMessageFastViewProjection;
@@ -59,6 +57,7 @@ import org.apache.james.mailbox.store.SessionProviderImpl;
import org.apache.james.mailbox.store.StoreMailboxManager;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.apache.james.mime4j.dom.Message;
+import org.apache.james.util.ClassLoaderUtils;
import org.apache.james.util.html.HtmlTextExtractor;
import org.apache.james.util.mime.MessageContentExtractor;
import org.assertj.core.api.SoftAssertions;
@@ -69,17 +68,25 @@ import reactor.core.publisher.Mono;
class ComputeMessageFastViewProjectionListenerTest {
private static final Username BOB = Username.of("bob");
- private static final Preview PREVIEW = Preview.from("This should be the preview of the message...");
+ private static final Preview PREVIEW = Preview.from("blabla bloblo");
private static final MailboxPath BOB_INBOX_PATH = MailboxPath.inbox(BOB);
private static final MailboxPath BOB_OTHER_BOX_PATH = MailboxPath.forUser(BOB, "otherBox");
- private static final MessageFastViewPrecomputedProperties MESSAGE_FAST_VIEW_PRECOMPUTED_PROPERTIES = MessageFastViewPrecomputedProperties.builder()
+ private static final MessageFastViewPrecomputedProperties PRECOMPUTED_PROPERTIES_PREVIEW = MessageFastViewPrecomputedProperties.builder()
.preview(PREVIEW)
.noAttachments()
.build();
- private static final MessageFastViewPrecomputedProperties MESSAGE_FAST_VIEW_PRECOMPUTED_PROPERTIES_EMPTY = MessageFastViewPrecomputedProperties.builder()
- .preview(Preview.from(PreviewDTO.from(Optional.empty()).getValue()))
+ private static final MessageFastViewPrecomputedProperties PRECOMPUTED_PROPERTIES_EMPTY = MessageFastViewPrecomputedProperties.builder()
+ .preview(Preview.from(""))
.noAttachments()
.build();
+ private static final MessageFastViewPrecomputedProperties PRECOMPUTED_PROPERTIES_PREVIEW_HAS_ATTACHMENT = MessageFastViewPrecomputedProperties.builder()
+ .preview(PREVIEW)
+ .hasAttachment()
+ .build();
+ private static final MessageFastViewPrecomputedProperties PRECOMPUTED_PROPERTIES_HAS_ATTACHMENT = MessageFastViewPrecomputedProperties.builder()
+ .preview(Preview.from(""))
+ .hasAttachment()
+ .build();
MessageFastViewProjection messageFastViewProjection;
MessageFullViewFactory messageFullViewFactory;
@@ -109,12 +116,12 @@ class ComputeMessageFastViewProjectionListenerTest {
mailboxManager = resources.getMailboxManager();
messageIdManager = spy(resources.getMessageIdManager());
- messageFastViewProjection = new MemoryMessageFastViewProjection();
+ messageFastViewProjection = new MemoryMessageFastViewProjection(new NoopMetricFactory());
MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
HtmlTextExtractor htmlTextExtractor = new JsoupHtmlTextExtractor();
- messageFullViewFactory = new MessageFullViewFactory(resources.getBlobManager(), messageContentExtractor, htmlTextExtractor);
+ messageFullViewFactory = new MessageFullViewFactory(resources.getBlobManager(), messageContentExtractor, htmlTextExtractor, messageIdManager, messageFastViewProjection);
FakeAuthenticator authenticator = new FakeAuthenticator();
authenticator.addUser(BOB, "12345");
@@ -142,25 +149,47 @@ class ComputeMessageFastViewProjectionListenerTest {
}
@Test
- void shouldStorePreviewWhenBodyMessageNotEmpty() throws Exception {
+ void shouldStorePreviewWithNoAttachmentsWhenBodyMessageNotEmptyAndNoAttachments() throws Exception {
ComposedMessageId composedId = inboxMessageManager.appendMessage(
MessageManager.AppendCommand.builder()
.build(previewMessage()),
mailboxSession);
assertThat(Mono.from(messageFastViewProjection.retrieve(composedId.getMessageId())).block())
- .isEqualTo(MESSAGE_FAST_VIEW_PRECOMPUTED_PROPERTIES);
+ .isEqualTo(PRECOMPUTED_PROPERTIES_PREVIEW);
}
@Test
- void shouldStoreEmptyPreviewWhenEmptyBodyMessage() throws Exception {
+ void shouldStoreEmptyPreviewWithNoAttachmentsWhenEmptyBodyMessageAndNoAttachments() throws Exception {
ComposedMessageId composedId = inboxMessageManager.appendMessage(
MessageManager.AppendCommand.builder()
.build(emptyMessage()),
mailboxSession);
assertThat(Mono.from(messageFastViewProjection.retrieve(composedId.getMessageId())).block())
- .isEqualTo(MESSAGE_FAST_VIEW_PRECOMPUTED_PROPERTIES_EMPTY);
+ .isEqualTo(PRECOMPUTED_PROPERTIES_EMPTY);
+ }
+
+ @Test
+ void shouldStorePreviewWithHasAttachmentWhenBodyMessageNotEmptyAndHasAttachment() throws Exception {
+ ComposedMessageId composedId = inboxMessageManager.appendMessage(
+ MessageManager.AppendCommand.builder()
+ .build(ClassLoaderUtils.getSystemResourceAsSharedStream("fullMessage.eml")),
+ mailboxSession);
+
+ assertThat(Mono.from(messageFastViewProjection.retrieve(composedId.getMessageId())).block())
+ .isEqualTo(PRECOMPUTED_PROPERTIES_PREVIEW_HAS_ATTACHMENT);
+ }
+
+ @Test
+ void shouldStoreEmptyPreviewWithHasAttachmentWhenEmptyBodyMessageAndHasAttachment() throws Exception {
+ ComposedMessageId composedId = inboxMessageManager.appendMessage(
+ MessageManager.AppendCommand.builder()
+ .build(ClassLoaderUtils.getSystemResourceAsSharedStream("emptyBodyMessageWithOneAttachment.eml")),
+ mailboxSession);
+
+ assertThat(Mono.from(messageFastViewProjection.retrieve(composedId.getMessageId())).block())
+ .isEqualTo(PRECOMPUTED_PROPERTIES_HAS_ATTACHMENT);
}
@Test
@@ -177,9 +206,9 @@ class ComputeMessageFastViewProjectionListenerTest {
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(Mono.from(messageFastViewProjection.retrieve(composedId1.getMessageId())).block())
- .isEqualTo(MESSAGE_FAST_VIEW_PRECOMPUTED_PROPERTIES);
+ .isEqualTo(PRECOMPUTED_PROPERTIES_PREVIEW);
softly.assertThat(Mono.from(messageFastViewProjection.retrieve(composedId2.getMessageId())).block())
- .isEqualTo(MESSAGE_FAST_VIEW_PRECOMPUTED_PROPERTIES_EMPTY);
+ .isEqualTo(PRECOMPUTED_PROPERTIES_EMPTY);
});
}
@@ -194,7 +223,7 @@ class ComputeMessageFastViewProjectionListenerTest {
MessageResult result = otherBoxMessageManager.getMessages(MessageRange.all(), FetchGroup.MINIMAL, mailboxSession).next();
assertThat(Mono.from(messageFastViewProjection.retrieve(result.getMessageId())).block())
- .isEqualTo(MESSAGE_FAST_VIEW_PRECOMPUTED_PROPERTIES);
+ .isEqualTo(PRECOMPUTED_PROPERTIES_PREVIEW);
}
@Test
@@ -208,7 +237,7 @@ class ComputeMessageFastViewProjectionListenerTest {
MessageResult result = otherBoxMessageManager.getMessages(MessageRange.all(), FetchGroup.MINIMAL, mailboxSession).next();
assertThat(Mono.from(messageFastViewProjection.retrieve(result.getMessageId())).block())
- .isEqualTo(MESSAGE_FAST_VIEW_PRECOMPUTED_PROPERTIES);
+ .isEqualTo(PRECOMPUTED_PROPERTIES_PREVIEW);
}
@Test
diff --git a/server/protocols/jmap-draft/src/test/resources/emptyBodyMessageWithOneAttachment.eml b/server/protocols/jmap-draft/src/test/resources/emptyBodyMessageWithOneAttachment.eml
new file mode 100644
index 0000000..125151c
--- /dev/null
+++ b/server/protocols/jmap-draft/src/test/resources/emptyBodyMessageWithOneAttachment.eml
@@ -0,0 +1,52 @@
+Reply-to: alice <al...@local>
+In-reply-to: bob@local
+Mime-Version: 1.0
+To: bob <bo...@local>
+From: alice <al...@local>
+Cc: jack <ja...@local>, jacob <ja...@local>
+Bcc: alice <al...@local>
+Subject: Full message
+Message-ID: <1c...@open-paas.org>
+Date: Tue, 7 Jun 2016 16:23:37 +0200
+Content-Type: multipart/mixed;
+ boundary="------------7AF1D14DE1DFA16229726B54"
+
+This is a multi-part message in MIME format.
+--------------7AF1D14DE1DFA16229726B54
+Content-Type: multipart/alternative;
+ boundary="------------172F9470CFA3BF3417835D92"
+
+
+--------------172F9470CFA3BF3417835D92
+Content-Type: text/plain; charset=utf-8; format=flowed
+Content-Transfer-Encoding: 7bit
+
+
+
+--------------172F9470CFA3BF3417835D92--
+
+--------------7AF1D14DE1DFA16229726B54
+Content-Type: image/jpeg;
+ name="4037_014.jpg"
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment;
+ filename="4037_014.jpg"
+
+/9j/4X2cRXhpZgAASUkqAAgAAAANAA8BAgAKAAAAqgAAABABAgAJAAAAtAAAABIBAwABAAAA
+AQAAABoBBQABAAAAvgAAABsBBQABAAAAxgAAACgBAwABAAAAAgAAADEBAgAKAAAAzgAAADIB
+AgAUAAAA2AAAABMCAwABAAAAAgAAAGmHBAABAAAAfAIAAKXEBwDQAAAA7AAAANLGBwBAAAAA
+vAEAANPGBwCAAAAA/AEAAEwqAABQYW5hc29uaWMARE1DLUZaNDUAALQAAAABAAAAtAAAAAEA
+AABWZXIuMS4wICAAMjAxNDowMjoyNSAxMDozMjowOQBQcmludElNADAyNTAAAA4AAQAWABYA
+AgAAAAAAAwBkAAAABwAAAAAACAAAAAAACQAAAAAACgAAAAAACwCsAAAADAAAAAAADQAAAAAA
+DgDEAAAAAAEFAAAAAQEBAAAAEAGAAAAACREAABAnAAALDwAAECcAAJcFAAAQJwAAsAgAABAn
+AAABHAAAECcAAF4CAAAQJwAAiwAAABAnAADLAwAAECcAAOUbAAAQJwAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+--------------7AF1D14DE1DFA16229726B54--
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org