james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject svn commit: r1719389 [2/2] - in /james/project/trunk/server/protocols/jmap/src: main/java/org/apache/james/jmap/model/ main/java/org/apache/james/jmap/model/message/ test/java/org/apache/james/jmap/model/
Date Fri, 11 Dec 2015 12:34:26 GMT
Added: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/RootMimePartContainerBuilder.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/RootMimePartContainerBuilder.java?rev=1719389&view=auto
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/RootMimePartContainerBuilder.java
(added)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/RootMimePartContainerBuilder.java
Fri Dec 11 12:34:26 2015
@@ -0,0 +1,89 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.model.message;
+
+import org.apache.james.mailbox.store.extractor.TextExtractor;
+import org.apache.james.mime4j.stream.Field;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+
+public class RootMimePartContainerBuilder implements MimePartContainerBuilder {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(RootMimePartContainerBuilder.class);
+
+    private MimePart rootMimePart;
+
+    @Override
+    public MimePart build() {
+        return rootMimePart;
+    }
+
+    @Override public MimePartContainerBuilder using(TextExtractor textExtractor) {
+        return this;
+    }
+
+    @Override
+    public MimePartContainerBuilder addToHeaders(Field field) {
+        LOGGER.warn("Trying to add headers to the Root MimePart container");
+        return this;
+    }
+
+    @Override
+    public MimePartContainerBuilder addBodyContent(InputStream bodyContent) {
+        LOGGER.warn("Trying to add body content to the Root MimePart container");
+        return this;
+    }
+
+    @Override
+    public MimePartContainerBuilder addChild(MimePart mimePart) {
+        if (rootMimePart == null) {
+            rootMimePart = mimePart;
+        } else {
+            LOGGER.warn("Trying to add several children to the Root MimePart container");
+        }
+        return this;
+    }
+
+    @Override
+    public MimePartContainerBuilder addFileName(String fileName) {
+        LOGGER.warn("Trying to add fineName to the Root MimePart container");
+        return this;
+    }
+
+    @Override
+    public MimePartContainerBuilder addMediaType(String mediaType) {
+        LOGGER.warn("Trying to add media type to the Root MimePart container");
+        return this;
+    }
+
+    @Override
+    public MimePartContainerBuilder addSubType(String subType) {
+        LOGGER.warn("Trying to add sub type to the Root MimePart container");
+        return this;
+    }
+
+    @Override
+    public MimePartContainerBuilder addContentDisposition(String contentDisposition) {
+        LOGGER.warn("Trying to add content disposition to the Root MimePart container");
+        return this;
+    }
+}

Added: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java?rev=1719389&view=auto
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java
(added)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java
Fri Dec 11 12:34:26 2015
@@ -0,0 +1,92 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.jmap.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.junit.Test;
+
+public class AttachmentTest {
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenBlobIdIsNull() {
+        Attachment.builder().build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenTypeIsNull() {
+        Attachment.builder().blobId("blobId").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenNameIsNull() {
+        Attachment.builder().blobId("blobId").type("type").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenSizeIsNull() {
+        Attachment.builder().blobId("blobId").type("type").name("name").build();
+    }
+    
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenBlobIdIsEmpty() {
+        Attachment.builder().blobId("").type("type").name("name").size(123).build();
+    }
+    
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenTypeIsEmpty() {
+        Attachment.builder().blobId("blobId").type("").name("name").size(123).build();
+    }
+    
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenNameIsEmpty() {
+        Attachment.builder().blobId("blobId").type("type").name("").size(123).build();
+    }
+    
+    @Test
+    public void buildShouldWorkWhenMandatoryFieldsArePresent() {
+        Attachment expected = new Attachment("blobId", "type", "name", 123, Optional.empty(),
false, Optional.empty(), Optional.empty());
+        Attachment tested = Attachment.builder()
+            .blobId("blobId")
+            .type("type")
+            .name("name")
+            .size(123)
+            .build();
+        assertThat(tested).isEqualToComparingFieldByField(expected);
+    }
+
+    @Test
+    public void buildShouldWorkWithAllFieldsSet() {
+        Attachment expected = new Attachment("blobId", "type", "name", 123, Optional.of("cid"),
true, Optional.of(456L), Optional.of(789L));
+        Attachment tested = Attachment.builder()
+            .blobId("blobId")
+            .type("type")
+            .name("name")
+            .size(123)
+            .cid("cid")
+            .isInline(true)
+            .width(456)
+            .height(789)
+            .build();
+        assertThat(tested).isEqualToComparingFieldByField(expected);
+    }
+
+}

Added: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/EmailerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/EmailerTest.java?rev=1719389&view=auto
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/EmailerTest.java
(added)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/EmailerTest.java
Fri Dec 11 12:34:26 2015
@@ -0,0 +1,62 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.jmap.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+public class EmailerTest {
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenNameIsNull() {
+        Emailer.builder().build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenEmailIsNull() {
+        Emailer.builder().build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenNameIsEmpty() {
+        Emailer.builder().name("").email("email@domain").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenEmailIsEmpty() {
+        Emailer.builder().name("name").email("").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenEmailWithoutArobase() {
+        Emailer.builder().name("name").email("email.without.arobase").build();
+    }
+    
+    @Test
+    public void buildShouldWork() {
+        Emailer expected = new Emailer("name", "user@domain");
+        Emailer emailer = Emailer.builder()
+            .name("name")
+            .email("user@domain")
+            .build();
+        assertThat(emailer).isEqualToComparingFieldByField(expected);
+    }
+
+}

Added: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java?rev=1719389&view=auto
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
(added)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
Fri Dec 11 12:34:26 2015
@@ -0,0 +1,220 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.jmap.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.ZonedDateTime;
+import java.util.Optional;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public class MessageTest {
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenIdIsNull() {
+        Message.builder().build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenIdIsEmpty() {
+        Message.builder().id("").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenBlobIdIsNull() {
+        Message.builder().id("id").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenBlobIdIsEmpty() {
+        Message.builder().id("id").blobId("").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenThreadIdIsNull() {
+        Message.builder().id("id").blobId("blobId").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenThreadIdIsEmpty() {
+        Message.builder().id("id").blobId("blobId").threadId("").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenMailboxIdsIsNull() {
+        Message.builder().id("id").blobId("blobId").threadId("threadId").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenHeadersIsNull() {
+        Message.builder().id("id").blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenSubjectIsNull() {
+        Message.builder().id("id").blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()).build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenSubjectIsEmpty() {
+        Message.builder().id("id").blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+            .subject("").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenSizeIsNull() {
+        Message.builder().id("id").blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+            .subject("subject").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenDateIsNull() {
+        Message.builder().id("id").blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+            .subject("subject").size(123).build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenPreviewIsNull() {
+        Message.builder().id("id").blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+            .subject("subject").size(123).date(ZonedDateTime.now()).build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenPreviewIsEmpty() {
+        Message.builder().id("id").blobId("blobId").threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+            .subject("subject").size(123).date(ZonedDateTime.now()).preview("").build();
+    }
+
+    @Test
+    public void buildShouldWorkWhenMandatoryFieldsArePresent() {
+        ZonedDateTime currentDate = ZonedDateTime.now();
+        Message expected = new Message("id", "blobId", "threadId", ImmutableList.of("mailboxId"),
Optional.empty(), false, false, false, false, false, ImmutableMap.of("key", "value"), Optional.empty(),
+                ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(),
"subject", currentDate, 123, "preview", Optional.empty(), Optional.empty(), ImmutableList.of(),
ImmutableMap.of());
+        Message tested = Message.builder()
+                .id("id")
+                .blobId("blobId")
+                .threadId("threadId")
+                .mailboxIds(ImmutableList.of("mailboxId"))
+                .headers(ImmutableMap.of("key", "value"))
+                .subject("subject")
+                .size(123)
+                .date(currentDate)
+                .preview("preview")
+                .build();
+        assertThat(tested).isEqualToComparingFieldByField(expected);
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenAttachedMessageIsNotMatchingAttachments() {
+        Attachment simpleAttachment = Attachment.builder().blobId("blobId").type("type").name("name").size(123).build();
+        ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment);
+        SubMessage simpleMessage = SubMessage.builder()
+                .headers(ImmutableMap.of("key", "value"))
+                .subject("subject")
+                .date(ZonedDateTime.now())
+                .build();
+        ImmutableMap<String, SubMessage> attachedMessages = ImmutableMap.of("differentBlobId",
simpleMessage);
+        Message.builder()
+            .id("id")
+            .blobId("blobId")
+            .threadId("threadId")
+            .mailboxIds(ImmutableList.of("mailboxId"))
+            .headers(ImmutableMap.of("key", "value"))
+            .subject("subject")
+            .size(123)
+            .date(ZonedDateTime.now())
+            .preview("preview")
+            .attachments(attachments)
+            .attachedMessages(attachedMessages)
+            .build();
+    }
+
+    @Test
+    public void buildShouldWorkWhenAllFieldsArePresent() {
+        Emailer from = Emailer.builder().name("from").email("from@domain").build();
+        ImmutableList<Emailer> to = ImmutableList.of(Emailer.builder().name("to").email("to@domain").build());
+        ImmutableList<Emailer> cc = ImmutableList.of(Emailer.builder().name("cc").email("cc@domain").build());
+        ImmutableList<Emailer> bcc = ImmutableList.of(Emailer.builder().name("bcc").email("bcc@domain").build());
+        ImmutableList<Emailer> replyTo = ImmutableList.of(Emailer.builder().name("replyTo").email("replyTo@domain").build());
+        ZonedDateTime currentDate = ZonedDateTime.now();
+        Attachment simpleAttachment = Attachment.builder().blobId("blobId").type("type").name("name").size(123).build();
+        ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment);
+        SubMessage simpleMessage = SubMessage.builder()
+                .headers(ImmutableMap.of("key", "value"))
+                .subject("subject")
+                .date(currentDate)
+                .build();
+        ImmutableMap<String, SubMessage> attachedMessages = ImmutableMap.of("blobId",
simpleMessage);
+        Message expected = new Message(
+                "id",
+                "blobId",
+                "threadId",
+                ImmutableList.of("mailboxId"),
+                Optional.of("inReplyToMessageId"), 
+                true,
+                true,
+                true,
+                true,
+                true,
+                ImmutableMap.of("key", "value"),
+                Optional.of(from),
+                to,
+                cc,
+                bcc,
+                replyTo,
+                "subject",
+                currentDate,
+                123,
+                "preview",
+                Optional.of("textBody"), 
+                Optional.of("htmlBody"),
+                attachments,
+                attachedMessages);
+        Message tested = Message.builder()
+            .id("id")
+            .blobId("blobId")
+            .threadId("threadId")
+            .mailboxIds(ImmutableList.of("mailboxId"))
+            .inReplyToMessageId("inReplyToMessageId")
+            .isUnread(true)
+            .isFlagged(true)
+            .isAnswered(true)
+            .isDraft(true)
+            .hasAttachment(true)
+            .headers(ImmutableMap.of("key", "value"))
+            .from(from)
+            .to(to)
+            .cc(cc)
+            .bcc(bcc)
+            .replyTo(replyTo)
+            .subject("subject")
+            .date(currentDate)
+            .size(123)
+            .preview("preview")
+            .textBody("textBody")
+            .htmlBody("htmlBody")
+            .attachments(attachments)
+            .attachedMessages(attachedMessages)
+            .build();
+        assertThat(tested).isEqualToComparingFieldByField(expected);
+    }
+}

Added: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SubMessageTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SubMessageTest.java?rev=1719389&view=auto
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SubMessageTest.java
(added)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SubMessageTest.java
Fri Dec 11 12:34:26 2015
@@ -0,0 +1,129 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.jmap.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.ZonedDateTime;
+import java.util.Optional;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public class SubMessageTest {
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenHeadersIsNull() {
+        SubMessage.builder().build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenSubjectIsNull() {
+        SubMessage.builder().headers(ImmutableMap.of()).build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenSubjectIsEmpty() {
+        SubMessage.builder().headers(ImmutableMap.of()).subject("").build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenDateIsNull() {
+        SubMessage.builder().headers(ImmutableMap.of()).subject("subject").build();
+    }
+
+    @Test
+    public void buildShouldWorkWhenMandatoryFieldsArePresent() {
+        ZonedDateTime currentDate = ZonedDateTime.now();
+        SubMessage expected = new SubMessage(ImmutableMap.of("key", "value"), Optional.empty(),
ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(),
+                "subject", currentDate, Optional.empty(), Optional.empty(), ImmutableList.of(),
ImmutableMap.of());
+        SubMessage tested = SubMessage.builder()
+            .headers(ImmutableMap.of("key", "value"))
+            .subject("subject")
+            .date(currentDate)
+            .build();
+        assertThat(tested).isEqualToComparingFieldByField(expected);
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenAttachedMessageIsNotMatchingAttachments() {
+        Attachment simpleAttachment = Attachment.builder().blobId("blobId").type("type").name("name").size(123).build();
+        ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment);
+        SubMessage simpleMessage = SubMessage.builder()
+                .headers(ImmutableMap.of("key", "value"))
+                .subject("subject")
+                .date(ZonedDateTime.now())
+                .build();
+        ImmutableMap<String, SubMessage> attachedMessages = ImmutableMap.of("differentBlobId",
simpleMessage);
+        SubMessage.builder()
+            .headers(ImmutableMap.of("key", "value"))
+            .subject("subject")
+            .date(ZonedDateTime.now())
+            .attachments(attachments)
+            .attachedMessages(attachedMessages)
+            .build();
+    }
+
+    @Test
+    public void buildShouldWorkWhenAllFieldsArePresent() {
+        Emailer from = Emailer.builder().name("from").email("from@domain").build();
+        ImmutableList<Emailer> to = ImmutableList.of(Emailer.builder().name("to").email("to@domain").build());
+        ImmutableList<Emailer> cc = ImmutableList.of(Emailer.builder().name("cc").email("cc@domain").build());
+        ImmutableList<Emailer> bcc = ImmutableList.of(Emailer.builder().name("bcc").email("bcc@domain").build());
+        ImmutableList<Emailer> replyTo = ImmutableList.of(Emailer.builder().name("replyTo").email("replyTo@domain").build());
+        ZonedDateTime currentDate = ZonedDateTime.now();
+        Attachment simpleAttachment = Attachment.builder().blobId("blobId").type("type").name("name").size(123).build();
+        ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment);
+        SubMessage simpleMessage = SubMessage.builder()
+                .headers(ImmutableMap.of("key", "value"))
+                .subject("subject")
+                .date(currentDate)
+                .build();
+        ImmutableMap<String, SubMessage> attachedMessages = ImmutableMap.of("blobId",
simpleMessage);
+        SubMessage expected = new SubMessage(
+                ImmutableMap.of("key", "value"),
+                Optional.of(from),
+                to,
+                cc,
+                bcc,
+                replyTo,
+                "subject",
+                currentDate,
+                Optional.of("textBody"),
+                Optional.of("htmlBody"),
+                attachments,
+                attachedMessages);
+        SubMessage tested = SubMessage.builder()
+            .headers(ImmutableMap.of("key", "value"))
+            .from(from)
+            .to(to)
+            .cc(cc)
+            .bcc(bcc)
+            .replyTo(replyTo)
+            .subject("subject")
+            .date(currentDate)
+            .textBody("textBody")
+            .htmlBody("htmlBody")
+            .attachments(attachments)
+            .attachedMessages(attachedMessages)
+            .build();
+        assertThat(tested).isEqualToComparingFieldByField(expected);
+    }
+}



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


Mime
View raw message