use of org.xwiki.mail.MimeBodyPartFactory in project xwiki-platform by xwiki.
the class HTMLMimeBodyPartFactoryTest method createWhenHTMLAndEmbeddedImagesAndNormalAttachments.
@Test
public void createWhenHTMLAndEmbeddedImagesAndNormalAttachments() throws Exception {
Attachment normalAttachment = mock(Attachment.class, "normalAttachment");
when(normalAttachment.getFilename()).thenReturn("attachment1.png");
Attachment embeddedAttachment = mock(Attachment.class, "embeddedAttachment");
when(embeddedAttachment.getFilename()).thenReturn("embeddedAttachment.png");
MimeBodyPart embeddedAttachmentBodyPart = mock(MimeBodyPart.class);
MimeBodyPartFactory attachmentBodyPartFactory = this.mocker.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, Attachment.class), "xwiki/attachment");
when(attachmentBodyPartFactory.create(same(embeddedAttachment), any(Map.class))).thenReturn(embeddedAttachmentBodyPart);
MimeBodyPart normalAttachmentBodyPart = mock(MimeBodyPart.class);
when(attachmentBodyPartFactory.create(same(normalAttachment), any(Map.class))).thenReturn(normalAttachmentBodyPart);
MimeBodyPart bodyPart = this.mocker.getComponentUnderTest().create("<p>html... <img src='cid:embeddedAttachment.png'/></p>", Collections.<String, Object>singletonMap("attachments", Arrays.asList(normalAttachment, embeddedAttachment)));
MimeMultipart multipart = (MimeMultipart) bodyPart.getContent();
assertEquals(2, multipart.getCount());
MimeMultipart htmlMultipart = (MimeMultipart) multipart.getBodyPart(0).getContent();
assertEquals(2, htmlMultipart.getCount());
assertEquals("<p>html... <img src='cid:embeddedAttachment.png'/></p>", htmlMultipart.getBodyPart(0).getContent());
assertSame(embeddedAttachmentBodyPart, htmlMultipart.getBodyPart(1));
assertSame(normalAttachmentBodyPart, multipart.getBodyPart(1));
}
use of org.xwiki.mail.MimeBodyPartFactory in project xwiki-platform by xwiki.
the class HTMLMimeBodyPartFactoryTest method createWhenHTMLAndEmbeddedImages.
@Test
public void createWhenHTMLAndEmbeddedImages() throws Exception {
Attachment attachment = mock(Attachment.class);
MimeBodyPart attachmentBodyPart = mock(MimeBodyPart.class);
MimeBodyPartFactory attachmentBodyPartFactory = this.mocker.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, Attachment.class), "xwiki/attachment");
when(attachmentBodyPartFactory.create(same(attachment), any(Map.class))).thenReturn(attachmentBodyPart);
MimeBodyPart bodyPart = this.mocker.getComponentUnderTest().create("<p>some html</p>", Collections.<String, Object>singletonMap("attachments", Arrays.asList(attachment)));
MimeMultipart multipart = ((MimeMultipart) bodyPart.getContent());
assertEquals(2, multipart.getCount());
assertEquals("<p>some html</p>", multipart.getBodyPart(0).getContent());
assertSame(attachmentBodyPart, multipart.getBodyPart(1));
}
use of org.xwiki.mail.MimeBodyPartFactory in project xwiki-platform by xwiki.
the class HTMLMimeBodyPartFactoryTest method createWhenHTMLAndAlternateTextContent.
@Test
public void createWhenHTMLAndAlternateTextContent() throws Exception {
MimeBodyPart textBodyPart = mock(MimeBodyPart.class);
MimeBodyPartFactory defaultBodyPartFactory = this.mocker.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, String.class));
when(defaultBodyPartFactory.create(eq("some text"), any(Map.class))).thenReturn(textBodyPart);
MimeBodyPart bodyPart = this.mocker.getComponentUnderTest().create("<p>some html</p>", Collections.<String, Object>singletonMap("alternate", "some text"));
MimeMultipart multipart = ((MimeMultipart) bodyPart.getContent());
assertEquals(2, multipart.getCount());
assertSame(textBodyPart, multipart.getBodyPart(0));
assertEquals("<p>some html</p>", multipart.getBodyPart(1).getContent());
}
use of org.xwiki.mail.MimeBodyPartFactory in project xwiki-platform by xwiki.
the class TemplateMimeBodyPartFactoryTest method createWithoutAttachment.
@Test
public void createWithoutAttachment() throws Exception {
MimeBodyPartFactory<String> htmlMimeBodyPartFactory = this.mocker.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, String.class), "text/html");
this.mocker.getComponentUnderTest().create(this.documentReference, Collections.<String, Object>singletonMap("velocityVariables", new HashMap<String, String>()));
verify(htmlMimeBodyPartFactory).create("Hello <b>John Doe</b> <br />john@doe.com", Collections.<String, Object>singletonMap("alternate", "Hello John Doe, john@doe.com"));
}
use of org.xwiki.mail.MimeBodyPartFactory in project xwiki-platform by xwiki.
the class TemplateMimeBodyPartFactoryTest method createWithAttachmentAndTemplateAttachments.
@Test
public void createWithAttachmentAndTemplateAttachments() throws Exception {
MimeBodyPartFactory<String> htmlMimeBodyPartFactory = this.mocker.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, String.class), "text/html");
Attachment attachment1 = mock(Attachment.class, "attachment1");
Map<String, Object> bodyPartParameters = new HashMap<>();
bodyPartParameters.put("velocityVariables", new HashMap<String, String>());
bodyPartParameters.put("attachments", Collections.singletonList(attachment1));
bodyPartParameters.put("includeTemplateAttachments", true);
// Mock the retrieval and conversion of attachments from the Template document
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
XWikiDocument xwikiDocument = mock(XWikiDocument.class);
when(dab.getDocumentInstance(this.documentReference)).thenReturn(xwikiDocument);
XWikiAttachment xwikiAttachment = mock(XWikiAttachment.class);
when(xwikiDocument.getAttachmentList()).thenReturn(Collections.singletonList(xwikiAttachment));
AttachmentConverter attachmentConverter = this.mocker.getInstance(AttachmentConverter.class);
Attachment attachment2 = mock(Attachment.class, "attachment2");
when(attachmentConverter.convert(Collections.singletonList(xwikiAttachment))).thenReturn(Collections.singletonList(attachment2));
this.mocker.getComponentUnderTest().create(this.documentReference, bodyPartParameters);
Map<String, Object> htmlParameters = new HashMap<>();
htmlParameters.put("alternate", "Hello John Doe, john@doe.com");
htmlParameters.put("attachments", Arrays.asList(attachment1, attachment2));
verify(htmlMimeBodyPartFactory).create("Hello <b>John Doe</b> <br />john@doe.com", htmlParameters);
}
Aggregations