Search in sources :

Example 1 with Space

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

the class PageResourceTest method getFirstPage.

private Page getFirstPage() throws Exception {
    GetMethod getMethod = executeGet(getFullUri(WikisResource.class));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Wikis wikis = (Wikis) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(wikis.getWikis().size() > 0);
    Wiki wiki = wikis.getWikis().get(0);
    // Get a link to an index of spaces (http://localhost:8080/xwiki/rest/wikis/xwiki/spaces)
    Link spacesLink = getFirstLinkByRelation(wiki, Relations.SPACES);
    Assert.assertNotNull(spacesLink);
    getMethod = executeGet(spacesLink.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Spaces spaces = (Spaces) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(spaces.getSpaces().size() > 0);
    Space space = null;
    for (final Space s : spaces.getSpaces()) {
        if (this.space.equals(s.getName())) {
            space = s;
            break;
        }
    }
    // get the pages list for the space
    // eg: http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages
    Link pagesInSpace = getFirstLinkByRelation(space, Relations.PAGES);
    Assert.assertNotNull(pagesInSpace);
    getMethod = executeGet(pagesInSpace.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Pages pages = (Pages) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(pages.getPageSummaries().size() > 0);
    Link pageLink = null;
    for (final PageSummary ps : pages.getPageSummaries()) {
        if (this.pageName.equals(ps.getName())) {
            pageLink = getFirstLinkByRelation(ps, Relations.PAGE);
            Assert.assertNotNull(pageLink);
            break;
        }
    }
    Assert.assertNotNull(pageLink);
    getMethod = executeGet(pageLink.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Page page = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    return page;
}
Also used : Space(org.xwiki.rest.model.jaxb.Space) Pages(org.xwiki.rest.model.jaxb.Pages) Spaces(org.xwiki.rest.model.jaxb.Spaces) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Wikis(org.xwiki.rest.model.jaxb.Wikis) Wiki(org.xwiki.rest.model.jaxb.Wiki) Page(org.xwiki.rest.model.jaxb.Page) PageSummary(org.xwiki.rest.model.jaxb.PageSummary) Link(org.xwiki.rest.model.jaxb.Link) WikisResource(org.xwiki.rest.resources.wikis.WikisResource)

Example 2 with Space

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

the class PagesResourceTest method testRepresentation.

@Override
@Test
public void testRepresentation() throws Exception {
    GetMethod getMethod = executeGet(getFullUri(WikisResource.class));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Wikis wikis = (Wikis) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(wikis.getWikis().size() > 0);
    Wiki wiki = wikis.getWikis().get(0);
    Link link = getFirstLinkByRelation(wiki, Relations.SPACES);
    Assert.assertNotNull(link);
    getMethod = executeGet(link.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Spaces spaces = (Spaces) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(spaces.getSpaces().size() > 0);
    Space space = spaces.getSpaces().get(0);
    link = getFirstLinkByRelation(space, Relations.PAGES);
    Assert.assertNotNull(link);
    getMethod = executeGet(link.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Pages pages = (Pages) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(pages.getPageSummaries().size() > 0);
    checkLinks(pages);
}
Also used : Space(org.xwiki.rest.model.jaxb.Space) Pages(org.xwiki.rest.model.jaxb.Pages) Spaces(org.xwiki.rest.model.jaxb.Spaces) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Wikis(org.xwiki.rest.model.jaxb.Wikis) Wiki(org.xwiki.rest.model.jaxb.Wiki) Link(org.xwiki.rest.model.jaxb.Link) WikisResource(org.xwiki.rest.resources.wikis.WikisResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 3 with Space

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

the class SpacesResourceTest method testRepresentation.

@Override
@Test
public void testRepresentation() throws Exception {
    // Create a subspace
    createPageIfDoesntExist(Arrays.asList("SpaceA", "SpaceB", "SpaceC"), "MyPage", "some content");
    GetMethod getMethod = executeGet(getFullUri(WikisResource.class));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Wikis wikis = (Wikis) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(wikis.getWikis().size() > 0);
    Wiki wiki = wikis.getWikis().get(0);
    Link link = getFirstLinkByRelation(wiki, Relations.SPACES);
    Assert.assertNotNull(link);
    getMethod = executeGet(link.getHref());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Spaces spaces = (Spaces) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(spaces.getSpaces().size() > 0);
    boolean nestedSpaceFound = false;
    for (Space space : spaces.getSpaces()) {
        link = getFirstLinkByRelation(space, Relations.SEARCH);
        Assert.assertNotNull(link);
        checkLinks(space);
        if ("xwiki:SpaceA.SpaceB.SpaceC".equals(space.getId())) {
            Assert.assertEquals("SpaceC", space.getName());
            nestedSpaceFound = true;
        }
        /*
             * Check that in the returned spaces there are not spaces not visible to user Guest, for example the
             * "Scheduler" space
             */
        Assert.assertFalse(space.getName().equals("Scheduler"));
    }
    Assert.assertTrue(nestedSpaceFound);
}
Also used : Space(org.xwiki.rest.model.jaxb.Space) Spaces(org.xwiki.rest.model.jaxb.Spaces) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Wikis(org.xwiki.rest.model.jaxb.Wikis) Wiki(org.xwiki.rest.model.jaxb.Wiki) Link(org.xwiki.rest.model.jaxb.Link) WikisResource(org.xwiki.rest.resources.wikis.WikisResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 4 with Space

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

the class ModelFactory method toRestSpace.

public Space toRestSpace(URI baseUri, String wikiName, List<String> spaces, Document home) {
    Space space = this.objectFactory.createSpace();
    space.setId(Utils.getSpaceId(wikiName, spaces));
    space.setWiki(wikiName);
    // the name of the space is the last element of the spaces list
    space.setName(spaces.get(spaces.size() - 1));
    if (home != null) {
        space.setHome(home.getPrefixedFullName());
        space.setXwikiRelativeUrl(home.getURL("view"));
        space.setXwikiAbsoluteUrl(home.getExternalURL("view"));
    }
    String pagesUri = Utils.createURI(baseUri, PagesResource.class, wikiName, spaces).toString();
    Link pagesLink = this.objectFactory.createLink();
    pagesLink.setHref(pagesUri);
    pagesLink.setRel(Relations.PAGES);
    space.getLinks().add(pagesLink);
    if (home != null) {
        String homeUri = Utils.createURI(baseUri, PageResource.class, wikiName, spaces, home.getName()).toString();
        Link homeLink = this.objectFactory.createLink();
        homeLink.setHref(homeUri);
        homeLink.setRel(Relations.HOME);
        space.getLinks().add(homeLink);
    }
    String searchUri = Utils.createURI(baseUri, SpaceSearchResource.class, wikiName, spaces).toString();
    Link searchLink = this.objectFactory.createLink();
    searchLink.setHref(searchUri);
    searchLink.setRel(Relations.SEARCH);
    space.getLinks().add(searchLink);
    return space;
}
Also used : Space(org.xwiki.rest.model.jaxb.Space) PageResource(org.xwiki.rest.resources.pages.PageResource) PagesResource(org.xwiki.rest.resources.pages.PagesResource) Link(org.xwiki.rest.model.jaxb.Link) SpaceSearchResource(org.xwiki.rest.resources.spaces.SpaceSearchResource)

Aggregations

Link (org.xwiki.rest.model.jaxb.Link)4 Space (org.xwiki.rest.model.jaxb.Space)4 GetMethod (org.apache.commons.httpclient.methods.GetMethod)3 Spaces (org.xwiki.rest.model.jaxb.Spaces)3 Wiki (org.xwiki.rest.model.jaxb.Wiki)3 Wikis (org.xwiki.rest.model.jaxb.Wikis)3 WikisResource (org.xwiki.rest.resources.wikis.WikisResource)3 Test (org.junit.Test)2 Pages (org.xwiki.rest.model.jaxb.Pages)2 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)2 Page (org.xwiki.rest.model.jaxb.Page)1 PageSummary (org.xwiki.rest.model.jaxb.PageSummary)1 PageResource (org.xwiki.rest.resources.pages.PageResource)1 PagesResource (org.xwiki.rest.resources.pages.PagesResource)1 SpaceSearchResource (org.xwiki.rest.resources.spaces.SpaceSearchResource)1