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 rc...@apache.org on 2019/11/29 02:00:26 UTC

[james-project] branch master updated (e8c2f63 -> 4a8cd1a)

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from e8c2f63  JAMES-2988 Use the smallest fetch group possible upon GetMessages
     new 3e94093  JAMES-2989 Preview factory method with the business from PreviewGenerator
     new 9a178a1  JAMES-2989 JMAP Messages carrying a strong typing Preview
     new 06fdadf  JAMES-2989 Replace plain string by strong typing preview
     new 8bf2503  JAMES-2989 drop MessagePreviewGenerator
     new abcb395  JAMES-2989 Move the hardcoded "(Empty)" to the presentation layer
     new 4a8cd1a  JAMES-2996 Errors upon start should be reported to the logging system

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/james/GuiceJamesServer.java    | 23 ++++--
 .../apache/james/jmap/draft/JMAPCommonModule.java  |  2 -
 .../org/apache/james/jmap/api/preview/Preview.java | 12 +++
 .../apache/james/jmap/api/preview/PreviewTest.java | 66 +++++++++++++++
 .../cucumber/GetMessagesMethodStepdefs.java        |  6 +-
 .../jmap/draft/model/MessagePreviewGenerator.java  | 41 ----------
 .../apache/james/jmap/draft/model/PreviewDTO.java} | 38 ++++++---
 .../draft/model/message/view/MessageFullView.java  | 22 +++--
 .../model/message/view/MessageFullViewFactory.java | 10 +--
 .../jmap/draft/json/ParsingWritingObjects.java     |  3 +-
 .../jmap/draft/methods/GetMessagesMethodTest.java  |  4 +-
 .../jmap/draft/methods/MessageSenderTest.java      |  5 +-
 .../methods/SetMessagesCreationProcessorTest.java  |  5 +-
 .../draft/model/MessagePreviewGeneratorTest.java   | 95 ----------------------
 .../james/jmap/draft/model/PreviewDTOTest.java     | 51 ++++++------
 .../jmap/draft/model/SetMessagesResponseTest.java  |  7 +-
 .../message/view/MessageFullViewFactoryTest.java   | 44 +++++-----
 .../model/message/view/MessageFullViewTest.java    | 43 ++++------
 18 files changed, 215 insertions(+), 262 deletions(-)
 delete mode 100644 server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessagePreviewGenerator.java
 copy server/{data/data-jmap/src/main/java/org/apache/james/jmap/api/preview/Preview.java => protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/PreviewDTO.java} (64%)
 delete mode 100644 server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MessagePreviewGeneratorTest.java
 copy mailbox/api/src/test/java/org/apache/james/mailbox/model/search/ExactNameTest.java => server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/PreviewDTOTest.java (56%)


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 03/06: JAMES-2989 Replace plain string by strong typing preview

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 06fdadfbcdcb1ff59ab431637706aa4bf28919be
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Tue Nov 26 11:24:09 2019 +0700

    JAMES-2989 Replace plain string by strong typing preview
---
 .../cucumber/GetMessagesMethodStepdefs.java        |  6 +--
 .../jmap/draft/json/ParsingWritingObjects.java     |  3 +-
 .../jmap/draft/methods/GetMessagesMethodTest.java  |  4 +-
 .../jmap/draft/methods/MessageSenderTest.java      |  5 +--
 .../methods/SetMessagesCreationProcessorTest.java  |  5 +--
 .../jmap/draft/model/SetMessagesResponseTest.java  |  7 +++-
 .../model/message/view/MessageFullViewTest.java    | 43 ++++++++--------------
 7 files changed, 29 insertions(+), 44 deletions(-)

diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/cucumber/GetMessagesMethodStepdefs.java
index 5b3acc3..d694e3e 100644
--- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/cucumber/GetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/cucumber/GetMessagesMethodStepdefs.java
@@ -43,15 +43,14 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.StringEscapeUtils;
 import org.apache.james.core.Username;
 import org.apache.james.jmap.TestingConstants;
+import org.apache.james.jmap.draft.JmapGuiceProbe;
 import org.apache.james.jmap.draft.methods.integration.cucumber.util.TableRow;
-import org.apache.james.jmap.draft.model.MessagePreviewGenerator;
 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.MessageId;
 import org.apache.james.modules.protocols.SmtpGuiceProbe;
 import org.apache.james.util.ClassLoaderUtils;
-import org.apache.james.jmap.draft.JmapGuiceProbe;
 import org.apache.james.utils.SMTPMessageSender;
 import org.javatuples.Pair;
 
@@ -76,6 +75,7 @@ public class GetMessagesMethodStepdefs {
     private static final String ATTACHMENTS = FIRST_MESSAGE + ".attachments";
     private static final String FIRST_ATTACHMENT = ATTACHMENTS + "[0]";
     private static final String SECOND_ATTACHMENT = ATTACHMENTS + "[1]";
+    private static final int PREVIEW_LENGTH = 256;
 
 
     private final MainStepdefs mainStepdefs;
@@ -659,7 +659,7 @@ public class GetMessagesMethodStepdefs {
     @Then("^the preview should not contain consecutive spaces or blank characters$")
     public void assertPreviewShouldBeNormalized() {
         String actual = httpClient.jsonPath.read(FIRST_MESSAGE + ".preview");
-        assertThat(actual).hasSize(MessagePreviewGenerator.MAX_PREVIEW_LENGTH)
+        assertThat(actual).hasSize(PREVIEW_LENGTH)
             .doesNotMatch("  ")
             .doesNotContain(StringUtils.CR)
             .doesNotContain(StringUtils.LF);
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/json/ParsingWritingObjects.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/json/ParsingWritingObjects.java
index 5baa6b4..0f355ff 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/json/ParsingWritingObjects.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/json/ParsingWritingObjects.java
@@ -24,6 +24,7 @@ import java.util.Optional;
 
 import javax.mail.Flags;
 
+import org.apache.james.jmap.api.preview.Preview;
 import org.apache.james.jmap.draft.model.BlobId;
 import org.apache.james.jmap.draft.model.Emailer;
 import org.apache.james.jmap.draft.model.Keyword;
@@ -66,7 +67,7 @@ public interface ParsingWritingObjects {
         String SUBJECT = "mySubject";
         Instant DATE = Instant.parse("2014-10-30T14:12:00Z");
         int SIZE = 1024;
-        String PREVIEW = "myPreview";
+        Preview PREVIEW = Preview.from("myPreview");
         Optional<String> TEXT_BODY = Optional.of("myTextBody");
         Optional<String> HTML_BODY = Optional.of("<h1>myHtmlBody</h1>");
     }
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java
index 420761e..833c8ac 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMessagesMethodTest.java
@@ -40,7 +40,6 @@ import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.core.Username;
 import org.apache.james.jmap.draft.model.GetMessagesRequest;
 import org.apache.james.jmap.draft.model.GetMessagesResponse;
-import org.apache.james.jmap.draft.model.MessagePreviewGenerator;
 import org.apache.james.jmap.draft.model.MessageProperties.MessageProperty;
 import org.apache.james.jmap.draft.model.MethodCallId;
 import org.apache.james.jmap.draft.model.message.view.MessageFullView;
@@ -107,13 +106,12 @@ public class GetMessagesMethodTest {
     public void setup() throws Exception {
         methodCallId = MethodCallId.of("#0");
         HtmlTextExtractor htmlTextExtractor = new JsoupHtmlTextExtractor();
-        MessagePreviewGenerator messagePreview = new MessagePreviewGenerator();
         MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
         BlobManager blobManager = mock(BlobManager.class);
         when(blobManager.toBlobId(any(MessageId.class))).thenReturn(BlobId.fromString("fake"));
         messageMetadataViewFactory = spy(new MessageMetadataViewFactory(blobManager));
         MetaMessageViewFactory metaMessageViewFactory = new MetaMessageViewFactory(
-            new MessageFullViewFactory(blobManager, messagePreview, messageContentExtractor, htmlTextExtractor),
+            new MessageFullViewFactory(blobManager, messageContentExtractor, htmlTextExtractor),
             new MessageHeaderViewFactory(blobManager),
             messageMetadataViewFactory);
 
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MessageSenderTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MessageSenderTest.java
index 4316a7f..fe2615d 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MessageSenderTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MessageSenderTest.java
@@ -36,7 +36,6 @@ import org.apache.james.core.MaybeSender;
 import org.apache.james.jmap.draft.model.EnvelopeUtils;
 import org.apache.james.jmap.draft.model.Keyword;
 import org.apache.james.jmap.draft.model.Keywords;
-import org.apache.james.jmap.draft.model.MessagePreviewGenerator;
 import org.apache.james.jmap.draft.model.message.view.MessageFullView;
 import org.apache.james.jmap.draft.model.message.view.MessageFullViewFactory;
 import org.apache.james.jmap.draft.model.message.view.MessageFullViewFactory.MetaDataWithContent;
@@ -84,14 +83,12 @@ class MessageSenderTest {
             .messageId(TestMessageId.of(2))
             .build();
 
-        MessagePreviewGenerator messagePreview = mock(MessagePreviewGenerator.class);
         HtmlTextExtractor htmlTextExtractor = mock(HtmlTextExtractor.class);
-        when(messagePreview.compute(any())).thenReturn("text preview");
 
         MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
         BlobManager blobManager = mock(BlobManager.class);
         when(blobManager.toBlobId(any(MessageId.class))).thenReturn(BlobId.fromString("fake"));
-        MessageFullViewFactory messageFullViewFactory = new MessageFullViewFactory(blobManager, messagePreview, messageContentExtractor, htmlTextExtractor);
+        MessageFullViewFactory messageFullViewFactory = new MessageFullViewFactory(blobManager, messageContentExtractor, htmlTextExtractor);
         jmapMessage = messageFullViewFactory.fromMetaDataWithContent(message);
         envelope = EnvelopeUtils.fromMessage(jmapMessage);
     }
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessorTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessorTest.java
index 7ffd423..4bf45dc 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessorTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessorTest.java
@@ -37,7 +37,6 @@ import org.apache.james.jmap.draft.exceptions.MailboxNotOwnedException;
 import org.apache.james.jmap.draft.model.CreationMessage;
 import org.apache.james.jmap.draft.model.CreationMessage.DraftEmailer;
 import org.apache.james.jmap.draft.model.CreationMessageId;
-import org.apache.james.jmap.draft.model.MessagePreviewGenerator;
 import org.apache.james.jmap.draft.model.SetMessagesRequest;
 import org.apache.james.jmap.draft.model.SetMessagesResponse;
 import org.apache.james.jmap.draft.model.message.view.MessageFullViewFactory;
@@ -122,12 +121,10 @@ public class SetMessagesCreationProcessorTest {
     @Before
     public void setUp() throws MailboxException {
         HtmlTextExtractor htmlTextExtractor = mock(HtmlTextExtractor.class);
-        MessagePreviewGenerator messagePreview = mock(MessagePreviewGenerator.class);
         MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
-        when(messagePreview.compute(any())).thenReturn("text preview");
         BlobManager blobManager = mock(BlobManager.class);
         when(blobManager.toBlobId(any(MessageId.class))).thenReturn(org.apache.james.mailbox.model.BlobId.fromString("fake"));
-        messageFullViewFactory = new MessageFullViewFactory(blobManager, messagePreview, messageContentExtractor, htmlTextExtractor);
+        messageFullViewFactory = new MessageFullViewFactory(blobManager, messageContentExtractor, htmlTextExtractor);
         mockedMailSpool = mock(MailSpool.class);
         mockedAttachmentManager = mock(AttachmentManager.class);
         mockedMailboxManager = mock(MailboxManager.class);
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/SetMessagesResponseTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/SetMessagesResponseTest.java
index 9b89f94..94c678b 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/SetMessagesResponseTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/SetMessagesResponseTest.java
@@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import java.time.Instant;
 
 import org.apache.commons.lang3.NotImplementedException;
+import org.apache.james.jmap.api.preview.Preview;
 import org.apache.james.jmap.draft.model.message.view.MessageFullView;
 import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.model.MessageId;
@@ -36,6 +37,8 @@ import com.google.common.collect.ImmutableMap;
 
 public class SetMessagesResponseTest {
 
+    private static final Preview PREVIEW = Preview.from("preview");
+
     @Test
     public void builderShouldThrowWhenAccountIdIsGiven() {
         assertThatThrownBy(() -> SetMessagesResponse.builder().accountId(""))
@@ -67,7 +70,7 @@ public class SetMessagesResponseTest {
                 .subject("subject")
                 .size(123)
                 .date(currentDate)
-                .preview("preview")
+                .preview(PREVIEW)
                 .build());
         ImmutableList<MessageId> updated = ImmutableList.of(TestMessageId.of(2));
         ImmutableList<MessageId> destroyed = ImmutableList.of(TestMessageId.of(3));
@@ -121,7 +124,7 @@ public class SetMessagesResponseTest {
                 .subject("subject")
                 .size(0)
                 .date(Instant.now())
-                .preview("preview")
+                .preview(PREVIEW)
                 .build());
     }
 
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewTest.java
index 1b5b63b..ff503b6 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewTest.java
@@ -24,12 +24,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import java.time.Instant;
 import java.util.Optional;
 
+import org.apache.james.jmap.api.preview.Preview;
 import org.apache.james.jmap.draft.model.Attachment;
 import org.apache.james.jmap.draft.model.BlobId;
 import org.apache.james.jmap.draft.model.Emailer;
 import org.apache.james.jmap.draft.model.Keyword;
 import org.apache.james.jmap.draft.model.Keywords;
 import org.apache.james.jmap.draft.model.Number;
+import org.apache.james.jmap.draft.model.PreviewDTO;
 import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.jupiter.api.Test;
@@ -39,6 +41,9 @@ import com.google.common.collect.ImmutableMap;
 
 class MessageFullViewTest {
 
+    private static final Preview PREVIEW = Preview.from("preview");
+    private static final PreviewDTO PREVIEW_DTO = PreviewDTO.from(PREVIEW);
+
     @Test
     void buildShouldThrowWhenIdIsNull() {
         assertThatThrownBy(() -> MessageFullView.builder().build())
@@ -153,22 +158,6 @@ class MessageFullViewTest {
     }
 
     @Test
-    void buildShouldThrowWhenPreviewIsEmpty() {
-        assertThatThrownBy(() -> MessageFullView.builder()
-                .id(TestMessageId.of(1))
-                .blobId(BlobId.of("blobId"))
-                .threadId("threadId")
-                .fluentMailboxIds()
-                .headers(ImmutableMap.of())
-                .subject("subject")
-                .size(123)
-                .date(Instant.now())
-                .preview("")
-                .build())
-            .isInstanceOf(IllegalStateException.class);
-    }
-
-    @Test
     void buildShouldWorkWhenMandatoryFieldsArePresent() {
         Instant currentDate = Instant.now();
         Number messageSize = Number.fromLong(123);
@@ -176,7 +165,7 @@ class MessageFullViewTest {
         MessageFullView expected = new MessageFullView(TestMessageId.of(1), BlobId.of("blobId"), "threadId",
             ImmutableList.of(InMemoryId.of(456)), Optional.empty(), false, ImmutableMap.of("key", "value"),
             Optional.empty(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(),
-            "subject", currentDate, messageSize, "preview", Optional.empty(), Optional.empty(),
+            "subject", currentDate, messageSize, PREVIEW_DTO, Optional.empty(), Optional.empty(),
             ImmutableList.of(), ImmutableMap.of(), Keywords.DEFAULT_VALUE);
 
         MessageFullView tested = MessageFullView.builder()
@@ -188,7 +177,7 @@ class MessageFullViewTest {
                 .subject("subject")
                 .size(123)
                 .date(currentDate)
-                .preview("preview")
+                .preview(PREVIEW)
                 .build();
         assertThat(tested).isEqualToComparingFieldByField(expected);
     }
@@ -215,7 +204,7 @@ class MessageFullViewTest {
                 .subject("subject")
                 .size(123)
                 .date(Instant.now())
-                .preview("preview")
+                .preview(PREVIEW)
                 .attachments(attachments)
                 .attachedMessages(attachedMessages)
                 .build())
@@ -261,7 +250,7 @@ class MessageFullViewTest {
             "subject",
             currentDate,
             messageSize,
-            "preview",
+            PREVIEW_DTO,
             Optional.of("textBody"),
             Optional.of("htmlBody"),
             attachments,
@@ -284,7 +273,7 @@ class MessageFullViewTest {
             .subject("subject")
             .date(currentDate)
             .size(123)
-            .preview("preview")
+            .preview(PREVIEW)
             .textBody(Optional.of("textBody"))
             .htmlBody(Optional.of("htmlBody"))
             .attachments(attachments)
@@ -305,7 +294,7 @@ class MessageFullViewTest {
                 .subject("subject")
                 .size(1)
                 .date(Instant.now())
-                .preview("preview")
+                .preview(PREVIEW)
                 .attachedMessages(ImmutableMap.of(BlobId.of("key"), SubMessage.builder()
                         .headers(ImmutableMap.of("key", "value"))
                         .subject("subject")
@@ -326,7 +315,7 @@ class MessageFullViewTest {
             .subject("subject")
             .size(1)
             .date(Instant.now())
-            .preview("preview")
+            .preview(PREVIEW)
             .attachments(ImmutableList.of(Attachment.builder()
                     .blobId(BlobId.of("key"))
                     .size(1)
@@ -351,7 +340,7 @@ class MessageFullViewTest {
             .subject("subject")
             .size(1)
             .date(Instant.now())
-            .preview("preview")
+            .preview(PREVIEW)
             .attachments(ImmutableList.of())
             .build();
 
@@ -369,7 +358,7 @@ class MessageFullViewTest {
             .subject("subject")
             .size(1)
             .date(Instant.now())
-            .preview("preview")
+            .preview(PREVIEW)
             .attachments(ImmutableList.of(
                     Attachment.builder()
                         .blobId(BlobId.of("key"))
@@ -401,7 +390,7 @@ class MessageFullViewTest {
             .subject("subject")
             .size(1)
             .date(Instant.now())
-            .preview("preview")
+            .preview(PREVIEW)
             .attachments(ImmutableList.of(
                     Attachment.builder()
                         .blobId(BlobId.of("key"))
@@ -439,7 +428,7 @@ class MessageFullViewTest {
             .subject("subject")
             .size(1)
             .date(Instant.now())
-            .preview("preview")
+            .preview(PREVIEW)
             .attachments(ImmutableList.of(
                     Attachment.builder()
                         .blobId(BlobId.of("key"))


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 02/06: JAMES-2989 JMAP Messages carrying a strong typing Preview

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9a178a1969104003d1e2d5832b728a9c7e086595
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Tue Nov 26 11:21:17 2019 +0700

    JAMES-2989 JMAP Messages carrying a strong typing Preview
---
 .../apache/james/jmap/draft/model/PreviewDTO.java  | 68 ++++++++++++++++++++++
 .../draft/model/message/view/MessageFullView.java  | 17 +++---
 .../model/message/view/MessageFullViewFactory.java | 11 ++--
 .../message/view/MessageFullViewFactoryTest.java   | 44 +++++++-------
 4 files changed, 107 insertions(+), 33 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
new file mode 100644
index 0000000..6754db7
--- /dev/null
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/PreviewDTO.java
@@ -0,0 +1,68 @@
+/****************************************************************
+ * 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.draft.model;
+
+import java.util.Objects;
+
+import org.apache.james.jmap.api.preview.Preview;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+
+public class PreviewDTO {
+
+    public static PreviewDTO from(Preview preview) {
+        return new PreviewDTO(preview.getValue());
+    }
+
+    @VisibleForTesting
+    public static PreviewDTO of(String value) {
+        return new PreviewDTO(value);
+    }
+
+    private final String value;
+
+    private PreviewDTO(String value) {
+        Preconditions.checkNotNull(value);
+
+        this.value = value;
+    }
+
+    @JsonValue
+    public String getValue() {
+        return value;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof PreviewDTO) {
+            PreviewDTO that = (PreviewDTO) o;
+
+            return Objects.equals(this.value, that.value);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(value);
+    }
+}
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java
index 01ab3a3..00d8005 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java
@@ -25,12 +25,14 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.function.Predicate;
 
+import org.apache.james.jmap.api.preview.Preview;
 import org.apache.james.jmap.draft.methods.JmapResponseWriterImpl;
 import org.apache.james.jmap.draft.model.Attachment;
 import org.apache.james.jmap.draft.model.BlobId;
 import org.apache.james.jmap.draft.model.Emailer;
 import org.apache.james.jmap.draft.model.Keywords;
 import org.apache.james.jmap.draft.model.Number;
+import org.apache.james.jmap.draft.model.PreviewDTO;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
 
@@ -39,7 +41,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
@@ -53,7 +54,7 @@ public class MessageFullView extends MessageHeaderView {
 
     @JsonPOJOBuilder(withPrefix = "")
     public static class Builder extends MessageHeaderView.Builder<MessageFullView.Builder> {
-        private String preview;
+        private Preview preview;
         private Optional<String> textBody = Optional.empty();
         private Optional<String> htmlBody = Optional.empty();
         private final ImmutableList.Builder<Attachment> attachments;
@@ -65,7 +66,7 @@ public class MessageFullView extends MessageHeaderView {
             attachedMessages = ImmutableMap.builder();
         }
 
-        public Builder preview(String preview) {
+        public Builder preview(Preview preview) {
             this.preview = preview;
             return this;
         }
@@ -98,13 +99,13 @@ public class MessageFullView extends MessageHeaderView {
 
             return new MessageFullView(id, blobId, threadId, mailboxIds, Optional.ofNullable(inReplyToMessageId),
                 hasAttachment, headers, Optional.ofNullable(from),
-                to.build(), cc.build(), bcc.build(), replyTo.build(), subject, date, size, preview, textBody, htmlBody, attachments, attachedMessages,
+                to.build(), cc.build(), bcc.build(), replyTo.build(), subject, date, size, PreviewDTO.from(preview), textBody, htmlBody, attachments, attachedMessages,
                 keywords.orElse(Keywords.DEFAULT_VALUE));
         }
 
         public void checkState(ImmutableList<Attachment> attachments, ImmutableMap<BlobId, SubMessage> attachedMessages) {
             super.checkState();
-            Preconditions.checkState(!Strings.isNullOrEmpty(preview), "'preview' is mandatory");
+            Preconditions.checkState(preview != null, "'preview' is mandatory");
             Preconditions.checkState(areAttachedMessagesKeysInAttachments(attachments, attachedMessages), "'attachedMessages' keys must be in 'attachements'");
         }
     }
@@ -126,7 +127,7 @@ public class MessageFullView extends MessageHeaderView {
     }
 
     private final boolean hasAttachment;
-    private final String preview;
+    private final PreviewDTO preview;
     private final Optional<String> textBody;
     private final Optional<String> htmlBody;
     private final ImmutableList<Attachment> attachments;
@@ -148,7 +149,7 @@ public class MessageFullView extends MessageHeaderView {
                     String subject,
                     Instant date,
                     Number size,
-                    String preview,
+                    PreviewDTO preview,
                     Optional<String> textBody,
                     Optional<String> htmlBody,
                     ImmutableList<Attachment> attachments,
@@ -167,7 +168,7 @@ public class MessageFullView extends MessageHeaderView {
         return hasAttachment;
     }
 
-    public String getPreview() {
+    public PreviewDTO getPreview() {
         return preview;
     }
 
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
index 430910d..c246ea5 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
@@ -30,10 +30,10 @@ import java.util.Set;
 import javax.inject.Inject;
 import javax.mail.internet.SharedInputStream;
 
+import org.apache.james.jmap.api.preview.Preview;
 import org.apache.james.jmap.draft.model.Attachment;
 import org.apache.james.jmap.draft.model.BlobId;
 import org.apache.james.jmap.draft.model.Keywords;
-import org.apache.james.jmap.draft.model.MessagePreviewGenerator;
 import org.apache.james.jmap.draft.utils.HtmlTextExtractor;
 import org.apache.james.mailbox.BlobManager;
 import org.apache.james.mailbox.MessageUid;
@@ -55,15 +55,13 @@ import com.google.common.collect.Sets;
 
 public class MessageFullViewFactory implements MessageViewFactory<MessageFullView> {
     private final BlobManager blobManager;
-    private final MessagePreviewGenerator messagePreview;
     private final MessageContentExtractor messageContentExtractor;
     private final HtmlTextExtractor htmlTextExtractor;
 
     @Inject
-    public MessageFullViewFactory(BlobManager blobManager, MessagePreviewGenerator messagePreview, MessageContentExtractor messageContentExtractor,
+    public MessageFullViewFactory(BlobManager blobManager, MessageContentExtractor messageContentExtractor,
                                   HtmlTextExtractor htmlTextExtractor) {
         this.blobManager = blobManager;
-        this.messagePreview = messagePreview;
         this.messageContentExtractor = messageContentExtractor;
         this.htmlTextExtractor = htmlTextExtractor;
     }
@@ -79,7 +77,10 @@ public class MessageFullViewFactory implements MessageViewFactory<MessageFullVie
         Optional<String> htmlBody = messageContent.getHtmlBody();
         Optional<String> mainTextContent = mainTextContent(messageContent);
         Optional<String> textBody = computeTextBodyIfNeeded(messageContent, mainTextContent);
-        String preview = messagePreview.compute(mainTextContent);
+
+        Preview preview = mainTextContent.map(Preview::compute)
+            .orElse(Preview.NO_BODY);
+
         return MessageFullView.builder()
                 .id(message.getMessageId())
                 .blobId(BlobId.of(blobManager.toBlobId(message.getMessageId())))
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
index c1c3082..60aefee 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
@@ -35,13 +35,14 @@ import java.util.Optional;
 import javax.mail.Flags;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.james.jmap.api.preview.Preview;
 import org.apache.james.jmap.draft.model.Attachment;
 import org.apache.james.jmap.draft.model.BlobId;
 import org.apache.james.jmap.draft.model.Emailer;
 import org.apache.james.jmap.draft.model.Keyword;
 import org.apache.james.jmap.draft.model.Keywords;
-import org.apache.james.jmap.draft.model.MessagePreviewGenerator;
 import org.apache.james.jmap.draft.model.Number;
+import org.apache.james.jmap.draft.model.PreviewDTO;
 import org.apache.james.jmap.draft.model.message.view.MessageFullViewFactory.MetaDataWithContent;
 import org.apache.james.jmap.draft.utils.HtmlTextExtractor;
 import org.apache.james.jmap.draft.utils.JsoupHtmlTextExtractor;
@@ -87,7 +88,6 @@ class MessageFullViewFactoryTest {
     void setUp() throws Exception {
         HtmlTextExtractor htmlTextExtractor = new JsoupHtmlTextExtractor();
 
-        MessagePreviewGenerator messagePreview = new MessagePreviewGenerator();
         MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
 
         InMemoryIntegrationResources resources = InMemoryIntegrationResources.defaultResources();
@@ -106,7 +106,7 @@ class MessageFullViewFactoryTest {
                 .build(ClassLoaderUtils.getSystemResourceAsSharedStream("fullMessage.eml")),
             session);
 
-        messageFullViewFactory = new MessageFullViewFactory(resources.getBlobManager(), messagePreview, messageContentExtractor, htmlTextExtractor);
+        messageFullViewFactory = new MessageFullViewFactory(resources.getBlobManager(), messageContentExtractor, htmlTextExtractor);
     }
 
     @Test
@@ -132,7 +132,7 @@ class MessageFullViewFactoryTest {
             softly.assertThat(actual.getSubject()).isEqualTo("Full message");
             softly.assertThat(actual.getDate()).isEqualTo("2016-06-07T14:23:37Z");
             softly.assertThat(actual.isHasAttachment()).isEqualTo(true);
-            softly.assertThat(actual.getPreview()).isEqualTo("blabla bloblo");
+            softly.assertThat(actual.getPreview()).isEqualTo(PreviewDTO.of("blabla bloblo"));
             softly.assertThat(actual.getTextBody()).isEqualTo(Optional.of("/blabla/\n*bloblo*\n"));
             softly.assertThat(actual.getHtmlBody()).isEqualTo(Optional.of("<i>blabla</i>\n<b>bloblo</b>\n"));
             softly.assertThat(actual.getAttachments()).hasSize(1);
@@ -171,7 +171,7 @@ class MessageFullViewFactoryTest {
         MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getSize, MessageFullView::getSubject, MessageFullView::getHeaders, MessageFullView::getDate)
-            .containsExactly("(Empty)", Number.ZERO, "", ImmutableMap.of("MIME-Version", "1.0"), INTERNAL_DATE);
+            .containsExactly(PreviewDTO.of("(Empty)"), Number.ZERO, "", ImmutableMap.of("MIME-Version", "1.0"), INTERNAL_DATE);
     }
 
     @Test
@@ -250,7 +250,7 @@ class MessageFullViewFactoryTest {
                 .subject("test subject")
                 .date(Instant.parse("2015-07-14T12:30:42.000Z"))
                 .size(headers.length())
-                .preview("(Empty)")
+                .preview(Preview.from("(Empty)"))
                 .textBody(Optional.of(""))
                 .htmlBody(Optional.empty())
                 .keywords(keywords)
@@ -301,7 +301,7 @@ class MessageFullViewFactoryTest {
             .subject("test subject")
             .date(Instant.parse("2012-02-03T14:30:42.000Z"))
             .size(headers.length())
-            .preview("(Empty)")
+            .preview(Preview.from("(Empty)"))
             .textBody(Optional.of(""))
             .htmlBody(Optional.empty())
             .keywords(keywords)
@@ -350,7 +350,7 @@ class MessageFullViewFactoryTest {
             .subject("test subject")
             .date(Instant.parse("2012-02-03T14:30:42.000Z"))
             .size(headers.length())
-            .preview("(Empty)")
+            .preview(Preview.from("(Empty)"))
             .textBody(Optional.of(""))
             .htmlBody(Optional.empty())
             .keywords(keywords)
@@ -421,11 +421,11 @@ class MessageFullViewFactoryTest {
         String body300 = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
                 + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
                 + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999";
-        String expectedPreview = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999" 
+        PreviewDTO expectedPreview = PreviewDTO.of("0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
                 + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999" 
-                + "00000000001111111111222222222233333333334444444444555555";
+                + "00000000001111111111222222222233333333334444444444555555");
         assertThat(body300.length()).isEqualTo(300);
-        assertThat(expectedPreview.length()).isEqualTo(256);
+        assertThat(expectedPreview.getValue().length()).isEqualTo(256);
         String mail = headers + "\n" + body300;
         MetaDataWithContent testMail = MetaDataWithContent.builder()
                 .uid(MessageUid.of(2))
@@ -438,7 +438,8 @@ class MessageFullViewFactoryTest {
                 .messageId(TestMessageId.of(2))
                 .build();
         MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
-        assertThat(testee.getPreview()).isEqualTo(expectedPreview);
+        assertThat(testee.getPreview())
+            .isEqualTo(expectedPreview);
     }
     
     @Test
@@ -638,7 +639,7 @@ class MessageFullViewFactoryTest {
         MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getSize, MessageFullView::getSubject, MessageFullView::getHeaders, MessageFullView::getDate)
-            .containsExactly("(Empty)", Number.fromLong(1010L), "", ImmutableMap.of("MIME-Version", "1.0"), INTERNAL_DATE);
+            .containsExactly(PreviewDTO.of("(Empty)"), Number.fromLong(1010L), "", ImmutableMap.of("MIME-Version", "1.0"), INTERNAL_DATE);
     }
 
     @Test
@@ -659,7 +660,8 @@ class MessageFullViewFactoryTest {
             .build();
         MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
 
-        assertThat(testee.getPreview()).isEqualTo("my HTML message");
+        assertThat(testee.getPreview())
+            .isEqualTo(PreviewDTO.of("my HTML message"));
         assertThat(testee.getTextBody()).hasValue("my HTML message");
         assertThat(testee.getHtmlBody()).hasValue("my <b>HTML</b> message");
     }
@@ -680,7 +682,7 @@ class MessageFullViewFactoryTest {
             .build();
         MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
 
-        assertThat(testee.getPreview()).isEqualTo(MessagePreviewGenerator.NO_BODY);
+        assertThat(testee.getPreview()).isEqualTo(PreviewDTO.of("(Empty)"));
         assertThat(testee.getHtmlBody()).contains("");
         assertThat(testee.getTextBody()).isEmpty();
     }
@@ -712,7 +714,8 @@ class MessageFullViewFactoryTest {
             .build();
         MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
 
-        assertThat(testee.getPreview()).isEqualTo(expected);
+        assertThat(testee.getPreview())
+            .isEqualTo(PreviewDTO.of(expected));
     }
 
     @Test
@@ -734,7 +737,8 @@ class MessageFullViewFactoryTest {
             .build();
         MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
 
-        assertThat(testee.getPreview()).isEqualTo("My plain text");
+        assertThat(testee.getPreview())
+            .isEqualTo(PreviewDTO.of("My plain text"));
     }
 
     @Test
@@ -755,7 +759,7 @@ class MessageFullViewFactoryTest {
 
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getHtmlBody, MessageFullView::getTextBody)
-            .containsExactly(MessagePreviewGenerator.NO_BODY, Optional.empty(), Optional.of(""));
+            .containsExactly(PreviewDTO.of("(Empty)"), Optional.empty(), Optional.of(""));
     }
 
     @Test
@@ -779,7 +783,7 @@ class MessageFullViewFactoryTest {
 
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getHtmlBody, MessageFullView::getTextBody)
-            .containsExactly(MessagePreviewGenerator.NO_BODY, Optional.of("<html><body></body></html>"), Optional.empty());
+            .containsExactly(PreviewDTO.of("(Empty)"), Optional.of("<html><body></body></html>"), Optional.empty());
     }
 
     @Test
@@ -815,7 +819,7 @@ class MessageFullViewFactoryTest {
 
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getHtmlBody, MessageFullView::getTextBody)
-            .containsExactly("My plain message", Optional.of("<html></html>"), Optional.of("My plain message"));
+            .containsExactly(PreviewDTO.of("My plain message"), Optional.of("<html></html>"), Optional.of("My plain message"));
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 04/06: JAMES-2989 drop MessagePreviewGenerator

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 8bf25037ebb0a309c45ca3d42b1d0ab82b88bee4
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Tue Nov 26 11:24:42 2019 +0700

    JAMES-2989 drop MessagePreviewGenerator
---
 .../apache/james/jmap/draft/JMAPCommonModule.java  |  2 -
 .../jmap/draft/model/MessagePreviewGenerator.java  | 41 ----------
 .../draft/model/MessagePreviewGeneratorTest.java   | 95 ----------------------
 3 files changed, 138 deletions(-)

diff --git a/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JMAPCommonModule.java b/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JMAPCommonModule.java
index 3bf46e5..48a0af2 100644
--- a/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JMAPCommonModule.java
+++ b/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JMAPCommonModule.java
@@ -34,7 +34,6 @@ import org.apache.james.jmap.draft.crypto.SignatureHandler;
 import org.apache.james.jmap.draft.crypto.SignedTokenFactory;
 import org.apache.james.jmap.draft.crypto.SignedTokenManager;
 import org.apache.james.jmap.draft.model.MailboxFactory;
-import org.apache.james.jmap.draft.model.MessagePreviewGenerator;
 import org.apache.james.jmap.draft.model.message.view.MessageFullViewFactory;
 import org.apache.james.jmap.draft.send.MailSpool;
 import org.apache.james.jmap.draft.utils.HeadersAuthenticationExtractor;
@@ -69,7 +68,6 @@ public class JMAPCommonModule extends AbstractModule {
         bind(AutomaticallySentMailDetectorImpl.class).in(Scopes.SINGLETON);
         bind(MailboxFactory.class).in(Scopes.SINGLETON);
         bind(MessageFullViewFactory.class).in(Scopes.SINGLETON);
-        bind(MessagePreviewGenerator.class).in(Scopes.SINGLETON);
         bind(MessageContentExtractor.class).in(Scopes.SINGLETON);
         bind(HeadersAuthenticationExtractor.class).in(Scopes.SINGLETON);
         bind(SecurityKeyLoader.class).in(Scopes.SINGLETON);
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessagePreviewGenerator.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessagePreviewGenerator.java
deleted file mode 100644
index 53ddcdb..0000000
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessagePreviewGenerator.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/****************************************************************
- * 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.draft.model;
-
-import java.util.Optional;
-
-import org.apache.commons.lang3.StringUtils;
-
-public class MessagePreviewGenerator {
-    
-    public static final String NO_BODY = "(Empty)";
-    public static final int MAX_PREVIEW_LENGTH = 256;
-
-    public String compute(Optional<String> textBody) {
-        return textBody.map(StringUtils::normalizeSpace)
-            .filter(text -> !text.isEmpty())
-            .map(this::truncateToMaxLength)
-            .orElse(NO_BODY);
-    }
-
-    private String truncateToMaxLength(String body) {
-        return StringUtils.left(body, MAX_PREVIEW_LENGTH);
-    }
-}
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MessagePreviewGeneratorTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MessagePreviewGeneratorTest.java
deleted file mode 100644
index 8fff51e..0000000
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MessagePreviewGeneratorTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************
- * 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.draft.model;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.Optional;
-
-import org.apache.commons.lang3.StringUtils;
-import org.junit.Before;
-import org.junit.Test;
-
-public class MessagePreviewGeneratorTest {
-    
-    private MessagePreviewGenerator testee;
-
-    @Before
-    public void setUp() {
-        testee = new MessagePreviewGenerator();
-    }
-
-    @Test
-    public void computeShouldReturnStringEmptyWhenEmptyTextBody() throws Exception {
-        assertThat(testee.compute(Optional.empty())).isEqualTo(MessagePreviewGenerator.NO_BODY);
-    }
-
-    @Test
-    public void computeShouldReturnStringEmptyWhenStringEmptyTextBody() throws Exception {
-        assertThat(testee.compute(Optional.of(""))).isEqualTo(MessagePreviewGenerator.NO_BODY);
-    }
-
-    @Test
-    public void computeShouldReturnStringEmptyWhenOnlySpaceTabAndBreakLines() throws Exception {
-        assertThat(testee.compute(Optional.of(" \n\t "))).isEqualTo(MessagePreviewGenerator.NO_BODY);
-    }
-
-    @Test
-    public void computeShouldReturnStringEmptyWhenOnlySpace() throws Exception {
-        assertThat(testee.compute(Optional.of(" "))).isEqualTo(MessagePreviewGenerator.NO_BODY);
-    }
-
-    @Test
-    public void computeShouldReturnStringEmptyWhenOnlyTab() throws Exception {
-        assertThat(testee.compute(Optional.of("\t"))).isEqualTo(MessagePreviewGenerator.NO_BODY);
-    }
-
-    @Test
-    public void computeShouldReturnStringEmptyWhenOnlyBreakLines() throws Exception {
-        assertThat(testee.compute(Optional.of("\n"))).isEqualTo(MessagePreviewGenerator.NO_BODY);
-    }
-
-    @Test
-    public void computeShouldReturnStringWithoutTruncation() throws Exception {
-        String body = StringUtils.leftPad("a", 100, "b");
-
-        assertThat(testee.compute(Optional.of(body)))
-                .hasSize(100)
-                .isEqualTo(body);
-    }
-
-    @Test
-    public void computeShouldReturnStringIsLimitedTo256Length() throws Exception {
-        String body = StringUtils.leftPad("a", 300, "b");
-        String expected = StringUtils.leftPad("b", MessagePreviewGenerator.MAX_PREVIEW_LENGTH, "b");
-
-        assertThat(testee.compute(Optional.of(body)))
-            .hasSize(MessagePreviewGenerator.MAX_PREVIEW_LENGTH)
-            .isEqualTo(expected);
-    }
-
-    @Test
-    public void computeShouldReturnNormalizeSpaceString() throws Exception {
-        String body = "    this      is\n      the\r           preview\t         content\n\n         ";
-
-        assertThat(testee.compute(Optional.of(body)))
-                .isEqualTo("this is the preview content");
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 01/06: JAMES-2989 Preview factory method with the business from PreviewGenerator

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 3e94093464f787d2b3fa3c8775c10fb705319887
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Fri Nov 22 10:02:01 2019 +0700

    JAMES-2989 Preview factory method with the business from PreviewGenerator
    
    Because the business to create a preview is simple and doesn't depend on
    other external states. I decided to move it into the POJO
---
 .../org/apache/james/jmap/api/preview/Preview.java | 17 ++++++
 .../apache/james/jmap/api/preview/PreviewTest.java | 66 ++++++++++++++++++++++
 2 files changed, 83 insertions(+)

diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/preview/Preview.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/preview/Preview.java
index 0d4a208..8fb0b66 100644
--- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/preview/Preview.java
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/preview/Preview.java
@@ -20,6 +20,9 @@
 package org.apache.james.jmap.api.preview;
 
 import java.util.Objects;
+import java.util.Optional;
+
+import org.apache.commons.lang3.StringUtils;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
@@ -27,11 +30,25 @@ import com.google.common.base.Preconditions;
 public class Preview {
 
     private static final int MAX_LENGTH = 256;
+    public static final Preview NO_BODY = new Preview("(Empty)");
 
     public static Preview from(String value) {
         return new Preview(value);
     }
 
+    public static Preview compute(String textBody) {
+        return Optional.of(textBody)
+            .map(StringUtils::normalizeSpace)
+            .filter(text -> !text.isEmpty())
+            .map(Preview::truncateToMaxLength)
+            .map(Preview::from)
+            .orElse(NO_BODY);
+    }
+
+    private static String truncateToMaxLength(String body) {
+        return StringUtils.left(body, MAX_LENGTH);
+    }
+
     private final String value;
 
     @VisibleForTesting
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/preview/PreviewTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/preview/PreviewTest.java
index 8298f5d..33b5ee4 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/preview/PreviewTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/preview/PreviewTest.java
@@ -23,6 +23,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
+import org.apache.commons.lang3.StringUtils;
+import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
 import com.google.common.base.Strings;
@@ -32,6 +34,7 @@ import nl.jqno.equalsverifier.EqualsVerifier;
 class PreviewTest {
 
     private static final String PREVIEW_RAW_VALUE = "Hello James!";
+    private static final Preview NO_BODY = new Preview("(Empty)");
 
     @Test
     void shouldMatchBeanContract() {
@@ -70,4 +73,67 @@ class PreviewTest {
         assertThatCode(() -> Preview.from(Strings.repeat("a", 256)))
             .doesNotThrowAnyException();
     }
+
+    @Nested
+    class ComputeTest {
+        
+        @Test
+        void computeShouldReturnStringEmptyWhenStringEmptyTextBody() throws Exception {
+            assertThat(Preview.compute(""))
+                .isEqualTo(NO_BODY);
+        }
+
+        @Test
+        void computeShouldReturnStringEmptyWhenOnlySpaceTabAndBreakLines() throws Exception {
+            assertThat(Preview.compute(" \n\t "))
+                .isEqualTo(NO_BODY);
+        }
+
+        @Test
+        void computeShouldReturnStringEmptyWhenOnlySpace() throws Exception {
+            assertThat(Preview.compute(" "))
+                .isEqualTo(NO_BODY);
+        }
+
+        @Test
+        void computeShouldReturnStringEmptyWhenOnlyTab() throws Exception {
+            assertThat(Preview.compute("\t"))
+                .isEqualTo(NO_BODY);
+        }
+
+        @Test
+        void computeShouldReturnStringEmptyWhenOnlyBreakLines() throws Exception {
+            assertThat(Preview.compute("\n"))
+                .isEqualTo(NO_BODY);
+        }
+
+        @Test
+        void computeShouldReturnStringWithoutTruncation() throws Exception {
+            String body = StringUtils.leftPad("a", 100, "b");
+
+            assertThat(Preview.compute(body)
+                    .getValue())
+                .hasSize(100)
+                .isEqualTo(body);
+        }
+
+        @Test
+        void computeShouldReturnStringIsLimitedTo256Length() throws Exception {
+            String body = StringUtils.leftPad("a", 300, "b");
+            String expected = StringUtils.leftPad("b", 256, "b");
+
+            assertThat(Preview.compute(body)
+                    .getValue())
+                .hasSize(256)
+                .isEqualTo(expected);
+        }
+
+        @Test
+        void computeShouldReturnNormalizeSpaceString() throws Exception {
+            String body = "    this      is\n      the\r           preview\t         content\n\n         ";
+
+            assertThat(Preview.compute(body))
+                .isEqualTo(Preview.from("this is the preview content"));
+        }
+    }
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 05/06: JAMES-2989 Move the hardcoded "(Empty)" to the presentation layer

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit abcb395a8255842e65d0b2ef14442d598308cedc
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed Nov 27 10:47:46 2019 +0700

    JAMES-2989 Move the hardcoded "(Empty)" to the presentation layer
    
    To avoid storing hardcoded string in to the database for improving locale
    friendly in the future. Conversation is at:
    
    https://github.com/linagora/james-project/pull/2918#discussion_r350829600
---
 .../org/apache/james/jmap/api/preview/Preview.java | 11 +---
 .../apache/james/jmap/api/preview/PreviewTest.java | 22 +++----
 .../apache/james/jmap/draft/model/PreviewDTO.java  | 14 ++++-
 .../draft/model/message/view/MessageFullView.java  |  7 ++-
 .../model/message/view/MessageFullViewFactory.java |  3 +-
 .../james/jmap/draft/model/PreviewDTOTest.java     | 71 ++++++++++++++++++++++
 .../message/view/MessageFullViewFactoryTest.java   | 10 +--
 .../model/message/view/MessageFullViewTest.java    |  2 +-
 8 files changed, 109 insertions(+), 31 deletions(-)

diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/preview/Preview.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/preview/Preview.java
index 8fb0b66..42c3db3 100644
--- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/preview/Preview.java
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/preview/Preview.java
@@ -20,7 +20,6 @@
 package org.apache.james.jmap.api.preview;
 
 import java.util.Objects;
-import java.util.Optional;
 
 import org.apache.commons.lang3.StringUtils;
 
@@ -30,19 +29,15 @@ import com.google.common.base.Preconditions;
 public class Preview {
 
     private static final int MAX_LENGTH = 256;
-    public static final Preview NO_BODY = new Preview("(Empty)");
 
     public static Preview from(String value) {
         return new Preview(value);
     }
 
     public static Preview compute(String textBody) {
-        return Optional.of(textBody)
-            .map(StringUtils::normalizeSpace)
-            .filter(text -> !text.isEmpty())
-            .map(Preview::truncateToMaxLength)
-            .map(Preview::from)
-            .orElse(NO_BODY);
+        return Preview.from(
+            truncateToMaxLength(
+                StringUtils.normalizeSpace(textBody)));
     }
 
     private static String truncateToMaxLength(String body) {
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/preview/PreviewTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/preview/PreviewTest.java
index 33b5ee4..8a897b2 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/preview/PreviewTest.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/preview/PreviewTest.java
@@ -34,7 +34,7 @@ import nl.jqno.equalsverifier.EqualsVerifier;
 class PreviewTest {
 
     private static final String PREVIEW_RAW_VALUE = "Hello James!";
-    private static final Preview NO_BODY = new Preview("(Empty)");
+    private static final Preview EMPTY_STRING_PREVIEW = Preview.from("");
 
     @Test
     void shouldMatchBeanContract() {
@@ -78,33 +78,33 @@ class PreviewTest {
     class ComputeTest {
         
         @Test
-        void computeShouldReturnStringEmptyWhenStringEmptyTextBody() throws Exception {
+        void computeShouldReturnEmptyStringPreviewWhenStringEmptyTextBody() throws Exception {
             assertThat(Preview.compute(""))
-                .isEqualTo(NO_BODY);
+                .isEqualTo(EMPTY_STRING_PREVIEW);
         }
 
         @Test
-        void computeShouldReturnStringEmptyWhenOnlySpaceTabAndBreakLines() throws Exception {
+        void computeShouldReturnEmptyStringPreviewWhenOnlySpaceTabAndBreakLines() throws Exception {
             assertThat(Preview.compute(" \n\t "))
-                .isEqualTo(NO_BODY);
+                .isEqualTo(EMPTY_STRING_PREVIEW);
         }
 
         @Test
-        void computeShouldReturnStringEmptyWhenOnlySpace() throws Exception {
+        void computeShouldReturnEmptyStringPreviewWhenOnlySpace() throws Exception {
             assertThat(Preview.compute(" "))
-                .isEqualTo(NO_BODY);
+                .isEqualTo(EMPTY_STRING_PREVIEW);
         }
 
         @Test
-        void computeShouldReturnStringEmptyWhenOnlyTab() throws Exception {
+        void computeShouldReturnEmptyStringPreviewWhenOnlyTab() throws Exception {
             assertThat(Preview.compute("\t"))
-                .isEqualTo(NO_BODY);
+                .isEqualTo(EMPTY_STRING_PREVIEW);
         }
 
         @Test
-        void computeShouldReturnStringEmptyWhenOnlyBreakLines() throws Exception {
+        void computeShouldReturnEmptyStringPreviewWhenOnlyBreakLines() throws Exception {
             assertThat(Preview.compute("\n"))
-                .isEqualTo(NO_BODY);
+                .isEqualTo(EMPTY_STRING_PREVIEW);
         }
 
         @Test
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 6754db7..6b2457c 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
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.draft.model;
 
 import java.util.Objects;
+import java.util.Optional;
 
 import org.apache.james.jmap.api.preview.Preview;
 
@@ -29,8 +30,13 @@ import com.google.common.base.Preconditions;
 
 public class PreviewDTO {
 
-    public static PreviewDTO from(Preview preview) {
-        return new PreviewDTO(preview.getValue());
+    private static final String NO_BODY_AS_STRING = "(Empty)";
+    private static final PreviewDTO NO_BODY = PreviewDTO.of(NO_BODY_AS_STRING);
+
+    public static PreviewDTO from(Optional<Preview> preview) {
+        return preview.map(Preview::getValue)
+            .map(PreviewDTO::of)
+            .orElse(NO_BODY);
     }
 
     @VisibleForTesting
@@ -43,7 +49,9 @@ public class PreviewDTO {
     private PreviewDTO(String value) {
         Preconditions.checkNotNull(value);
 
-        this.value = value;
+        this.value = Optional.of(value)
+            .filter(previewValue -> !previewValue.isEmpty())
+            .orElse(NO_BODY_AS_STRING);
     }
 
     @JsonValue
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java
index 00d8005..40399c9 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java
@@ -54,7 +54,7 @@ public class MessageFullView extends MessageHeaderView {
 
     @JsonPOJOBuilder(withPrefix = "")
     public static class Builder extends MessageHeaderView.Builder<MessageFullView.Builder> {
-        private Preview preview;
+        private Optional<Preview> preview;
         private Optional<String> textBody = Optional.empty();
         private Optional<String> htmlBody = Optional.empty();
         private final ImmutableList.Builder<Attachment> attachments;
@@ -67,6 +67,11 @@ public class MessageFullView extends MessageHeaderView {
         }
 
         public Builder preview(Preview preview) {
+            this.preview = Optional.of(preview);
+            return this;
+        }
+
+        public Builder preview(Optional<Preview> preview) {
             this.preview = preview;
             return this;
         }
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
index c246ea5..bc17419 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactory.java
@@ -78,8 +78,7 @@ public class MessageFullViewFactory implements MessageViewFactory<MessageFullVie
         Optional<String> mainTextContent = mainTextContent(messageContent);
         Optional<String> textBody = computeTextBodyIfNeeded(messageContent, mainTextContent);
 
-        Preview preview = mainTextContent.map(Preview::compute)
-            .orElse(Preview.NO_BODY);
+        Optional<Preview> preview = mainTextContent.map(Preview::compute);
 
         return MessageFullView.builder()
                 .id(message.getMessageId())
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/PreviewDTOTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/PreviewDTOTest.java
new file mode 100644
index 0000000..95b1a79
--- /dev/null
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/PreviewDTOTest.java
@@ -0,0 +1,71 @@
+/****************************************************************
+ * 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.draft.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.apache.james.jmap.api.preview.Preview;
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class PreviewDTOTest {
+
+    private static final String EMPTY_PREVIEW = "(Empty)";
+    private static final String SAMPLE_PREVIEW_VALUE = "hello bob!";
+
+    @Test
+    void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(PreviewDTO.class)
+            .verify();
+    }
+
+    @Test
+    void fromShouldReturnPreviewWithTheValue() {
+        assertThat(PreviewDTO.from(Optional.of(Preview.from(SAMPLE_PREVIEW_VALUE))))
+            .isEqualTo(PreviewDTO.of(SAMPLE_PREVIEW_VALUE));
+    }
+
+    @Test
+    void fromShouldReturnNoBodyWhenNoPreview() {
+        assertThat(PreviewDTO.from(Optional.empty()))
+            .isEqualTo(PreviewDTO.of(EMPTY_PREVIEW));
+    }
+
+    @Test
+    void fromShouldReturnNoBodyWhenPreviewOfEmptyString() {
+        assertThat(PreviewDTO.from(Optional.of(Preview.from(""))))
+            .isEqualTo(PreviewDTO.of(EMPTY_PREVIEW));
+    }
+
+    @Test
+    void ofShouldReturnPreviewWithTheValue() {
+        assertThat(PreviewDTO.of(SAMPLE_PREVIEW_VALUE))
+            .isEqualTo(PreviewDTO.of(SAMPLE_PREVIEW_VALUE));
+    }
+
+    @Test
+    void ofShouldReturnNoBodyWhenPreviewOfEmptyString() {
+        assertThat(PreviewDTO.of(""))
+            .isEqualTo(PreviewDTO.of(EMPTY_PREVIEW));
+    }
+}
\ No newline at end of file
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
index 60aefee..e0c3ff9 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
@@ -171,7 +171,7 @@ class MessageFullViewFactoryTest {
         MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getSize, MessageFullView::getSubject, MessageFullView::getHeaders, MessageFullView::getDate)
-            .containsExactly(PreviewDTO.of("(Empty)"), Number.ZERO, "", ImmutableMap.of("MIME-Version", "1.0"), INTERNAL_DATE);
+            .containsExactly(PreviewDTO.of(""), Number.ZERO, "", ImmutableMap.of("MIME-Version", "1.0"), INTERNAL_DATE);
     }
 
     @Test
@@ -639,7 +639,7 @@ class MessageFullViewFactoryTest {
         MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getSize, MessageFullView::getSubject, MessageFullView::getHeaders, MessageFullView::getDate)
-            .containsExactly(PreviewDTO.of("(Empty)"), Number.fromLong(1010L), "", ImmutableMap.of("MIME-Version", "1.0"), INTERNAL_DATE);
+            .containsExactly(PreviewDTO.of(""), Number.fromLong(1010L), "", ImmutableMap.of("MIME-Version", "1.0"), INTERNAL_DATE);
     }
 
     @Test
@@ -682,7 +682,7 @@ class MessageFullViewFactoryTest {
             .build();
         MessageFullView testee = messageFullViewFactory.fromMetaDataWithContent(testMail);
 
-        assertThat(testee.getPreview()).isEqualTo(PreviewDTO.of("(Empty)"));
+        assertThat(testee.getPreview()).isEqualTo(PreviewDTO.of(""));
         assertThat(testee.getHtmlBody()).contains("");
         assertThat(testee.getTextBody()).isEmpty();
     }
@@ -759,7 +759,7 @@ class MessageFullViewFactoryTest {
 
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getHtmlBody, MessageFullView::getTextBody)
-            .containsExactly(PreviewDTO.of("(Empty)"), Optional.empty(), Optional.of(""));
+            .containsExactly(PreviewDTO.of(""), Optional.empty(), Optional.of(""));
     }
 
     @Test
@@ -783,7 +783,7 @@ class MessageFullViewFactoryTest {
 
         assertThat(testee)
             .extracting(MessageFullView::getPreview, MessageFullView::getHtmlBody, MessageFullView::getTextBody)
-            .containsExactly(PreviewDTO.of("(Empty)"), Optional.of("<html><body></body></html>"), Optional.empty());
+            .containsExactly(PreviewDTO.of(""), Optional.of("<html><body></body></html>"), Optional.empty());
     }
 
     @Test
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewTest.java
index ff503b6..81c64e6 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewTest.java
@@ -42,7 +42,7 @@ import com.google.common.collect.ImmutableMap;
 class MessageFullViewTest {
 
     private static final Preview PREVIEW = Preview.from("preview");
-    private static final PreviewDTO PREVIEW_DTO = PreviewDTO.from(PREVIEW);
+    private static final PreviewDTO PREVIEW_DTO = PreviewDTO.of(PREVIEW.getValue());
 
     @Test
     void buildShouldThrowWhenIdIsNull() {


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[james-project] 06/06: JAMES-2996 Errors upon start should be reported to the logging system

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 4a8cd1ab9a08f2aecd3b6e8db98ebddd0e93cb78
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Nov 28 09:28:04 2019 +0700

    JAMES-2996 Errors upon start should be reported to the logging system
    
    log then rethrow pattern is the only solution to do this while still pro-
    pagating the error.
---
 .../java/org/apache/james/GuiceJamesServer.java    | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
index 85311fd..84611d7 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
@@ -31,6 +31,8 @@ import org.apache.james.server.core.configuration.Configuration;
 import org.apache.james.utils.GuiceProbe;
 import org.apache.james.utils.GuiceProbeProvider;
 import org.apache.james.utils.InitializationOperations;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Iterables;
 import com.google.inject.Guice;
@@ -41,6 +43,7 @@ import com.google.inject.TypeLiteral;
 import com.google.inject.util.Modules;
 
 public class GuiceJamesServer {
+    private static final Logger LOGGER = LoggerFactory.getLogger(GuiceJamesServer.class);
 
     protected final Module module;
     private final IsStartedProbe isStartedProbe;
@@ -76,13 +79,19 @@ public class GuiceJamesServer {
     }
 
     public void start() throws Exception {
-        Injector injector = Guice.createInjector(module);
-        preDestroy = injector.getInstance(Key.get(new TypeLiteral<Stager<PreDestroy>>() {}));
-        injector.getInstance(StartUpChecksPerformer.class)
-            .performCheck();
-        injector.getInstance(InitializationOperations.class).initModules();
-        guiceProbeProvider = injector.getInstance(GuiceProbeProvider.class);
-        isStartedProbe.notifyStarted();
+        try {
+            Injector injector = Guice.createInjector(module);
+            preDestroy = injector.getInstance(Key.get(new TypeLiteral<Stager<PreDestroy>>() {
+            }));
+            injector.getInstance(StartUpChecksPerformer.class)
+                .performCheck();
+            injector.getInstance(InitializationOperations.class).initModules();
+            guiceProbeProvider = injector.getInstance(GuiceProbeProvider.class);
+            isStartedProbe.notifyStarted();
+        } catch (Throwable e) {
+            LOGGER.error("Fatal error while starting James", e);
+            throw e;
+        }
     }
 
     public void stop() {


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org