use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class ScriptingIntegrationTest method registerConfiguration.
@BeforeComponent
public void registerConfiguration() throws Exception {
MailSenderConfiguration configuration = new TestMailSenderConfiguration(this.mail.getSmtp().getPort(), null, null, new Properties());
this.componentManager.registerComponent(MailSenderConfiguration.class, configuration);
// Register a test Permission Checker that allows sending mails
ScriptServicePermissionChecker checker = mock(ScriptServicePermissionChecker.class);
this.componentManager.registerComponent(ScriptServicePermissionChecker.class, "test", checker);
// Set the current wiki in the Context
ModelContext modelContext = this.componentManager.registerMockComponent(ModelContext.class);
Mockito.when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("wiki"));
Provider<XWikiContext> xwikiContextProvider = this.componentManager.registerMockComponent(XWikiContext.TYPE_PROVIDER);
when(xwikiContextProvider.get()).thenReturn(Mockito.mock(XWikiContext.class));
this.componentManager.registerMockComponent(ExecutionContextManager.class);
this.componentManager.registerMockComponent(new DefaultParameterizedType(null, Copier.class, ExecutionContext.class));
EnvironmentConfiguration environmentConfiguration = this.componentManager.registerMockComponent(EnvironmentConfiguration.class);
when(environmentConfiguration.getPermanentDirectoryPath()).thenReturn(System.getProperty("java.io.tmpdir"));
this.componentManager.registerMockComponent(ConverterManager.class);
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class HTMLMimeBodyPartFactoryTest method createWhenHTMLAndAlternateTextAndEmbeddedImagesAndNormalAttachments.
@Test
public void createWhenHTMLAndAlternateTextAndEmbeddedImagesAndNormalAttachments() 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 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);
Map<String, Object> parameters = new HashMap<>();
parameters.put("attachments", Arrays.asList(normalAttachment, embeddedAttachment));
parameters.put("alternate", "some text");
MimeBodyPart bodyPart = this.mocker.getComponentUnderTest().create("<p>html... <img src='cid:embeddedAttachment.png'/></p>", parameters);
MimeMultipart multipart = (MimeMultipart) bodyPart.getContent();
assertEquals(2, multipart.getCount());
MimeMultipart alternateMultipart = (MimeMultipart) multipart.getBodyPart(0).getContent();
assertEquals(2, alternateMultipart.getCount());
assertSame(textBodyPart, alternateMultipart.getBodyPart(0));
MimeMultipart relatedMultipart = (MimeMultipart) alternateMultipart.getBodyPart(1).getContent();
assertEquals(2, relatedMultipart.getCount());
assertEquals("<p>html... <img src='cid:embeddedAttachment.png'/></p>", relatedMultipart.getBodyPart(0).getContent());
assertSame(embeddedAttachmentBodyPart, relatedMultipart.getBodyPart(1));
assertSame(normalAttachmentBodyPart, multipart.getBodyPart(1));
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class TemplateMimeBodyPartFactoryTest method createWithAttachment.
@Test
public void createWithAttachment() throws Exception {
MimeBodyPartFactory<String> htmlMimeBodyPartFactory = this.mocker.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, String.class), "text/html");
Attachment attachment = mock(Attachment.class);
List<Attachment> attachments = Collections.singletonList(attachment);
Map<String, Object> bodyPartParameters = new HashMap<>();
bodyPartParameters.put("velocityVariables", new HashMap<String, String>());
bodyPartParameters.put("attachments", attachments);
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", attachments);
verify(htmlMimeBodyPartFactory).create("Hello <b>John Doe</b> <br />john@doe.com", htmlParameters);
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class TemplateMimeBodyPartFactoryTest method createWithAttachmentAndTemplateAttachmentsWhenError.
@Test
public void createWithAttachmentAndTemplateAttachmentsWhenError() 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);
when(dab.getDocumentInstance(this.documentReference)).thenThrow(new Exception("error"));
try {
this.mocker.getComponentUnderTest().create(this.documentReference, bodyPartParameters);
fail("Should have thrown an exception here");
} catch (MessagingException expected) {
assertEquals("Failed to include attachments from the Mail Template [wiki:space.page]", expected.getMessage());
}
verifyNoMoreInteractions(htmlMimeBodyPartFactory);
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class TemplateMimeMessageFactoryTest method setUp.
@Before
public void setUp() throws Exception {
this.templateReference = new DocumentReference("templatewiki", "templatespace", "templatepage");
MailTemplateManager mailTemplateManager = this.mocker.getInstance(MailTemplateManager.class);
when(mailTemplateManager.evaluate(same(this.templateReference), eq("subject"), any(), any())).thenReturn("XWiki news");
MimeBodyPartFactory<DocumentReference> templateBodyPartFactory = this.mocker.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, DocumentReference.class), "xwiki/template");
this.mimeBodyPart = mock(MimeBodyPart.class);
when(templateBodyPartFactory.create(same(this.templateReference), any())).thenReturn(this.mimeBodyPart);
}
Aggregations