Search in sources :

Example 91 with Document

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

the class NewsletterAttachmentServiceTest method testAddAttachment.

@Test
public void testAddAttachment() 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");
    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 92 with Document

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

the class NewsletterAttachmentServiceTest method testGetAttachmentForFullname.

@Test
public void testGetAttachmentForFullname() 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();
    replayDefault();
    assertEquals(att.getFilename(), service.getAttachmentForFullname("Test.Img;file.jpg").getFilename());
    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 93 with Document

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

the class NewsletterAttachmentServiceTest method testEmbedImagesInContent_inner_externalURLwww.

@Test
public void testEmbedImagesInContent_inner_externalURLwww() 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=\"www.test.com/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/"));
    assertFalse(result, result.contains("www"));
}
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 94 with Document

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

the class NewsletterAttachmentServiceTest method testEmbedImagesInContent_inner_externalURLhttp.

@Test
public void testEmbedImagesInContent_inner_externalURLhttp() 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=\"http://www.test.com/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/"));
    assertFalse(result, result.contains("http"));
}
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 95 with Document

use of com.xpn.xwiki.api.Document 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)

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