Search in sources :

Example 46 with Document

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());
}
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 47 with Document

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/"));
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 48 with Document

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/"));
}
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 49 with Document

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);
}
Also used : DocChangeRule(com.xpn.xwiki.notify.DocChangeRule) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Mock(org.jmock.Mock) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 50 with Document

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());
}
Also used : Inject(javax.inject.Inject) XWiki(com.xpn.xwiki.XWiki) Attachment(com.xpn.xwiki.api.Attachment) Provider(javax.inject.Provider) Component(org.xwiki.component.annotation.Component) DocumentReference(org.xwiki.model.reference.DocumentReference) Collection(java.util.Collection) XWikiContext(com.xpn.xwiki.XWikiContext) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) Document(com.xpn.xwiki.api.Document) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) Document(com.xpn.xwiki.api.Document)

Aggregations

Document (com.xpn.xwiki.api.Document)97 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)60 XWikiException (com.xpn.xwiki.XWikiException)41 XWikiRestException (org.xwiki.rest.XWikiRestException)40 DocumentReference (org.xwiki.model.reference.DocumentReference)37 BaseObject (com.xpn.xwiki.objects.BaseObject)24 Test (org.junit.Test)23 WebApplicationException (javax.ws.rs.WebApplicationException)22 ArrayList (java.util.ArrayList)16 Attachment (com.xpn.xwiki.api.Attachment)14 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)14 Vector (java.util.Vector)12 Link (org.xwiki.rest.model.jaxb.Link)10 XWikiContext (com.xpn.xwiki.XWikiContext)9 AbstractComponentTest (com.celements.common.test.AbstractComponentTest)7 Date (java.util.Date)7 XWiki (com.xpn.xwiki.api.XWiki)6 RangeIterable (org.xwiki.rest.internal.RangeIterable)6 Object (org.xwiki.rest.model.jaxb.Object)6 XWiki (com.xpn.xwiki.XWiki)5