Search in sources :

Example 86 with Document

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

the class ZipExplorerTest method testGetFileTreeList.

public void testGetFileTreeList() throws Exception {
    XWikiDocument document = createXWikiDocumentWithZipFileAttachment();
    List<ListItem> entries = this.plugin.getFileTreeList(new Document(document, null), "zipfile.zip", null);
    Assert.assertEquals(3, entries.size());
    Assert.assertEquals("Directory/", entries.get(0).getId());
    Assert.assertEquals("Directory", entries.get(0).getValue());
    Assert.assertEquals("", entries.get(0).getParent());
    Assert.assertEquals("Directory/File.txt", entries.get(1).getId());
    Assert.assertEquals("File.txt", entries.get(1).getValue());
    Assert.assertEquals("Directory/", entries.get(1).getParent());
    Assert.assertEquals("File2.txt", entries.get(2).getId());
    Assert.assertEquals("File2.txt", entries.get(2).getValue());
    Assert.assertEquals("", entries.get(2).getParent());
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ListItem(com.xpn.xwiki.objects.classes.ListItem) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument)

Example 87 with Document

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

the class ArticleEngineHQLTest method testGetBlogArticles_getArchivedArticles_notYetArchived.

@Test
public void testGetBlogArticles_getArchivedArticles_notYetArchived() throws XWikiException {
    String artSpace = "ArtSpace";
    DocumentReference articleDocRef = new DocumentReference("xwikidb", artSpace, "Article");
    XWikiDocument xdoc = createMock(XWikiDocument.class);
    Document doc = new Document(xdoc, context);
    List<Object> artName = new ArrayList<>();
    String articleFN = artSpace + ".Article";
    artName.add(articleFN);
    expect(xwiki.search(eq(getAllArticlesHQL(artSpace)), same(context))).andReturn(artName).once();
    XWikiDocument confxDoc = createMock(XWikiDocument.class);
    Document confDoc = createMock(Document.class);
    expect(xwiki.getDocument(eq(articleFN), same(context))).andReturn(xdoc).atLeastOnce();
    expect(blogServiceMock.getBlogPageByBlogSpace(eq("ArtSpace"))).andReturn(confxDoc).atLeastOnce();
    expect(xwiki.getSpacePreference(eq("default_language"), eq(artSpace), eq(""), same(context))).andReturn("de").once();
    expect(confxDoc.newDocument(same(context))).andReturn(confDoc).atLeastOnce();
    expect(xdoc.newDocument(same(context))).andReturn(doc);
    BaseObject obj = new BaseObject();
    obj.setDocumentReference(articleDocRef);
    obj.setStringValue("lang", "de");
    obj.setDateValue("publishdate", new Date(8089, 0, 1));
    obj.setDateValue("archivedate", new Date(8099, 11, 31));
    obj.setStringValue("title", "the title");
    obj.setStringValue("content", "the content");
    Vector<BaseObject> objVec = new Vector<>();
    objVec.add(obj);
    DocumentReference articleClassRef = new DocumentReference("xwikidb", "XWiki", "ArticleClass");
    expect(xdoc.clone()).andReturn(xdoc).atLeastOnce();
    expect(xdoc.resolveClassReference(eq("XWiki.ArticleClass"))).andReturn(articleClassRef);
    expect(xdoc.getXObjects(eq(articleClassRef))).andReturn(objVec);
    expect(xdoc.getDocumentReference()).andReturn(articleDocRef).atLeastOnce();
    expect(xdoc.getSpace()).andReturn(artSpace).atLeastOnce();
    replayDefault(confDoc, confxDoc, xdoc);
    List<Article> result = engine.getBlogArticles(artSpace, Collections.<String>emptyList(), "de", true, false, false, true, true, true, true, false, true, true);
    assertEquals("0 Articles expected, but received " + result.size(), 0, result.size());
    verifyDefault(confDoc, confxDoc, xdoc);
}
Also used : ArrayList(java.util.ArrayList) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Date(java.util.Date) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObject(com.xpn.xwiki.objects.BaseObject) Vector(java.util.Vector) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 88 with Document

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

the class ArticleTest method testHasMoreLink_in_translation_translation_not_empty.

@Test
public void testHasMoreLink_in_translation_translation_not_empty() throws XWikiException, EmptyArticleException {
    Document articleApiDoc = new Document(articleDoc, context);
    expect(articleDoc.newDocument(same(context))).andReturn(articleApiDoc);
    Vector<BaseObject> articleObjs = new Vector<>();
    BaseObject articleDe = new BaseObject();
    articleDe.setLargeStringValue("extract", "deutscher extract");
    articleDe.setLargeStringValue("content", "deutscher content");
    articleDe.setStringValue("lang", "de");
    articleObjs.add(articleDe);
    BaseObject articleFr = new BaseObject();
    articleFr.setStringValue("lang", "fr");
    articleObjs.add(articleFr);
    BaseObject articleIt = new BaseObject();
    articleIt.setStringValue("lang", "it");
    articleIt.setLargeStringValue("extract", "Ital extract");
    articleIt.setLargeStringValue("content", "Ital content");
    articleObjs.add(articleIt);
    DocumentReference articleClassRef = new DocumentReference("xwikidb", "XWiki", "ArticleClass");
    expect(articleDoc.clone()).andReturn(articleDoc).atLeastOnce();
    expect(articleDoc.resolveClassReference(eq("XWiki.ArticleClass"))).andReturn(articleClassRef);
    expect(articleDoc.getXObjects(eq(articleClassRef))).andReturn(articleObjs);
    DocumentReference articleDocRef = new DocumentReference("xwikidb", "News", "Bla");
    expect(articleDoc.getDocumentReference()).andReturn(articleDocRef).atLeastOnce();
    expect(xwiki.getSpacePreference(eq("default_language"), eq("News"), eq(""), same(context))).andReturn("de");
    expect(blogServiceMock.getBlogPageByBlogSpace(eq("Main"))).andReturn(null).anyTimes();
    replayAll();
    article = new Article(articleDoc, context);
    article.injected_blogService = blogServiceMock;
    assertTrue("Has translation in it.", article.hasMoreLink("it", false));
    verifyAll();
}
Also used : Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Vector(java.util.Vector) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) AbstractComponentTest(com.celements.common.test.AbstractComponentTest) Test(org.junit.Test)

Example 89 with Document

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

the class ArticleTest method testHasMoreLink_in_translation_no_extract.

@Test
public void testHasMoreLink_in_translation_no_extract() throws XWikiException, EmptyArticleException {
    // expect(articleDoc.getSpace()).andReturn("News");
    Document articleApiDoc = new Document(articleDoc, context);
    expect(articleDoc.newDocument(same(context))).andReturn(articleApiDoc);
    Vector<BaseObject> articleObjs = new Vector<>();
    BaseObject articleDe = new BaseObject();
    articleDe.setLargeStringValue("content", "deutscher content");
    articleDe.setStringValue("lang", "de");
    articleObjs.add(articleDe);
    BaseObject articleIt = new BaseObject();
    articleIt.setStringValue("lang", "it");
    articleObjs.add(articleIt);
    DocumentReference articleClassRef = new DocumentReference("xwikidb", "XWiki", "ArticleClass");
    expect(articleDoc.clone()).andReturn(articleDoc).atLeastOnce();
    expect(articleDoc.resolveClassReference(eq("XWiki.ArticleClass"))).andReturn(articleClassRef);
    expect(articleDoc.getXObjects(eq(articleClassRef))).andReturn(articleObjs);
    DocumentReference articleDocRef = new DocumentReference("xwikidb", "News", "Bla");
    expect(articleDoc.getDocumentReference()).andReturn(articleDocRef).atLeastOnce();
    expect(xwiki.getSpacePreference(eq("default_language"), eq("News"), eq(""), same(context))).andReturn("de");
    expect(blogServiceMock.getBlogPageByBlogSpace(eq("Main"))).andReturn(null).anyTimes();
    replayAll();
    article = new Article(articleDoc, context);
    article.injected_blogService = blogServiceMock;
    assertFalse("Only details (short) but no extract in de.", article.hasMoreLink("it", false));
    verifyAll();
}
Also used : Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Vector(java.util.Vector) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) AbstractComponentTest(com.celements.common.test.AbstractComponentTest) Test(org.junit.Test)

Example 90 with Document

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

the class ArticleTest method testHasMoreLink_in_default_lang_no_extract.

@Test
public void testHasMoreLink_in_default_lang_no_extract() throws XWikiException, EmptyArticleException {
    Document articleApiDoc = new Document(articleDoc, context);
    expect(articleDoc.newDocument(same(context))).andReturn(articleApiDoc);
    Vector<BaseObject> articleObjs = new Vector<>();
    BaseObject articleDe = new BaseObject();
    articleDe.setLargeStringValue("content", "deutscher content");
    articleDe.setStringValue("lang", "de");
    articleObjs.add(articleDe);
    DocumentReference articleClassRef = new DocumentReference("xwikidb", "XWiki", "ArticleClass");
    expect(articleDoc.clone()).andReturn(articleDoc).atLeastOnce();
    expect(articleDoc.resolveClassReference(eq("XWiki.ArticleClass"))).andReturn(articleClassRef);
    expect(articleDoc.getXObjects(eq(articleClassRef))).andReturn(articleObjs);
    DocumentReference articleDocRef = new DocumentReference("xwikidb", "News", "Bla");
    expect(articleDoc.getDocumentReference()).andReturn(articleDocRef).atLeastOnce();
    expect(xwiki.getSpacePreference(eq("default_language"), eq("News"), eq(""), same(context))).andReturn("de");
    expect(blogServiceMock.getBlogPageByBlogSpace(eq("Main"))).andReturn(null).anyTimes();
    replayAll();
    article = new Article(articleDoc, context);
    article.injected_blogService = blogServiceMock;
    assertFalse("Only details (short) but no extract in de.", article.hasMoreLink("de", false));
    verifyAll();
}
Also used : Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Vector(java.util.Vector) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) AbstractComponentTest(com.celements.common.test.AbstractComponentTest) 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