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 aad93ebb28fd0f53f6e4e25b5911f4abf3b50790
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Fri Jan 17 17:03:47 2020 +0700

    JAMES-2997 Renable AttachmentMapperTest
---
 .../mail/CassandraAttachmentMapperTest.java        |   3 -
 .../inmemory/mail/MemoryAttachmentMapperTest.java  |   3 -
 .../store/mail/model/AttachmentMapperTest.java     | 294 +++++++--------------
 3 files changed, 100 insertions(+), 200 deletions(-)

diff --git 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapperTest.java
 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapperTest.java
index 4edf53e..8935848 100644
--- 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapperTest.java
+++ 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapperTest.java
@@ -31,7 +31,6 @@ import 
org.apache.james.mailbox.store.mail.model.AttachmentMapperTest;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
 class CassandraAttachmentMapperTest extends AttachmentMapperTest {
-/*
     private static final CassandraModule MODULES = 
CassandraModule.aggregateModules(
         CassandraAttachmentModule.MODULE,
         CassandraBlobModule.MODULE);
@@ -49,6 +48,4 @@ class CassandraAttachmentMapperTest extends 
AttachmentMapperTest {
     protected MessageId generateMessageId() {
         return new CassandraMessageId.Factory().generate();
     }
-    
- */
 }
diff --git 
a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/MemoryAttachmentMapperTest.java
 
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/MemoryAttachmentMapperTest.java
index e3ece02..f65fc8f 100644
--- 
a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/MemoryAttachmentMapperTest.java
+++ 
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/MemoryAttachmentMapperTest.java
@@ -25,7 +25,6 @@ import org.apache.james.mailbox.store.mail.AttachmentMapper;
 import org.apache.james.mailbox.store.mail.model.AttachmentMapperTest;
 
 class MemoryAttachmentMapperTest extends AttachmentMapperTest {
-/*
     @Override
     protected AttachmentMapper createAttachmentMapper() {
         return new InMemoryAttachmentMapper();
@@ -35,6 +34,4 @@ class MemoryAttachmentMapperTest extends AttachmentMapperTest 
{
     protected MessageId generateMessageId() {
         return new InMemoryMessageId.Factory().generate();
     }
-
- */
 }
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentMapperTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentMapperTest.java
index 93f4c21..9299fe3 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentMapperTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentMapperTest.java
@@ -22,6 +22,7 @@ package org.apache.james.mailbox.store.mail.model;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
+import java.io.ByteArrayInputStream;
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.List;
@@ -31,7 +32,9 @@ import 
org.apache.james.mailbox.exception.AttachmentNotFoundException;
 import org.apache.james.mailbox.model.Attachment;
 import org.apache.james.mailbox.model.AttachmentId;
 import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.ParsedAttachment;
 import org.apache.james.mailbox.store.mail.AttachmentMapper;
+import org.assertj.core.api.SoftAssertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -40,7 +43,6 @@ import com.google.common.collect.ImmutableList;
 import reactor.core.publisher.Mono;
 
 public abstract class AttachmentMapperTest {
-    /*
     private static final AttachmentId UNKNOWN_ATTACHMENT_ID = 
AttachmentId.from("unknown");
     private static final Username OWNER = Username.of("owner");
     private static final Username ADDITIONAL_OWNER = 
Username.of("additionalOwner");
@@ -69,40 +71,43 @@ public abstract class AttachmentMapperTest {
     }
 
     @Test
+    void storeAttachmentForOwnerShouldReturnSuppliedInformation() throws 
Exception {
+        String content = "content";
+        byte[] bytes = "payload".getBytes(StandardCharsets.UTF_8);
+
+        Attachment stored = 
Mono.from(attachmentMapper.storeAttachmentForOwner(content, new 
ByteArrayInputStream(bytes), OWNER)).block();
+
+        SoftAssertions.assertSoftly(solftly -> {
+            solftly.assertThat(stored.getSize()).isEqualTo(bytes.length);
+            solftly.assertThat(stored.getType()).isEqualTo(content);
+        });
+    }
+
+    @Test
     void getAttachmentShouldReturnTheAttachmentWhenReferenced() throws 
Exception {
-        //Given
-        Attachment expected = Attachment.builder()
-                .bytes("payload".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        AttachmentId attachmentId = expected.getAttachmentId();
-        Mono.from(attachmentMapper.storeAttachmentForOwner(expected, 
OWNER)).block();
-        //When
-        Attachment attachment = attachmentMapper.getAttachment(attachmentId);
-        //Then
-        assertThat(attachment).isEqualTo(expected);
+        String content = "content";
+        byte[] bytes = "payload".getBytes(StandardCharsets.UTF_8);
+
+        Attachment stored = 
Mono.from(attachmentMapper.storeAttachmentForOwner(content, new 
ByteArrayInputStream(bytes), OWNER)).block();
+
+        Attachment attachment = 
attachmentMapper.getAttachment(stored.getAttachmentId());
+
+        SoftAssertions.assertSoftly(solftly -> {
+            
solftly.assertThat(attachment.getAttachmentId()).isEqualTo(stored.getAttachmentId());
+            solftly.assertThat(attachment.getSize()).isEqualTo(bytes.length);
+            solftly.assertThat(attachment.getType()).isEqualTo(content);
+        });
     }
 
     @Test
-    void getAttachmentShouldReturnTheAttachmentsWhenMultipleStored() throws 
Exception {
-        //Given
-        Attachment expected1 = Attachment.builder()
-                .bytes("payload1".getBytes(StandardCharsets.UTF_8))
-                .type("content1")
-                .build();
-        Attachment expected2 = Attachment.builder()
-                .bytes("payload2".getBytes(StandardCharsets.UTF_8))
-                .type("content2")
-                .build();
-        AttachmentId attachmentId1 = expected1.getAttachmentId();
-        AttachmentId attachmentId2 = expected2.getAttachmentId();
-        //When
-        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(expected1, 
expected2), generateMessageId());
-        //Then
-        Attachment attachment1 = attachmentMapper.getAttachment(attachmentId1);
-        Attachment attachment2 = attachmentMapper.getAttachment(attachmentId2);
-        assertThat(attachment1).isEqualTo(expected1);
-        assertThat(attachment2).isEqualTo(expected2);
+    void loadAttachmentContentShouldReturnStoredContent() throws Exception {
+        String content = "content";
+        byte[] bytes = "payload".getBytes(StandardCharsets.UTF_8);
+
+        Attachment stored = 
Mono.from(attachmentMapper.storeAttachmentForOwner(content, new 
ByteArrayInputStream(bytes), OWNER)).block();
+
+        
assertThat(attachmentMapper.loadAttachmentContent(stored.getAttachmentId()))
+            .hasSameContentAs(new ByteArrayInputStream(bytes));
     }
 
     @Test
@@ -121,24 +126,15 @@ public abstract class AttachmentMapperTest {
     @Test
     void getAttachmentsShouldReturnTheAttachmentsWhenSome() {
         //Given
-        Attachment expected = Attachment.builder()
-                .bytes("payload".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        AttachmentId attachmentId = expected.getAttachmentId();
-        Mono.from(attachmentMapper.storeAttachmentForOwner(expected, 
OWNER)).block();
-
-        Attachment expected2 = Attachment.builder()
-                .bytes("payload2".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        AttachmentId attachmentId2 = expected2.getAttachmentId();
-        Mono.from(attachmentMapper.storeAttachmentForOwner(expected2, 
OWNER)).block();
-
-        //When
-        List<Attachment> attachments = 
attachmentMapper.getAttachments(ImmutableList.of(attachmentId, attachmentId2));
-        //Then
-        assertThat(attachments).contains(expected, expected2);
+        String content1 = "content";
+        byte[] bytes1 = "payload".getBytes(StandardCharsets.UTF_8);
+        Attachment stored1 = 
Mono.from(attachmentMapper.storeAttachmentForOwner(content1, new 
ByteArrayInputStream(bytes1), OWNER)).block();
+        String content2 = "content";
+        byte[] bytes2 = "payload".getBytes(StandardCharsets.UTF_8);
+        Attachment stored2 = 
Mono.from(attachmentMapper.storeAttachmentForOwner(content2, new 
ByteArrayInputStream(bytes2), OWNER)).block();
+
+        
assertThat(attachmentMapper.getAttachments(ImmutableList.of(stored1.getAttachmentId(),
 stored2.getAttachmentId())))
+            .contains(stored1, stored2);
     }
 
     @Test
@@ -150,172 +146,84 @@ public abstract class AttachmentMapperTest {
 
     @Test
     void getOwnerMessageIdsShouldReturnEmptyWhenStoredWithoutMessageId() 
throws Exception {
-        //Given
-        Attachment attachment = Attachment.builder()
-                .bytes("payload".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        AttachmentId attachmentId = attachment.getAttachmentId();
-        Mono.from(attachmentMapper.storeAttachmentForOwner(attachment, 
OWNER)).block();
-        
-        //When
-        Collection<MessageId> messageIds = 
attachmentMapper.getRelatedMessageIds(attachmentId);
-        //Then
-        assertThat(messageIds).isEmpty();
+        String content = "content";
+        byte[] bytes = "payload".getBytes(StandardCharsets.UTF_8);
+        Attachment stored = 
Mono.from(attachmentMapper.storeAttachmentForOwner(content, new 
ByteArrayInputStream(bytes), OWNER)).block();
+
+        
assertThat(attachmentMapper.getRelatedMessageIds(stored.getAttachmentId())).isEmpty();
     }
 
     @Test
-    void getOwnerMessageIdsShouldReturnMessageIdWhenStoredWithMessageId() 
throws Exception {
-        //Given
-        Attachment attachment = Attachment.builder()
-                .bytes("payload".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        AttachmentId attachmentId = attachment.getAttachmentId();
+    void getRelatedMessageIdsShouldReturnMessageIdWhenStoredWithMessageId() 
throws Exception {
         MessageId messageId = generateMessageId();
-        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(attachment), 
messageId);
-        
-        //When
-        Collection<MessageId> messageIds = 
attachmentMapper.getRelatedMessageIds(attachmentId);
-        //Then
-        assertThat(messageIds).containsOnly(messageId);
-    }
+        AttachmentId attachmentId = 
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(ParsedAttachment.builder()
+            .contentType("content")
+            .content(new 
ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)))
+            .noName()
+            .noCid()
+            .inline(false)), messageId)
+            .get(0).getAttachmentId();
 
-    @Test
-    void getOwnerMessageIdsShouldReturnTwoMessageIdsWhenStoredTwice() throws 
Exception {
-        //Given
-        Attachment attachment = Attachment.builder()
-                .bytes("payload".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        AttachmentId attachmentId = attachment.getAttachmentId();
-        MessageId messageId1 = generateMessageId();
-        MessageId messageId2 = generateMessageId();
-        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(attachment), 
messageId1);
-        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(attachment), 
messageId2);
-        
-        //When
-        Collection<MessageId> messageIds = 
attachmentMapper.getRelatedMessageIds(attachmentId);
-        //Then
-        assertThat(messageIds).containsOnly(messageId1, messageId2);
+        
assertThat(attachmentMapper.getRelatedMessageIds(attachmentId)).containsOnly(messageId);
     }
 
     @Test
     void getOwnerMessageIdsShouldReturnOnlyMatchingMessageId() throws 
Exception {
-        //Given
-        Attachment attachment = Attachment.builder()
-                .bytes("payload".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        Attachment otherAttachment = Attachment.builder()
-                .bytes("something different".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        AttachmentId attachmentId = attachment.getAttachmentId();
         MessageId messageId1 = generateMessageId();
-        MessageId messageId2 = generateMessageId();
-        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(attachment), 
messageId1);
-        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(otherAttachment), 
messageId2);
-        
-        //When
-        Collection<MessageId> messageIds = 
attachmentMapper.getRelatedMessageIds(attachmentId);
-        //Then
-        assertThat(messageIds).containsOnly(messageId1);
-    }
-
-    @Test
-    void getOwnerMessageIdsShouldReturnOnlyOneMessageIdWhenStoredTwice() 
throws Exception {
-        //Given
-        Attachment attachment = Attachment.builder()
-                .bytes("payload".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        AttachmentId attachmentId = attachment.getAttachmentId();
-        MessageId messageId = generateMessageId();
-        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(attachment), 
messageId);
-        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(attachment), 
messageId);
-        
-        //When
-        Collection<MessageId> messageIds = 
attachmentMapper.getRelatedMessageIds(attachmentId);
-        //Then
-        assertThat(messageIds).containsOnly(messageId);
-    }
+        AttachmentId attachmentId1 = 
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(ParsedAttachment.builder()
+            .contentType("content")
+            .content(new 
ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)))
+            .noName()
+            .noCid()
+            .inline(false)), messageId1)
+            .get(0).getAttachmentId();
+        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(ParsedAttachment.builder()
+            .contentType("content")
+            .content(new 
ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)))
+            .noName()
+            .noCid()
+            .inline(false)), generateMessageId())
+            .get(0).getAttachmentId();
 
-    @Test
-    void 
getOwnerMessageIdsShouldReturnMessageIdForTwoAttachmentsWhenBothStoredAtTheSameTime()
 throws Exception {
-        //Given
-        Attachment attachment = Attachment.builder()
-                .bytes("payload".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        Attachment attachment2 = Attachment.builder()
-                .bytes("other payload".getBytes(StandardCharsets.UTF_8))
-                .type("content")
-                .build();
-        AttachmentId attachmentId = attachment.getAttachmentId();
-        AttachmentId attachmentId2 = attachment2.getAttachmentId();
-        MessageId messageId = generateMessageId();
-        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(attachment, 
attachment2), messageId);
-        
-        //When
-        Collection<MessageId> messageIds = 
attachmentMapper.getRelatedMessageIds(attachmentId);
-        Collection<MessageId> messageIds2 = 
attachmentMapper.getRelatedMessageIds(attachmentId2);
-        //Then
-        assertThat(messageIds).isEqualTo(messageIds2);
+        
assertThat(attachmentMapper.getRelatedMessageIds(attachmentId1)).containsOnly(messageId1);
     }
 
     @Test
     void getOwnersShouldBeRetrievedWhenExplicitlySpecified() throws Exception {
-        //Given
-        Attachment attachment = Attachment.builder()
-            .bytes("payload".getBytes(StandardCharsets.UTF_8))
-            .type("content")
-            .build();
-
-        AttachmentId attachmentId = attachment.getAttachmentId();
-        Mono.from(attachmentMapper.storeAttachmentForOwner(attachment, 
OWNER)).block();
-
-        //When
-        Collection<Username> expectedOwners = ImmutableList.of(OWNER);
-        Collection<Username> actualOwners = 
attachmentMapper.getOwners(attachmentId);
-        //Then
-        assertThat(actualOwners).containsOnlyElementsOf(expectedOwners);
+        String content = "content";
+        byte[] bytes = "payload".getBytes(StandardCharsets.UTF_8);
+        Attachment stored = 
Mono.from(attachmentMapper.storeAttachmentForOwner(content, new 
ByteArrayInputStream(bytes), OWNER)).block();
+
+        Collection<Username> actualOwners = 
attachmentMapper.getOwners(stored.getAttachmentId());
+
+        assertThat(actualOwners).containsOnly(OWNER);
     }
 
     @Test
-    void getOwnersShouldReturnEmptyWhenMessageIdReferenced() throws Exception {
-        //Given
-        Attachment attachment = Attachment.builder()
-            .bytes("payload".getBytes(StandardCharsets.UTF_8))
-            .type("content")
-            .build();
+    void getOwnersShouldNotReturnUnrelatedOwners() throws Exception {
+        String content = "content";
+        byte[] bytes = "payload".getBytes(StandardCharsets.UTF_8);
+        Attachment stored = 
Mono.from(attachmentMapper.storeAttachmentForOwner(content, new 
ByteArrayInputStream(bytes), OWNER)).block();
+        String content2 = "content";
+        byte[] bytes2 = "payload".getBytes(StandardCharsets.UTF_8);
+        Attachment stored2 = 
Mono.from(attachmentMapper.storeAttachmentForOwner(content2, new 
ByteArrayInputStream(bytes2), ADDITIONAL_OWNER)).block();
 
-        AttachmentId attachmentId = attachment.getAttachmentId();
-        
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(attachment), 
generateMessageId());
+        Collection<Username> actualOwners = 
attachmentMapper.getOwners(stored.getAttachmentId());
 
-        //When
-        Collection<Username> actualOwners = 
attachmentMapper.getOwners(attachmentId);
-        //Then
-        assertThat(actualOwners).isEmpty();
+        assertThat(actualOwners).containsOnly(OWNER);
     }
 
     @Test
-    void getOwnersShouldReturnAllOwners() throws Exception {
-        //Given
-        Attachment attachment = Attachment.builder()
-            .bytes("payload".getBytes(StandardCharsets.UTF_8))
-            .type("content")
-            .build();
-
-        AttachmentId attachmentId = attachment.getAttachmentId();
-        Mono.from(attachmentMapper.storeAttachmentForOwner(attachment, 
OWNER)).block();
-        Mono.from(attachmentMapper.storeAttachmentForOwner(attachment, 
ADDITIONAL_OWNER)).block();
-
-        //When
-        Collection<Username> expectedOwners = ImmutableList.of(OWNER, 
ADDITIONAL_OWNER);
-        Collection<Username> actualOwners = 
attachmentMapper.getOwners(attachmentId);
-        //Then
-        assertThat(actualOwners).containsOnlyElementsOf(expectedOwners);
+    void getOwnersShouldReturnEmptyWhenMessageIdReferenced() throws Exception {
+        AttachmentId attachmentId = 
attachmentMapper.storeAttachmentsForMessage(ImmutableList.of(ParsedAttachment.builder()
+            .contentType("content")
+            .content(new 
ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)))
+            .noName()
+            .noCid()
+            .inline(false)), generateMessageId())
+            .get(0).getAttachmentId();
+
+        assertThat(attachmentMapper.getOwners(attachmentId)).isEmpty();
     }
 
     @Test
@@ -324,6 +232,4 @@ public abstract class AttachmentMapperTest {
 
         assertThat(actualOwners).isEmpty();
     }
-
-     */
 }


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

Reply via email to