Search in sources :

Example 36 with Attachment

use of com.xpn.xwiki.api.Attachment in project celements-blog by celements.

the class NewsletterAttachmentServiceTest method testGetEmbedAttList_emptyList.

@Test
public void testGetEmbedAttList_emptyList() {
    VelocityContext vcontext = (VelocityContext) getContext().get("vcontext");
    List<Attachment> list = new ArrayList<>();
    vcontext.put("nlEmbedAttList", list);
    assertNull(service.getAttachmentList(true));
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Attachment(com.xpn.xwiki.api.Attachment) Test(org.junit.Test)

Example 37 with Attachment

use of com.xpn.xwiki.api.Attachment in project celements-blog by celements.

the class NewsletterAttachmentServiceTest method testGetImageURL_embedded.

@Test
public void testGetImageURL_embedded() throws Exception {
    DocumentReference docRef = new DocumentReference(getContext().getDatabase(), "Test", "Img");
    String expectedResult = "cid:file.jpg";
    XWikiDocument doc = createMockAndAddToDefault(XWikiDocument.class);
    XWikiAttachment att = new XWikiAttachment();
    expect(attService.getAttachmentNameEqual(same(doc), eq("file.jpg"))).andReturn(att).anyTimes();
    expect(attService.getApiAttachment(same(att))).andReturn(new Attachment(new Document(doc, getContext()), att, getContext()));
    expect(xwiki.getDocument(eq(docRef), same(getContext()))).andReturn(doc).once();
    replayDefault();
    assertEquals(expectedResult, service.getImageURL("Test.Img;file.jpg", true));
    verifyDefault();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Attachment(com.xpn.xwiki.api.Attachment) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 38 with Attachment

use of com.xpn.xwiki.api.Attachment in project celements-blog by celements.

the class NewsletterAttachmentServiceTest method testClearAttachmentList.

@Test
public void testClearAttachmentList() throws Exception {
    DocumentReference docRef = new DocumentReference(getContext().getDatabase(), "Test", "Img");
    XWikiDocument doc = createMockAndAddToDefault(XWikiDocument.class);
    XWikiAttachment att = new XWikiAttachment();
    expect(attService.getAttachmentNameEqual(same(doc), eq("file.pdf"))).andReturn(att).anyTimes();
    expect(attService.getApiAttachment(same(att))).andReturn(new Attachment(new Document(doc, getContext()), att, getContext()));
    expect(xwiki.getDocument(eq(docRef), same(getContext()))).andReturn(doc).once();
    replayDefault();
    service.addAttachment("Test.Img;file.pdf");
    service.clearAttachmentList();
    verifyDefault();
    List<Attachment> atts = service.getAttachmentList(false);
    assertTrue("clearAttachmentList must clear the list.", (atts == null) || atts.isEmpty());
    List<Attachment> atts2 = service.getAttachmentList(true);
    assertTrue("clearAttachmentList must clear both list.", (atts2 == null) || atts2.isEmpty());
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Attachment(com.xpn.xwiki.api.Attachment) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

Attachment (com.xpn.xwiki.api.Attachment)38 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)24 Test (org.junit.Test)21 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)15 Document (com.xpn.xwiki.api.Document)14 DocumentReference (org.xwiki.model.reference.DocumentReference)14 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)8 MimeBodyPart (javax.mail.internet.MimeBodyPart)7 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)6 MimeBodyPartFactory (org.xwiki.mail.MimeBodyPartFactory)6 XWikiContext (com.xpn.xwiki.XWikiContext)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 MimeMultipart (javax.mail.internet.MimeMultipart)5 InputStream (java.io.InputStream)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiAttachmentContent (com.xpn.xwiki.doc.XWikiAttachmentContent)3 File (java.io.File)3 IOException (java.io.IOException)3