use of com.xpn.xwiki.api.Attachment in project celements-blog by celements.
the class NewsletterAttachmentServiceTest method testClearAttachmentList_add_afterClear.
@Test
public void testClearAttachmentList_add_afterClear() 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())).anyTimes();
expect(xwiki.getDocument(eq(docRef), same(getContext()))).andReturn(doc).atLeastOnce();
replayDefault();
service.addAttachment("Test.Img;file.pdf");
service.clearAttachmentList();
service.addAttachment("Test.Img;file.pdf");
verifyDefault();
List<Attachment> atts = service.getAttachmentList(false);
assertNotNull(atts);
assertEquals(1, atts.size());
}
use of com.xpn.xwiki.api.Attachment in project celements-blog by celements.
the class NewsletterAttachmentServiceTest method testGetEmbedAttList_validList.
@Test
public void testGetEmbedAttList_validList() {
VelocityContext vcontext = (VelocityContext) getContext().get("vcontext");
List<Attachment> list = new ArrayList<>();
Attachment att = new Attachment(null, new XWikiAttachment(), getContext());
list.add(att);
vcontext.put("nlEmbedAttList", list);
List<Attachment> resList = service.getAttachmentList(true);
assertNotNull(resList);
assertSame(att, resList.get(0));
}
use of com.xpn.xwiki.api.Attachment in project celements-blog by celements.
the class NewsletterAttachmentServiceTest method testEmbedImagesInContent_inner.
@Test
public void testEmbedImagesInContent_inner() 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.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();
String imgTag = "<img class=\"abc\" src=\"/download/Test/Img/file.jpg?bla=123\" />";
String content = "Test text with " + imgTag + " image included";
Set<String> tags = new HashSet<>();
tags.add(imgTag);
replayDefault();
String result = service.embedImagesInContent(content, tags);
verifyDefault();
assertTrue(result, result.contains("src=\"cid:file.jpg\""));
assertFalse(result, result.contains("/download/"));
}
use of com.xpn.xwiki.api.Attachment in project celements-blog by celements.
the class NewsletterAttachmentServiceTest method testExtendAttachmentList.
@Test
public void testExtendAttachmentList() {
Attachment att = new Attachment(null, null, getContext());
service.extendAttachmentList(att, "nlEmbedNoImgAttList");
List<Attachment> atts = service.getAttachmentList(false);
assertNotNull(atts);
assertEquals(1, atts.size());
assertSame(att, atts.get(0));
}
use of com.xpn.xwiki.api.Attachment in project celements-blog by celements.
the class NewsletterAttachmentServiceTest method testEmbedImagesInContent.
@Test
public void testEmbedImagesInContent() 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.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();
String imgTag = "<img class=\"abc\" src=\"/download/Test/Img/file.jpg?bla=123\" />";
String content = "Test text with " + imgTag + " image included";
replayDefault();
String result = service.embedImagesInContent(content);
verifyDefault();
assertTrue(result, result.contains("src=\"cid:file.jpg\""));
assertFalse(result, result.contains("/download/"));
}
Aggregations