Search in sources :

Example 26 with DefaultParameterizedType

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());
    }
}
Also used : HashMap(java.util.HashMap) MessagingException(javax.mail.MessagingException) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Provider(javax.inject.Provider) Test(org.junit.Test)

Example 27 with DefaultParameterizedType

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));
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) MimeBodyPartFactory(org.xwiki.mail.MimeBodyPartFactory) Attachment(com.xpn.xwiki.api.Attachment) MimeBodyPart(javax.mail.internet.MimeBodyPart) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 28 with DefaultParameterizedType

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));
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) MimeBodyPartFactory(org.xwiki.mail.MimeBodyPartFactory) Attachment(com.xpn.xwiki.api.Attachment) MimeBodyPart(javax.mail.internet.MimeBodyPart) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 29 with DefaultParameterizedType

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());
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) MimeBodyPartFactory(org.xwiki.mail.MimeBodyPartFactory) MimeBodyPart(javax.mail.internet.MimeBodyPart) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 30 with DefaultParameterizedType

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"));
}
Also used : HashMap(java.util.HashMap) MimeBodyPartFactory(org.xwiki.mail.MimeBodyPartFactory) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Test(org.junit.Test)

Aggregations

DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)104 Test (org.junit.Test)44 Before (org.junit.Before)32 Provider (javax.inject.Provider)27 DocumentReference (org.xwiki.model.reference.DocumentReference)24 XWikiContext (com.xpn.xwiki.XWikiContext)19 ComponentManager (org.xwiki.component.manager.ComponentManager)19 ExecutionContext (org.xwiki.context.ExecutionContext)17 ExtendedURL (org.xwiki.url.ExtendedURL)15 Execution (org.xwiki.context.Execution)14 HashMap (java.util.HashMap)13 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)13 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)12 ResourceReferenceSerializer (org.xwiki.resource.ResourceReferenceSerializer)10 VfsResourceReference (org.xwiki.vfs.VfsResourceReference)10 Properties (java.util.Properties)9 MimeBodyPartFactory (org.xwiki.mail.MimeBodyPartFactory)9 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)8 XWiki (com.xpn.xwiki.XWiki)7 File (java.io.File)7