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/11/28 02:12:31 UTC

[james-project] 14/23: JAMES-2989 Tests for FetchGroupConverter

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 9e5ddfba2a3f56a5e8014dea95b006322dc93b81
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Nov 25 12:50:57 2019 +0700

    JAMES-2989 Tests for FetchGroupConverter
---
 .../mailbox/store/mail/FetchGroupConverter.java    |   8 ++
 .../store/mail/FetchGroupConverterTest.java        | 121 +++++++++++++++++++++
 2 files changed, 129 insertions(+)

diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
index cfd91fb..5bceef9 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
@@ -56,6 +56,14 @@ public class FetchGroupConverter {
             full = true;
             content -= FetchGroup.MIME_DESCRIPTOR_MASK;
         }
+        if ((content & FetchGroup.MIME_CONTENT_MASK) > 0) {
+            full = true;
+            content -= FetchGroup.MIME_CONTENT_MASK;
+        }
+        if ((content & FetchGroup.MIME_HEADERS_MASK) > 0) {
+            full = true;
+            content -= FetchGroup.MIME_HEADERS_MASK;
+        }
         if (full || (body && headers)) {
             return MessageMapper.FetchType.Full;
         } else if (body) {
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
new file mode 100644
index 0000000..2c3f66f
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
@@ -0,0 +1,121 @@
+/****************************************************************
+ * 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: ww.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.mailbox.store.mail;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.model.FetchGroup;
+import org.apache.james.mailbox.model.MimePath;
+import org.junit.jupiter.api.Test;
+
+class FetchGroupConverterTest {
+    @Test
+    void getFetchTypeShouldReturnMetadataWhenMinimal() {
+        assertThat(FetchGroupConverter.getFetchType(FetchGroup.MINIMAL))
+            .isEqualTo(MessageMapper.FetchType.Metadata);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnHeadersWhenHeaders() {
+        assertThat(FetchGroupConverter.getFetchType(FetchGroup.HEADERS))
+            .isEqualTo(MessageMapper.FetchType.Headers);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnBodyContentWhenBody() {
+        assertThat(FetchGroupConverter.getFetchType(FetchGroup.BODY_CONTENT))
+            .isEqualTo(MessageMapper.FetchType.Body);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnFullWhenBodyAndHeaders() {
+        FetchGroup fetchGroup = FetchGroup.BODY_CONTENT
+            .or(FetchGroup.HEADERS_MASK);
+
+        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
+            .isEqualTo(MessageMapper.FetchType.Full);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnFullWhenFull() {
+        assertThat(FetchGroupConverter.getFetchType(FetchGroup.FULL_CONTENT))
+            .isEqualTo(MessageMapper.FetchType.Full);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnFullWhenMimeContent() {
+        FetchGroup fetchGroup = FetchGroup.MINIMAL
+            .or(FetchGroup.MIME_CONTENT_MASK);
+        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
+            .isEqualTo(MessageMapper.FetchType.Full);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnFullWhenMimeDescriptor() {
+        FetchGroup fetchGroup = FetchGroup.MINIMAL
+            .or(FetchGroup.MIME_DESCRIPTOR_MASK);
+        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
+            .isEqualTo(MessageMapper.FetchType.Full);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnFullWhenMimeHeaders() {
+        FetchGroup fetchGroup = FetchGroup.MINIMAL
+            .or(FetchGroup.MIME_HEADERS_MASK);
+        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
+            .isEqualTo(MessageMapper.FetchType.Full);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnFullWhenMimePartIsReadMinimally() {
+        int[] parts = {12};
+        FetchGroup fetchGroup = FetchGroup.MINIMAL
+            .addPartContent(new MimePath(parts), FetchGroup.MINIMAL_MASK);
+        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
+            .isEqualTo(MessageMapper.FetchType.Full);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnFullWhenMimePartHeadersIsRead() {
+        int[] parts = {12};
+        FetchGroup fetchGroup = FetchGroup.MINIMAL
+            .addPartContent(new MimePath(parts), FetchGroup.HEADERS_MASK);
+        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
+            .isEqualTo(MessageMapper.FetchType.Full);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnFullWhenMimePartBodyIsRead() {
+        int[] parts = {12};
+        FetchGroup fetchGroup = FetchGroup.MINIMAL
+            .addPartContent(new MimePath(parts), FetchGroup.BODY_CONTENT_MASK);
+        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
+            .isEqualTo(MessageMapper.FetchType.Full);
+    }
+
+    @Test
+    void getFetchTypeShouldReturnFullWhenMimePartIsFullyRead() {
+        int[] parts = {12};
+        FetchGroup fetchGroup = FetchGroup.MINIMAL
+            .addPartContent(new MimePath(parts), FetchGroup.FULL_CONTENT_MASK);
+        assertThat(FetchGroupConverter.getFetchType(fetchGroup))
+            .isEqualTo(MessageMapper.FetchType.Full);
+    }
+}
\ 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