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());
}
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);
}
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();
}
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();
}
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();
}
Aggregations