Re: [xwiki-devs] [xwiki-notifications] r15193 - in sandbox/xwiki-core-rest: . src/main/java/org/xwiki/rest src/main/java/org/xwiki/rest/model src/main/java/org/xwiki/rest/resources src/main/resources/META-INF/plexus src/test/java/org/xwiki/rest
On Thu, Jan 8, 2009 at 8:58 PM, SVN fmancinelli <[email protected]> wrote:
Author: fmancinelli Date: 2009-01-08 20:58:17 +0100 (Thu, 08 Jan 2009) New Revision: 15193
Added: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Wiki.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Wikis.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/WikisResource.java Modified: sandbox/xwiki-core-rest/.classpath
This file should not be versionned since it's managed/generated by M2Eclipse
sandbox/xwiki-core-rest/pom.xml sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/Constants.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/DomainObjectFactory.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/Utils.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/XWikiResource.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Relations.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Space.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/UriConstants.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/XStreamFactory.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/SpaceResource.java sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/SpacesResource.java sandbox/xwiki-core-rest/src/main/resources/META-INF/plexus/components.xml sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/PageResourceTest.java sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/PagesResourceTest.java sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/RootResourceTest.java sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/SpacesResourceTest.java Log: Added support for multiple wikis.
Modified: sandbox/xwiki-core-rest/.classpath =================================================================== --- sandbox/xwiki-core-rest/.classpath 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/.classpath 2009-01-08 19:58:17 UTC (rev 15193) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="src" output="target/classes" path="src/main/java"/> + <classpathentry kind="src" path="src/main/java"/> <classpathentry kind="src" path="src/main/resources"/> <classpathentry kind="src" path="src/test/java"/> <classpathentry kind="src" path="src/test/resources"/>
Modified: sandbox/xwiki-core-rest/pom.xml =================================================================== --- sandbox/xwiki-core-rest/pom.xml 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/pom.xml 2009-01-08 19:58:17 UTC (rev 15193) @@ -91,6 +91,14 @@ <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <dependencies> <dependency>
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/Constants.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/Constants.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/Constants.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -13,7 +13,7 @@
/* These are relevant parameter names that are used in URI templates. */ public static final String WIKI_NAME_PARAMETER = "wikiName"; - + public static final String SPACE_NAME_PARAMETER = "spaceName";
public static final String PAGE_NAME_PARAMETER = "pageName";
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/DomainObjectFactory.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/DomainObjectFactory.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/DomainObjectFactory.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -1,6 +1,7 @@ package org.xwiki.rest;
import java.sql.Timestamp; +import java.util.ArrayList; import java.util.List;
import org.restlet.data.MediaType; @@ -12,7 +13,7 @@ import org.xwiki.rest.model.Relations; import org.xwiki.rest.model.Space; import org.xwiki.rest.model.Translations; -import org.xwiki.rest.model.UriConstants; +import org.xwiki.rest.model.Wikis; import org.xwiki.rest.model.XWikiRoot; import org.xwiki.rest.resources.PageResource; import org.xwiki.rest.resources.PageTranslationResource; @@ -22,7 +23,9 @@ import org.xwiki.rest.resources.RootResource; import org.xwiki.rest.resources.SpaceResource; import org.xwiki.rest.resources.SpacesResource; +import org.xwiki.rest.resources.WikisResource;
+import com.xpn.xwiki.XWikiException; import com.xpn.xwiki.api.Document; import com.xpn.xwiki.doc.rcs.XWikiRCSNodeId;
@@ -37,9 +40,9 @@ XWikiRoot xwikiRoot = new XWikiRoot(xwikiApi.getVersion());
String fullUri = - String.format("%s%s", request.getRootRef(), registry.getUriPatternForResourceClass(SpacesResource.class)); + String.format("%s%s", request.getRootRef(), registry.getUriPatternForResourceClass(WikisResource.class)); Link link = new Link(Utils.formatUriTemplate(fullUri)); - link.setRel(Relations.SPACES); + link.setRel(Relations.WIKIS); xwikiRoot.addLink(link);
fullUri = @@ -52,15 +55,43 @@ return xwikiRoot; }
- public static Space createSpace(Request request, XWikiResourceClassRegistry resourceClassRegistry, - String wiki, String spaceName, String home, int numberOfPages) + public static Wikis createWikis(Request request, com.xpn.xwiki.XWiki xwiki, + com.xpn.xwiki.XWikiContext xwikiContext, XWikiResourceClassRegistry registry) { + Wikis wikis = new Wikis(); + + List<String> databaseNames = new ArrayList<String>(); + + try { + databaseNames = xwiki.getVirtualWikisDatabaseNames(xwikiContext); + } catch (XWikiException e) { + /* Ignore */ + } + + for (String databaseName : databaseNames) { + String fullUri = + String.format("%s%s", request.getRootRef(), registry + .getUriPatternForResourceClass(SpacesResource.class)); + Link link = new Link(Utils.formatUriTemplate(fullUri)); + link.setRel(Relations.SPACES); + wikis.addLink(link); + } + + return wikis; + + } + + public static Space createSpace(Request request, XWikiResourceClassRegistry resourceClassRegistry, String wiki, + String spaceName, String home, int numberOfPages) + { Space space = new Space(wiki, spaceName, home, numberOfPages);
String fullUri = String.format("%s%s", request.getRootRef(), resourceClassRegistry .getUriPatternForResourceClass(PagesResource.class)); - Link link = new Link(Utils.formatUriTemplate(fullUri, UriConstants.SPACE_NAME_PARAMETER, spaceName)); + Link link = + new Link(Utils.formatUriTemplate(fullUri, Constants.WIKI_NAME_PARAMETER, wiki, + Constants.SPACE_NAME_PARAMETER, spaceName)); link.setRel(Relations.PAGES);
space.addLink(link); @@ -99,8 +130,9 @@ String.format("%s%s", request.getRootRef(), resourceClassRegistry .getUriPatternForResourceClass(PageTranslationResource.class)); link = - new Link(Utils.formatUriTemplate(fullUri, UriConstants.SPACE_NAME_PARAMETER, doc.getSpace(), - UriConstants.PAGE_NAME_PARAMETER, doc.getName(), UriConstants.LANGUAGE_ID_PARAMETER, language)); + new Link(Utils.formatUriTemplate(fullUri, Constants.WIKI_NAME_PARAMETER, doc.getWiki(), + Constants.SPACE_NAME_PARAMETER, doc.getSpace(), Constants.PAGE_NAME_PARAMETER, doc.getName(), + Constants.LANGUAGE_ID_PARAMETER, language)); link.setRel(Relations.TRANSLATION); link.setHrefLang(language); translations.addLink(link); @@ -110,15 +142,17 @@ String.format("%s%s", request.getRootRef(), resourceClassRegistry .getUriPatternForResourceClass(PageResource.class)); link = - new Link(Utils.formatUriTemplate(fullUri, UriConstants.SPACE_NAME_PARAMETER, doc.getSpace(), - UriConstants.PAGE_NAME_PARAMETER, doc.getName())); + new Link(Utils.formatUriTemplate(fullUri, Constants.WIKI_NAME_PARAMETER, doc.getWiki(), + Constants.SPACE_NAME_PARAMETER, doc.getSpace(), Constants.PAGE_NAME_PARAMETER, doc.getName())); link.setRel(Relations.PAGE); pageSummary.addLink(link);
fullUri = String.format("%s%s", request.getRootRef(), resourceClassRegistry .getUriPatternForResourceClass(SpaceResource.class)); - link = new Link(Utils.formatUriTemplate(fullUri, UriConstants.SPACE_NAME_PARAMETER, doc.getSpace())); + link = + new Link(Utils.formatUriTemplate(fullUri, Constants.WIKI_NAME_PARAMETER, doc.getWiki(), + Constants.SPACE_NAME_PARAMETER, doc.getSpace())); link.setRel(Relations.SPACE); pageSummary.addLink(link);
@@ -127,10 +161,12 @@ pageSummary.setParent(doc.getParent());
String[] components = doc.getParent().split("\\."); - fullUri = String.format("%s%s", request.getRootRef(), UriConstants.PAGE_URI_TEMPLATE); + fullUri = + String.format("%s%s", request.getRootRef(), resourceClassRegistry + .getUriPatternForResourceClass(PageResource.class)); link = - new Link(Utils.formatUriTemplate(fullUri, UriConstants.SPACE_NAME_PARAMETER, components[0], - UriConstants.PAGE_NAME_PARAMETER, components[1])); + new Link(Utils.formatUriTemplate(fullUri, Constants.WIKI_NAME_PARAMETER, doc.getWiki(), + Constants.SPACE_NAME_PARAMETER, components[0], Constants.PAGE_NAME_PARAMETER, components[1])); link.setRel(Relations.PARENT); pageSummary.addLink(link); } @@ -180,8 +216,9 @@ String.format("%s%s", request.getRootRef(), resourceClassRegistry .getUriPatternForResourceClass(PageTranslationResource.class)); link = - new Link(Utils.formatUriTemplate(fullUri, UriConstants.SPACE_NAME_PARAMETER, doc.getSpace(), - UriConstants.PAGE_NAME_PARAMETER, doc.getName(), UriConstants.LANGUAGE_ID_PARAMETER, language)); + new Link(Utils.formatUriTemplate(fullUri, Constants.WIKI_NAME_PARAMETER, doc.getWiki(), + Constants.SPACE_NAME_PARAMETER, doc.getSpace(), Constants.PAGE_NAME_PARAMETER, doc.getName(), + Constants.LANGUAGE_ID_PARAMETER, language)); link.setRel(Relations.TRANSLATION); link.setHrefLang(language); translations.addLink(link); @@ -194,7 +231,7 @@ fullUri = String.format("%s%s", request.getRootRef(), resourceClassRegistry .getUriPatternForResourceClass(SpaceResource.class)); - link = new Link(Utils.formatUriTemplate(fullUri, UriConstants.SPACE_NAME_PARAMETER, doc.getSpace())); + link = new Link(Utils.formatUriTemplate(fullUri, Constants.SPACE_NAME_PARAMETER, doc.getSpace())); link.setRel(Relations.SPACE); page.addLink(link);
@@ -207,8 +244,8 @@ String.format("%s%s", request.getRootRef(), resourceClassRegistry .getUriPatternForResourceClass(PageResource.class)); link = - new Link(Utils.formatUriTemplate(fullUri, UriConstants.SPACE_NAME_PARAMETER, components[0], - UriConstants.PAGE_NAME_PARAMETER, components[1])); + new Link(Utils.formatUriTemplate(fullUri, Constants.SPACE_NAME_PARAMETER, components[0], + Constants.PAGE_NAME_PARAMETER, components[1])); link.setRel(Relations.PARENT); page.addLink(link); } @@ -250,16 +287,16 @@ String.format("%s%s", request.getRootRef(), resourceClassRegistry .getUriPatternForResourceClass(PageTranslationVersionResource.class)); link = - new Link(Utils.formatUriTemplate(fullUri, UriConstants.SPACE_NAME_PARAMETER, spaceName, - UriConstants.PAGE_NAME_PARAMETER, pageName, UriConstants.LANGUAGE_ID_PARAMETER, languageId, - UriConstants.VERSION_PARAMETER, String.format("%d.%d", version, minorVersion))); + new Link(Utils.formatUriTemplate(fullUri, Constants.SPACE_NAME_PARAMETER, spaceName, + Constants.PAGE_NAME_PARAMETER, pageName, Constants.LANGUAGE_ID_PARAMETER, languageId, + Constants.VERSION_PARAMETER, String.format("%d.%d", version, minorVersion))); } else { fullUri = String.format("%s%s", request.getRootRef(), resourceClassRegistry .getUriPatternForResourceClass(PageVersionResource.class)); link = - new Link(Utils.formatUriTemplate(fullUri, UriConstants.SPACE_NAME_PARAMETER, spaceName, - UriConstants.PAGE_NAME_PARAMETER, pageName, UriConstants.VERSION_PARAMETER, String.format("%d.%d", + new Link(Utils.formatUriTemplate(fullUri, Constants.SPACE_NAME_PARAMETER, spaceName, + Constants.PAGE_NAME_PARAMETER, pageName, Constants.VERSION_PARAMETER, String.format("%d.%d", version, minorVersion))); }
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/Utils.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/Utils.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/Utils.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -18,6 +18,8 @@ import org.xwiki.rest.model.XStreamFactory;
import com.thoughtworks.xstream.XStream; +import com.xpn.xwiki.api.Document; +import com.xpn.xwiki.doc.XWikiDocument;
public class Utils { @@ -96,4 +98,16 @@ return null; }
+ public static String getPrefixedPageName(String database, String space, String name) + { + XWikiDocument xwikiDocument = new XWikiDocument(); + xwikiDocument.setDatabase(database); + xwikiDocument.setName(name); + xwikiDocument.setSpace(space); + + Document document = new Document(xwikiDocument, null); + + return document.getPrefixedFullName(); + } + }
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/XWikiResource.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/XWikiResource.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/XWikiResource.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -174,12 +174,14 @@ public DocumentInfo getDocumentFromRequest(Request request, boolean failIfDoesntExist) { try { + String wikiName = (String) request.getAttributes().get(Constants.WIKI_NAME_PARAMETER); String spaceName = (String) request.getAttributes().get(Constants.SPACE_NAME_PARAMETER); String pageName = (String) request.getAttributes().get(Constants.PAGE_NAME_PARAMETER); String language = (String) request.getAttributes().get(Constants.LANGUAGE_ID_PARAMETER); String version = (String) request.getAttributes().get(Constants.VERSION_PARAMETER); - String pageFullName = String.format("%s.%s", spaceName, pageName);
+ String pageFullName = Utils.getPrefixedPageName(wikiName, spaceName, pageName); + boolean existed = xwikiApi.exists(pageFullName);
if (failIfDoesntExist) {
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Relations.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Relations.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Relations.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -7,6 +7,10 @@ { public static final String SELF = "self";
+ public static final String WADL = "wadl"; + + public static final String WIKIS = "http://www.xwiki.org/rel/wikis"; + public static final String SPACES = "http://www.xwiki.org/rel/spaces";
public static final String SPACE = "http://www.xwiki.org/rel/space"; @@ -18,6 +22,4 @@ public static final String PAGE = "http://www.xwiki.org/rel/page";
public static final String PARENT = "http://www.xwiki.org/rel/page/parent"; - - public static final String WADL = "wadl"; }
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Space.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Space.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Space.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -9,7 +9,7 @@ public class Space extends LinkCollection { private String wiki; - + private String name;
private String home;
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/UriConstants.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/UriConstants.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/UriConstants.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -7,6 +7,8 @@ { public static final String BROWSER_AUTHENTICATION_URI_TEMPLATE = "/browser_authentication";
+ public static final String WIKI_NAME_PARAMETER = "wikiName"; + public static final String SPACE_NAME_PARAMETER = "spaceName";
public static final String PAGE_NAME_PARAMETER = "pageName"; @@ -17,34 +19,40 @@
public static final String ROOT_URI_TEMPLATE = "/";
- public static final String SPACES_URI_TEMPLATE = "/spaces"; + public static final String WIKIS_URI_TEMPLATE = "/wikis";
- public static final String PAGES_URI_TEMPLATE = String.format("/spaces/{%s}/pages", SPACE_NAME_PARAMETER); + public static final String SPACES_URI_TEMPLATE = "/wikis/{%s}";
+ public static final String PAGES_URI_TEMPLATE = + String.format("/wikis/{%s}/spaces/{%s}/pages", WIKI_NAME_PARAMETER, SPACE_NAME_PARAMETER); + public static final String PAGE_URI_TEMPLATE = - String.format("/spaces/{%s}/pages/{%s}", SPACE_NAME_PARAMETER, PAGE_NAME_PARAMETER); + String.format("/wikis/{%s}/spaces/{%s}/pages/{%s}", WIKI_NAME_PARAMETER, SPACE_NAME_PARAMETER, + PAGE_NAME_PARAMETER);
public static final String TRANSLATIONS_URI_TEMPLATE = - String.format("/spaces/{%s}/pages/{%s}/translations", SPACE_NAME_PARAMETER, PAGE_NAME_PARAMETER); + String.format("/wikis/{%s}/spaces/{%s}/pages/{%s}/translations", WIKI_NAME_PARAMETER, SPACE_NAME_PARAMETER, + PAGE_NAME_PARAMETER);
public static final String PAGE_TRANSLATION_URI_TEMPLATE = - String.format("/spaces/{%s}/pages/{%s}/translations/{%s}", SPACE_NAME_PARAMETER, PAGE_NAME_PARAMETER, - LANGUAGE_ID_PARAMETER); + String.format("/wikis/{%s}/spaces/{%s}/pages/{%s}/translations/{%s}", WIKI_NAME_PARAMETER, + SPACE_NAME_PARAMETER, PAGE_NAME_PARAMETER, LANGUAGE_ID_PARAMETER);
public static final String HISTORY_URI_TEMPLATE = - String.format("/spaces/{%s}/pages/{%s}/history", SPACE_NAME_PARAMETER, PAGE_NAME_PARAMETER); + String.format("/wikis/{%s}/spaces/{%s}/pages/{%s}/history", WIKI_NAME_PARAMETER, SPACE_NAME_PARAMETER, + PAGE_NAME_PARAMETER);
public static final String TRANSLATION_HISTORY_URI_TEMPLATE = - String.format("/spaces/{%s}/pages/{%s}/translations/{%s}/history", SPACE_NAME_PARAMETER, PAGE_NAME_PARAMETER, - LANGUAGE_ID_PARAMETER); + String.format("/wikis/{%s}/spaces/{%s}/pages/{%s}/translations/{%s}/history", WIKI_NAME_PARAMETER, + SPACE_NAME_PARAMETER, PAGE_NAME_PARAMETER, LANGUAGE_ID_PARAMETER);
public static final String PAGE_VERSION_URI_TEMPLATE = - String.format("/spaces/{%s}/pages/{%s}/history/{%s}", SPACE_NAME_PARAMETER, PAGE_NAME_PARAMETER, - VERSION_PARAMETER); + String.format("/wikis/{%s}/spaces/{%s}/pages/{%s}/history/{%s}", WIKI_NAME_PARAMETER, SPACE_NAME_PARAMETER, + PAGE_NAME_PARAMETER, VERSION_PARAMETER);
public static final String PAGE_TRANSLATION_VERSION_URI_TEMPLATE = - String.format("/spaces/{%s}/pages/{%s}/translations/{%s}/history/{%s}", SPACE_NAME_PARAMETER, - PAGE_NAME_PARAMETER, LANGUAGE_ID_PARAMETER, VERSION_PARAMETER); + String.format("/wikis/{%s}/spaces/{%s}/pages/{%s}/translations/{%s}/history/{%s}", WIKI_NAME_PARAMETER, + SPACE_NAME_PARAMETER, PAGE_NAME_PARAMETER, LANGUAGE_ID_PARAMETER, VERSION_PARAMETER);
public static final String START_PARAMETER = "start";
Added: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Wiki.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Wiki.java (rev 0) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Wiki.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -0,0 +1,23 @@ +package org.xwiki.rest.model; + +import com.thoughtworks.xstream.annotations.XStreamAlias; + +/** + * @version $Id$ + */ +@XStreamAlias("wiki") +public class Wiki extends LinkCollection +{ + private String name; + + public Wiki(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + +}
Added: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Wikis.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Wikis.java (rev 0) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/Wikis.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -0,0 +1,32 @@ +package org.xwiki.rest.model; + +import java.util.ArrayList; +import java.util.List; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamImplicit; + +/** + * @version $Id$ + */ +@XStreamAlias("wikis") +public class Wikis extends LinkCollection +{ + @XStreamImplicit + private List<Wiki> wikiList; + + public Wikis() + { + wikiList = new ArrayList<Wiki>(); + } + + public void addWiki(Wiki space) + { + wikiList.add(space); + } + + public List<Wiki> getWikiList() + { + return wikiList; + } +}
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/XStreamFactory.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/XStreamFactory.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/model/XStreamFactory.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -28,6 +28,8 @@
sorter.registerFieldOrder(XWikiRoot.class, new String[] {"version", "links"});
+ sorter.registerFieldOrder(Wiki.class, new String[] {"name", "links"}); + sorter.registerFieldOrder(Space.class, new String[] {"wiki", "name", "home", "numberOfPages", "links"});
sorter.registerFieldOrder(PageSummary.class, new String[] {"fullId", "id", "wiki", "space", "name", "title", @@ -41,6 +43,8 @@
xstream.processAnnotations(Link.class); xstream.processAnnotations(XWikiRoot.class); + xstream.processAnnotations(Wikis.class); + xstream.processAnnotations(Wiki.class); xstream.processAnnotations(Spaces.class); xstream.processAnnotations(Space.class); xstream.processAnnotations(Pages.class);
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/SpaceResource.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/SpaceResource.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/SpaceResource.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -11,7 +11,6 @@ import org.xwiki.rest.model.Space;
import com.xpn.xwiki.XWikiException; -import com.xpn.xwiki.api.Document;
/** * @version $Id$ @@ -25,7 +24,7 @@ String spaceName = (String) getRequest().getAttributes().get(Constants.SPACE_NAME_PARAMETER);
xwiki.setDatabase("xwiki"); - + List<String> docNames = xwikiApi.getSpaceDocsName(spaceName); String home = String.format("%s.WebHome", spaceName);
@@ -36,7 +35,8 @@ String wiki = "xwiki";
Space space = - DomainObjectFactory.createSpace(getRequest(), resourceClassRegistry, wiki, spaceName, home, docNames.size()); + DomainObjectFactory.createSpace(getRequest(), resourceClassRegistry, wiki, spaceName, home, docNames + .size());
return getRepresenterFor(variant).represent(getContext(), getRequest(), getResponse(), space); } catch (XWikiException e) {
Modified: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/SpacesResource.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/SpacesResource.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/SpacesResource.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -7,6 +7,7 @@ import org.restlet.data.Status; import org.restlet.resource.Representation; import org.restlet.resource.Variant; +import org.xwiki.rest.Constants; import org.xwiki.rest.DomainObjectFactory; import org.xwiki.rest.RangeIterable; import org.xwiki.rest.Utils; @@ -15,7 +16,6 @@ import org.xwiki.rest.model.UriConstants;
import com.xpn.xwiki.XWikiException; -import com.xpn.xwiki.api.Document;
/** * @version $Id$ @@ -24,8 +24,13 @@ { @Override public Representation represent(Variant variant) - { + { + String database = xwikiContext.getDatabase(); + try { + String wiki = (String) getRequest().getAttributes().get(Constants.WIKI_NAME_PARAMETER); + xwikiContext.setDatabase(wiki); + Spaces spaces = new Spaces();
List<String> spaceNames = xwikiApi.getSpaces(); @@ -44,8 +49,6 @@ home = null; }
- String wiki = "xwiki"; - spaces.addSpace(DomainObjectFactory.createSpace(getRequest(), resourceClassRegistry, wiki, spaceName, home, docNames.size())); } @@ -54,7 +57,9 @@ } catch (XWikiException e) { e.printStackTrace(); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); - } + } finally { + xwikiContext.setDatabase(database); + }
return null; }
Added: sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/WikisResource.java =================================================================== --- sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/WikisResource.java (rev 0) +++ sandbox/xwiki-core-rest/src/main/java/org/xwiki/rest/resources/WikisResource.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -0,0 +1,57 @@ +package org.xwiki.rest.resources; + +import java.util.List; + +import org.restlet.data.Status; +import org.restlet.resource.Representation; +import org.restlet.resource.Variant; +import org.xwiki.rest.Constants; +import org.xwiki.rest.Utils; +import org.xwiki.rest.XWikiResource; +import org.xwiki.rest.model.Link; +import org.xwiki.rest.model.Relations; +import org.xwiki.rest.model.Wiki; +import org.xwiki.rest.model.Wikis; + +import com.xpn.xwiki.XWikiException; + +/** + * @version $Id$ + */ +public class WikisResource extends XWikiResource +{ + @Override + public Representation represent(Variant variant) + { + try { + Wikis wikis = new Wikis(); + + List<String> databaseNames = xwiki.getVirtualWikisDatabaseNames(xwikiContext); + + if (databaseNames.isEmpty()) { + databaseNames.add("xwiki"); + } + + for (String databaseName : databaseNames) { + Wiki wiki = new Wiki(databaseName); + + String fullUri = + String.format("%s%s", getRequest().getRootRef(), resourceClassRegistry + .getUriPatternForResourceClass(SpacesResource.class)); + Link link = new Link(Utils.formatUriTemplate(fullUri, Constants.WIKI_NAME_PARAMETER, databaseName)); + link.setRel(Relations.SPACES); + wiki.addLink(link); + + wikis.addWiki(wiki); + } + + return getRepresenterFor(variant).represent(getContext(), getRequest(), getResponse(), wikis); + } catch (XWikiException e) { + e.printStackTrace(); + getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); + } + + return null; + + } +}
Modified: sandbox/xwiki-core-rest/src/main/resources/META-INF/plexus/components.xml =================================================================== --- sandbox/xwiki-core-rest/src/main/resources/META-INF/plexus/components.xml 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/main/resources/META-INF/plexus/components.xml 2009-01-08 19:58:17 UTC (rev 15193) @@ -76,7 +76,50 @@ org.xwiki.rest.representers.XmlTextXStreamRepresenter </implementation> </component> + + <!-- ***************** --> + <!-- * Wikis resource * --> + <!-- ***************** --> + <component> + <role>org.xwiki.rest.XWikiResource + </role> + <role-hint>org.xwiki.rest.resources.WikisResource + </role-hint> + <instantiation-strategy>per-lookup</instantiation-strategy> + <implementation>org.xwiki.rest.resources.WikisResource + </implementation> + <requirements> + <requirement> + <role>org.xwiki.rest.XWikiResourceClassRegistry + </role> + </requirement> + <requirement> + <role>org.xwiki.rest.XWikiResourceRepresenter + </role> + <role-hint>org.xwiki.rest.resources.WikisResource + </role-hint> + <field-name>descriptorToRepresenterMap + </field-name> + </requirement> + </requirements> + <configuration> + <uriPattern>/wikis</uriPattern> + </configuration> + </component>
+ <!-- *** Representers for Wikis resource *** --> + + <component> + <role>org.xwiki.rest.XWikiResourceRepresenter + </role> + <role-hint>org.xwiki.rest.resources.WikisResource:text/xml + </role-hint> + <instantiation-strategy>singleton</instantiation-strategy> + <implementation> + org.xwiki.rest.representers.XmlTextXStreamRepresenter + </implementation> + </component> + <!-- ******************* --> <!-- * Spaces resource * --> <!-- ******************* --> @@ -108,7 +151,7 @@ </requirement> </requirements> <configuration> - <uriPattern>/spaces</uriPattern> + <uriPattern>/wikis/{wikiName}/spaces</uriPattern> </configuration> </component>
@@ -163,7 +206,7 @@ </requirement> </requirements> <configuration> - <uriPattern>/spaces/{spaceName}</uriPattern> + <uriPattern>/wikis/{wikiName}/spaces/{spaceName}</uriPattern> </configuration> </component>
@@ -207,7 +250,7 @@ </requirement> </requirements> <configuration> - <uriPattern>/spaces/{spaceName}/pages + <uriPattern>/wikis/{wikiName}/spaces/{spaceName}/pages </uriPattern> </configuration> </component> @@ -252,7 +295,7 @@ </requirement> </requirements> <configuration> - <uriPattern>/spaces/{spaceName}/pages/{pageName} + <uriPattern>/wikis/{wikiName}/spaces/{spaceName}/pages/{pageName} </uriPattern> </configuration> </component> @@ -297,7 +340,7 @@ </requirement> </requirements> <configuration> - <uriPattern>/spaces/{spaceName}/pages/{pageName}/history/{version} + <uriPattern>/wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history/{version} </uriPattern> </configuration> </component> @@ -342,7 +385,7 @@ </requirement> </requirements> <configuration> - <uriPattern>/spaces/{spaceName}/pages/{pageName}/translations + <uriPattern>/wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations </uriPattern> </configuration> </component> @@ -387,7 +430,7 @@ </requirement> </requirements> <configuration> - <uriPattern>/spaces/{spaceName}/pages/{pageName}/translations/{languageId} + <uriPattern>/wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations/{languageId} </uriPattern> </configuration> </component> @@ -432,7 +475,7 @@ </requirement> </requirements> <configuration> - <uriPattern>/spaces/{spaceName}/pages/{pageName}/translations/{languageId}/history/{version} + <uriPattern>/wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations/{languageId}/history/{version} </uriPattern> </configuration> </component> @@ -477,7 +520,7 @@ </requirement> </requirements> <configuration> - <uriPattern>/spaces/{spaceName}/pages/{pageName}/history + <uriPattern>/wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/history </uriPattern> </configuration> </component> @@ -522,7 +565,7 @@ </requirement> </requirements> <configuration> - <uriPattern>/spaces/{spaceName}/pages/{pageName}/translations/{languageId}/history + <uriPattern>/wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/translations/{languageId}/history </uriPattern> </configuration> </component>
Modified: sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/PageResourceTest.java =================================================================== --- sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/PageResourceTest.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/PageResourceTest.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -14,21 +14,34 @@ import org.xwiki.rest.model.Space; import org.xwiki.rest.model.Spaces; import org.xwiki.rest.model.UriConstants; +import org.xwiki.rest.model.Wiki; +import org.xwiki.rest.model.Wikis;
public class PageResourceTest extends AbstractHttpTest { private Page getPage() throws Exception { - GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.SPACES_URI_TEMPLATE))); + GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.WIKIS_URI_TEMPLATE))); assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); TestUtils.printHttpMethodInfo(getMethod);
+ Wikis wikis = (Wikis) xstream.fromXML(getMethod.getResponseBodyAsString()); + assertTrue(wikis.getWikiList().size() > 0); + + Wiki wiki = wikis.getWikiList().get(0); + Link link = wiki.getFirstLinkByRelation(Relations.SPACES); + assertNotNull(link); + + getMethod = executeGet(link.getHref()); + assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); + TestUtils.printHttpMethodInfo(getMethod); + Spaces spaces = (Spaces) xstream.fromXML(getMethod.getResponseBodyAsString());
assertTrue(spaces.getSpaceList().size() > 0);
Space space = spaces.getSpaceList().get(0); - Link link = space.getFirstLinkByRelation(Relations.PAGES); + link = space.getFirstLinkByRelation(Relations.PAGES); assertNotNull(link);
getMethod = executeGet(link.getHref()); @@ -51,6 +64,18 @@ return page; }
+ public String getWiki() throws Exception + { + GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.WIKIS_URI_TEMPLATE))); + assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); + TestUtils.printHttpMethodInfo(getMethod); + + Wikis wikis = (Wikis) xstream.fromXML(getMethod.getResponseBodyAsString()); + assertTrue(wikis.getWikiList().size() > 0); + + return wikis.getWikiList().get(0).getName(); + } + public void testRepresentation() throws Exception { TestUtils.banner("testRepresentation()"); @@ -67,7 +92,8 @@
GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_URI_TEMPLATE, - UriConstants.SPACE_NAME_PARAMETER, "NOTEXISTING", UriConstants.PAGE_NAME_PARAMETER, "NOTEXISTING"))); + UriConstants.WIKI_NAME_PARAMETER, getWiki(), UriConstants.SPACE_NAME_PARAMETER, "NOTEXISTING", + UriConstants.PAGE_NAME_PARAMETER, "NOTEXISTING"))); assertTrue(getMethod.getStatusCode() == HttpStatus.SC_NOT_FOUND); TestUtils.printHttpMethodInfo(getMethod); } @@ -131,8 +157,8 @@
PutMethod putMethod = executePut(getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_URI_TEMPLATE, - UriConstants.SPACE_NAME_PARAMETER, SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, PAGE_NAME)), page, - "Admin", "admin"); + UriConstants.WIKI_NAME_PARAMETER, getWiki(), UriConstants.SPACE_NAME_PARAMETER, SPACE_NAME, + UriConstants.PAGE_NAME_PARAMETER, PAGE_NAME)), page, "Admin", "admin"); assertTrue(putMethod.getStatusCode() == HttpStatus.SC_CREATED); TestUtils.printHttpMethodInfo(putMethod);
@@ -159,8 +185,8 @@ private void createPageIfDoesntExist(String spaceName, String pageName, String content) throws Exception { String uri = - getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_URI_TEMPLATE, UriConstants.SPACE_NAME_PARAMETER, - spaceName, UriConstants.PAGE_NAME_PARAMETER, pageName)); + getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_URI_TEMPLATE, UriConstants.WIKI_NAME_PARAMETER, + getWiki(), UriConstants.SPACE_NAME_PARAMETER, spaceName, UriConstants.PAGE_NAME_PARAMETER, pageName));
GetMethod getMethod = executeGet(uri); TestUtils.printHttpMethodInfo(getMethod); @@ -197,16 +223,17 @@
PutMethod putMethod = executePut(getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_TRANSLATION_URI_TEMPLATE, - UriConstants.SPACE_NAME_PARAMETER, TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, - TestConstants.TRANSLATIONS_PAGE_NAME, UriConstants.LANGUAGE_ID_PARAMETER, languageId)), page, "Admin", - "admin"); + UriConstants.WIKI_NAME_PARAMETER, getWiki(), UriConstants.SPACE_NAME_PARAMETER, + TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, TestConstants.TRANSLATIONS_PAGE_NAME, + UriConstants.LANGUAGE_ID_PARAMETER, languageId)), page, "Admin", "admin"); assertTrue(putMethod.getStatusCode() == HttpStatus.SC_CREATED); TestUtils.printHttpMethodInfo(putMethod);
GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_TRANSLATION_URI_TEMPLATE, - UriConstants.SPACE_NAME_PARAMETER, TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, - TestConstants.TRANSLATIONS_PAGE_NAME, UriConstants.LANGUAGE_ID_PARAMETER, languageId))); + UriConstants.WIKI_NAME_PARAMETER, getWiki(), UriConstants.SPACE_NAME_PARAMETER, + TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, TestConstants.TRANSLATIONS_PAGE_NAME, + UriConstants.LANGUAGE_ID_PARAMETER, languageId))); assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); TestUtils.printHttpMethodInfo(getMethod);
@@ -221,8 +248,8 @@
GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_URI_TEMPLATE, - UriConstants.SPACE_NAME_PARAMETER, TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, - TestConstants.TRANSLATIONS_PAGE_NAME))); + UriConstants.WIKI_NAME_PARAMETER, getWiki(), UriConstants.SPACE_NAME_PARAMETER, + TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, TestConstants.TRANSLATIONS_PAGE_NAME))); assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); TestUtils.printHttpMethodInfo(getMethod);
@@ -232,6 +259,7 @@ assertTrue(translationLinks.size() > 0);
for (Link translationLink : translationLinks) { + System.out.format("Translation link: %s\n", translationLink.getHref()); getMethod = executeGet(translationLink.getHref()); assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); TestUtils.printHttpMethodInfo(getMethod); @@ -248,15 +276,16 @@
GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_URI_TEMPLATE, - UriConstants.SPACE_NAME_PARAMETER, TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, - TestConstants.TRANSLATIONS_PAGE_NAME))); + UriConstants.WIKI_NAME_PARAMETER, getWiki(), UriConstants.SPACE_NAME_PARAMETER, + TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, TestConstants.TRANSLATIONS_PAGE_NAME))); assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); TestUtils.printHttpMethodInfo(getMethod);
getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_TRANSLATION_URI_TEMPLATE, - UriConstants.SPACE_NAME_PARAMETER, TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, - TestConstants.TRANSLATIONS_PAGE_NAME, UriConstants.LANGUAGE_ID_PARAMETER, "NOTEXISTING"))); + UriConstants.WIKI_NAME_PARAMETER, getWiki(), UriConstants.SPACE_NAME_PARAMETER, + TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, TestConstants.TRANSLATIONS_PAGE_NAME, + UriConstants.LANGUAGE_ID_PARAMETER, "NOTEXISTING"))); assertTrue(getMethod.getStatusCode() == HttpStatus.SC_NOT_FOUND); TestUtils.printHttpMethodInfo(getMethod); } @@ -271,15 +300,15 @@
DeleteMethod deleteMethod = executeDelete(getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_URI_TEMPLATE, - UriConstants.SPACE_NAME_PARAMETER, TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, - pageName))); + UriConstants.WIKI_NAME_PARAMETER, getWiki(), UriConstants.SPACE_NAME_PARAMETER, + TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, pageName))); assertTrue(deleteMethod.getStatusCode() == HttpStatus.SC_OK); TestUtils.printHttpMethodInfo(deleteMethod);
GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.PAGE_URI_TEMPLATE, - UriConstants.SPACE_NAME_PARAMETER, TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, - pageName))); + UriConstants.WIKI_NAME_PARAMETER, getWiki(), UriConstants.SPACE_NAME_PARAMETER, + TestConstants.TEST_SPACE_NAME, UriConstants.PAGE_NAME_PARAMETER, pageName))); assertTrue(getMethod.getStatusCode() == HttpStatus.SC_NOT_FOUND); TestUtils.printHttpMethodInfo(getMethod); }
Modified: sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/PagesResourceTest.java =================================================================== --- sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/PagesResourceTest.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/PagesResourceTest.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -8,6 +8,8 @@ import org.xwiki.rest.model.Space; import org.xwiki.rest.model.Spaces; import org.xwiki.rest.model.UriConstants; +import org.xwiki.rest.model.Wiki; +import org.xwiki.rest.model.Wikis;
public class PagesResourceTest extends AbstractHttpTest { @@ -15,15 +17,26 @@ { TestUtils.banner("testRepresentation()");
- GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.SPACES_URI_TEMPLATE))); + GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.WIKIS_URI_TEMPLATE))); assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); TestUtils.printHttpMethodInfo(getMethod);
+ Wikis wikis = (Wikis) xstream.fromXML(getMethod.getResponseBodyAsString()); + assertTrue(wikis.getWikiList().size() > 0); + + Wiki wiki = wikis.getWikiList().get(0); + Link link = wiki.getFirstLinkByRelation(Relations.SPACES); + assertNotNull(link); + + getMethod = executeGet(link.getHref()); + assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); + TestUtils.printHttpMethodInfo(getMethod); + Spaces spaces = (Spaces) xstream.fromXML(getMethod.getResponseBodyAsString()); assertTrue(spaces.getSpaceList().size() > 0);
Space space = spaces.getSpaceList().get(0); - Link link = space.getFirstLinkByRelation(Relations.PAGES); + link = space.getFirstLinkByRelation(Relations.PAGES); assertNotNull(link);
getMethod = executeGet(link.getHref());
Modified: sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/RootResourceTest.java =================================================================== --- sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/RootResourceTest.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/RootResourceTest.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -19,7 +19,7 @@
XWikiRoot xwikiRoot = (XWikiRoot) xstream.fromXML(getMethod.getResponseBodyAsString());
- Link link = xwikiRoot.getFirstLinkByRelation(Relations.SPACES); + Link link = xwikiRoot.getFirstLinkByRelation(Relations.WIKIS); assertNotNull(link);
link = xwikiRoot.getFirstLinkByRelation(Relations.WADL);
Modified: sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/SpacesResourceTest.java =================================================================== --- sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/SpacesResourceTest.java 2009-01-08 19:48:12 UTC (rev 15192) +++ sandbox/xwiki-core-rest/src/test/java/org/xwiki/rest/SpacesResourceTest.java 2009-01-08 19:58:17 UTC (rev 15193) @@ -2,8 +2,12 @@
import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; +import org.xwiki.rest.model.Link; +import org.xwiki.rest.model.Relations; import org.xwiki.rest.model.Spaces; import org.xwiki.rest.model.UriConstants; +import org.xwiki.rest.model.Wiki; +import org.xwiki.rest.model.Wikis;
public class SpacesResourceTest extends AbstractHttpTest { @@ -11,10 +15,21 @@ { TestUtils.banner("testRepresentation()");
- GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.SPACES_URI_TEMPLATE))); + GetMethod getMethod = executeGet(getFullUri(Utils.formatUriTemplate(UriConstants.WIKIS_URI_TEMPLATE))); assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); TestUtils.printHttpMethodInfo(getMethod);
+ Wikis wikis = (Wikis) xstream.fromXML(getMethod.getResponseBodyAsString()); + assertTrue(wikis.getWikiList().size() > 0); + + Wiki wiki = wikis.getWikiList().get(0); + Link link = wiki.getFirstLinkByRelation(Relations.SPACES); + assertNotNull(link); + + getMethod = executeGet(link.getHref()); + assertTrue(getMethod.getStatusCode() == HttpStatus.SC_OK); + TestUtils.printHttpMethodInfo(getMethod); + Spaces spaces = (Spaces) xstream.fromXML(getMethod.getResponseBodyAsString());
assertTrue(spaces.getSpaceList().size() > 0);
_______________________________________________ notifications mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/notifications
-- Thomas Mortagne
participants (1)
-
Thomas Mortagne