use of com.xpn.xwiki.api.Document in project celements-blog by celements.
the class ArticleEngineHQLTest method testGetBlogArticles_getArchivedArticles_archiveBeforePublishBeforeToday.
@Test
public void testGetBlogArticles_getArchivedArticles_archiveBeforePublishBeforeToday() 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();
DocumentReference blogConfigDocRef = new DocumentReference(context.getDatabase(), artSpace, "BlogConfig");
XWikiDocument confxDoc = createMock(XWikiDocument.class);
Document confDoc = createMock(Document.class);
expect(xwiki.getDocument(eq(blogConfigDocRef), same(context))).andReturn(confxDoc).atLeastOnce();
expect(xwiki.getDocument(eq(articleDocRef), same(context))).andReturn(xdoc).atLeastOnce();
expect(xwiki.getDocument(eq(articleFN), same(context))).andReturn(xdoc).atLeastOnce();
expect(blogServiceMock.getBlogPageByBlogSpace(eq("ArtSpace"))).andReturn(confxDoc).atLeastOnce();
expect(blogServiceMock.getBlogDocRefByBlogSpace(eq("ArtSpace"))).andReturn(blogConfigDocRef).atLeastOnce();
expect(xwiki.getSpacePreference(eq("default_language"), eq(artSpace), eq(""), same(context))).andReturn("de").once();
expect(confDoc.hasProgrammingRights()).andReturn(true).atLeastOnce();
expect(confDoc.hasAccessLevel((String) anyObject())).andReturn(true).atLeastOnce();
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(10, 11, 31));
obj.setDateValue("archivedate", new Date(0, 0, 1));
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(1, 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_empty.
@Test
public void testHasMoreLink_in_translation_translation_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 extract");
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");
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("No translation in it but details 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_translation_no_extract_long_content.
@Test
public void testHasMoreLink_in_translation_no_extract_long_content() 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", getLoremIpsum());
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;
assertTrue("Only details (to long for extract) 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_long_content.
@Test
public void testHasMoreLink_in_default_lang_no_extract_long_content() 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", getLoremIpsum());
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;
assertTrue("Only details (to long for extract) but no extract in de.", article.hasMoreLink("de", false));
verifyAll();
}
use of com.xpn.xwiki.api.Document in project celements-blog by celements.
the class ArticleTest method testHasMoreLink_in_default_lang.
@Test
public void testHasMoreLink_in_default_lang() 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);
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("Details in de.", article.hasMoreLink("de", false));
verifyAll();
}
Aggregations