Search in sources :

Example 6 with PageSummary

use of org.xwiki.rest.model.jaxb.PageSummary in project xwiki-platform by xwiki.

the class WikisResourceTest method testPages.

@Test
public void testPages() throws Exception {
    // Create a clean test page.
    this.testUtils.rest().delete(this.reference);
    this.testUtils.rest().savePage(this.reference);
    // Get all pages
    GetMethod getMethod = executeGet(String.format("%s", buildURI(WikiPagesResource.class, getWiki())));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Pages pages = (Pages) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(pages.getPageSummaries().size() > 0);
    for (PageSummary pageSummary : pages.getPageSummaries()) {
        checkLinks(pageSummary);
    }
    // Get all pages having a document name that contains "WebHome" (for all spaces)
    getMethod = executeGet(String.format("%s?name=" + this.pageName, buildURI(WikiPagesResource.class, getWiki())));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    pages = (Pages) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    List<PageSummary> pageSummaries = pages.getPageSummaries();
    Assert.assertTrue(pageSummaries.size() == 1);
    PageSummary pageSummary = pageSummaries.get(0);
    assertEquals(this.fullName, pageSummary.getFullName());
    checkLinks(pageSummary);
    // Get all pages having a document name that contains "WebHome" and a space with an "s" in its name.
    getMethod = executeGet(String.format("%s?name=" + this.pageName + "&space=" + this.fullName.charAt(2), buildURI(WikiPagesResource.class, getWiki())));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    pages = (Pages) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    pageSummaries = pages.getPageSummaries();
    Assert.assertTrue(pageSummaries.size() == 1);
    pageSummary = pageSummaries.get(0);
    assertEquals(this.fullName, pageSummary.getFullName());
    checkLinks(pageSummary);
}
Also used : Pages(org.xwiki.rest.model.jaxb.Pages) GetMethod(org.apache.commons.httpclient.methods.GetMethod) WikiPagesResource(org.xwiki.rest.resources.wikis.WikiPagesResource) PageSummary(org.xwiki.rest.model.jaxb.PageSummary) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 7 with PageSummary

use of org.xwiki.rest.model.jaxb.PageSummary in project xwiki-platform by xwiki.

the class ModelFactory method toRestPageSummary.

public PageSummary toRestPageSummary(URI baseUri, Document doc, Boolean withPrettyNames) throws XWikiException {
    PageSummary pageSummary = this.objectFactory.createPageSummary();
    toRestPageSummary(pageSummary, baseUri, doc, false, withPrettyNames);
    String pageUri = Utils.createURI(baseUri, PageResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName()).toString();
    Link pageLink = this.objectFactory.createLink();
    pageLink.setHref(pageUri);
    pageLink.setRel(Relations.PAGE);
    pageSummary.getLinks().add(pageLink);
    return pageSummary;
}
Also used : PageResource(org.xwiki.rest.resources.pages.PageResource) PageSummary(org.xwiki.rest.model.jaxb.PageSummary) Link(org.xwiki.rest.model.jaxb.Link)

Aggregations

PageSummary (org.xwiki.rest.model.jaxb.PageSummary)7 Pages (org.xwiki.rest.model.jaxb.Pages)5 GetMethod (org.apache.commons.httpclient.methods.GetMethod)4 Link (org.xwiki.rest.model.jaxb.Link)4 Test (org.junit.Test)3 PageResource (org.xwiki.rest.resources.pages.PageResource)3 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)3 Page (org.xwiki.rest.model.jaxb.Page)2 Document (com.xpn.xwiki.api.Document)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 URL (java.net.URL)1 Formatter (java.util.Formatter)1 HashMap (java.util.HashMap)1 PutMethod (org.apache.commons.httpclient.methods.PutMethod)1 Query (org.xwiki.query.Query)1 QueryException (org.xwiki.query.QueryException)1 XWikiRestException (org.xwiki.rest.XWikiRestException)1 Space (org.xwiki.rest.model.jaxb.Space)1 Spaces (org.xwiki.rest.model.jaxb.Spaces)1 Tag (org.xwiki.rest.model.jaxb.Tag)1