Search in sources :

Example 41 with Document

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

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

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();
}
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 44 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_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();
}
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 45 with Document

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