use of com.xpn.xwiki.api.Document 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.Document 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.Document 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/"));
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class XWikiNotificationTest method testSaveDocumentFromAPIUsesCorrectOriginalDocument.
/**
* We only verify here that the saveDocument API calls the Notification Manager. Detailed tests of the notification
* classes are implemented in the notification package.
*/
public void testSaveDocumentFromAPIUsesCorrectOriginalDocument() throws Exception {
Mock mockRights = mock(XWikiRightService.class);
mockRights.stubs().method("hasAccessLevel").will(returnValue(true));
this.xwiki.setRightService((XWikiRightService) mockRights.proxy());
TestListener listener = new TestListener();
listener.expectedNewStatus = false;
getNotificationManager().addGeneralRule(new DocChangeRule(listener));
XWikiDocument original = new XWikiDocument(new DocumentReference("WikiDescriptor", "Space", "Page"));
original.setNew(false);
original.setContent("Old content");
XWikiDocument document = new XWikiDocument(new DocumentReference("WikiDescriptor", "Space", "Page"));
document.setContent("New content");
document.setOriginalDocument(original);
Document api = new Document(document, getContext());
api.save();
assertTrue("Listener not called", listener.hasListenerBeenCalled);
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class MailTemplateImageAttachmentsExtractor method getImages.
/**
* @param documentReference the reference of the document
* @return all images contained in the attachments of the given document
* @throws Exception if an error occurs
*/
public Collection<Attachment> getImages(DocumentReference documentReference) throws Exception {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
Document document = new Document(xwiki.getDocument(documentReference, context), context);
return document.getAttachmentList().stream().filter(att -> att.isImage()).collect(Collectors.toList());
}
Aggregations