use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class GroupMimeMessageFactoryTest method createMessageWhenNotExistingMimeMessageFactory.
@Test
public void createMessageWhenNotExistingMimeMessageFactory() throws Exception {
DocumentReference groupReference = new DocumentReference("wiki", "space", "page");
Map<String, Object> parameters = new HashMap<>();
parameters.put("hint", "factoryHint");
parameters.put("source", "factorySource");
Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(this.mocker);
try {
this.mocker.getComponentUnderTest().createMessage(groupReference, parameters);
fail("Should have thrown an exception");
} catch (MessagingException expected) {
assertEquals("Failed to find a [MimeMessageFactory<MimeMessage>] for hint [factoryHint]", expected.getMessage());
}
}
use of org.xwiki.component.util.DefaultParameterizedType 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.component.util.DefaultParameterizedType 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.component.util.DefaultParameterizedType 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.component.util.DefaultParameterizedType 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"));
}
Aggregations