1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.rest

File PageResourceTest.java

 

Code metrics

8
251
20
1
590
422
24
0.1
12.55
20
1.2

Classes

Class Line # Actions
PageResourceTest 66 251 0% 24 4
0.9856630698.6%
 

Contributing tests

This file is covered by 17 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.test.rest;
21   
22    import java.util.Arrays;
23    import java.util.List;
24    import java.util.Locale;
25    import java.util.UUID;
26   
27    import javax.ws.rs.core.MediaType;
28   
29    import org.apache.commons.httpclient.HttpStatus;
30    import org.apache.commons.httpclient.NameValuePair;
31    import org.apache.commons.httpclient.methods.DeleteMethod;
32    import org.apache.commons.httpclient.methods.GetMethod;
33    import org.apache.commons.httpclient.methods.PostMethod;
34    import org.apache.commons.httpclient.methods.PutMethod;
35    import org.junit.Assert;
36    import org.junit.Before;
37    import org.junit.Test;
38    import org.xwiki.localization.LocaleUtils;
39    import org.xwiki.model.reference.DocumentReference;
40    import org.xwiki.rest.Relations;
41    import org.xwiki.rest.model.jaxb.History;
42    import org.xwiki.rest.model.jaxb.HistorySummary;
43    import org.xwiki.rest.model.jaxb.Link;
44    import org.xwiki.rest.model.jaxb.Object;
45    import org.xwiki.rest.model.jaxb.Page;
46    import org.xwiki.rest.model.jaxb.PageSummary;
47    import org.xwiki.rest.model.jaxb.Pages;
48    import org.xwiki.rest.model.jaxb.Property;
49    import org.xwiki.rest.model.jaxb.Space;
50    import org.xwiki.rest.model.jaxb.Spaces;
51    import org.xwiki.rest.model.jaxb.Translation;
52    import org.xwiki.rest.model.jaxb.Wiki;
53    import org.xwiki.rest.model.jaxb.Wikis;
54    import org.xwiki.rest.resources.pages.PageChildrenResource;
55    import org.xwiki.rest.resources.pages.PageHistoryResource;
56    import org.xwiki.rest.resources.pages.PageResource;
57    import org.xwiki.rest.resources.pages.PageTranslationResource;
58    import org.xwiki.rest.resources.wikis.WikisResource;
59    import org.xwiki.test.rest.framework.AbstractHttpTest;
60    import org.xwiki.test.rest.framework.TestConstants;
61    import org.xwiki.test.ui.TestUtils;
62   
63    import static org.hamcrest.Matchers.isIn;
64    import static org.junit.Assert.assertThat;
65   
 
66    public class PageResourceTest extends AbstractHttpTest
67    {
68    private String wikiName;
69   
70    private String space;
71   
72    private List<String> spaces;
73   
74    private String pageName;
75   
76    private DocumentReference reference;
77   
78    private String childPageName;
79   
80    private DocumentReference childReference;
81   
 
82  17 toggle @Before
83    @Override
84    public void setUp() throws Exception
85    {
86  17 super.setUp();
87   
88  17 this.wikiName = getWiki();
89  17 this.space = getTestClassName();
90  17 this.spaces = Arrays.asList(this.space);
91  17 this.pageName = getTestMethodName();
92  17 this.reference = new DocumentReference(this.wikiName, this.spaces, this.pageName);
93   
94  17 this.childPageName = "child";
95  17 this.childReference = new DocumentReference(this.wikiName, this.spaces, this.childPageName);
96   
97    // Create a clean test page.
98  17 this.testUtils.rest().delete(this.reference);
99  17 Page page = this.testUtils.rest().page(this.reference);
100  17 page.setComment("Test page");
101  17 this.testUtils.rest().save(page);
102   
103    // Create a clean test page child.
104  17 this.testUtils.rest().delete(this.childReference);
105  17 Page childPage = this.testUtils.rest().page(this.childReference);
106  17 childPage.setComment("Test page child");
107  17 childPage.setParent(this.space + '.' + this.pageName);
108  17 this.testUtils.rest().save(childPage);
109    }
110   
 
111  7 toggle private Page getFirstPage() throws Exception
112    {
113  7 GetMethod getMethod = executeGet(getFullUri(WikisResource.class));
114  7 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
115   
116  7 Wikis wikis = (Wikis) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
117  7 Assert.assertTrue(wikis.getWikis().size() > 0);
118  7 Wiki wiki = wikis.getWikis().get(0);
119   
120    // Get a link to an index of spaces (http://localhost:8080/xwiki/rest/wikis/xwiki/spaces)
121  7 Link spacesLink = getFirstLinkByRelation(wiki, Relations.SPACES);
122  7 Assert.assertNotNull(spacesLink);
123  7 getMethod = executeGet(spacesLink.getHref());
124  7 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
125  7 Spaces spaces = (Spaces) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
126  7 Assert.assertTrue(spaces.getSpaces().size() > 0);
127   
128  7 Space space = null;
129  7 for (final Space s : spaces.getSpaces()) {
130  28 if (this.space.equals(s.getName())) {
131  7 space = s;
132  7 break;
133    }
134    }
135   
136    // get the pages list for the space
137    // eg: http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages
138  7 Link pagesInSpace = getFirstLinkByRelation(space, Relations.PAGES);
139  7 Assert.assertNotNull(pagesInSpace);
140  7 getMethod = executeGet(pagesInSpace.getHref());
141  7 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
142  7 Pages pages = (Pages) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
143  7 Assert.assertTrue(pages.getPageSummaries().size() > 0);
144   
145  7 Link pageLink = null;
146  7 for (final PageSummary ps : pages.getPageSummaries()) {
147  39 if (this.pageName.equals(ps.getName())) {
148  7 pageLink = getFirstLinkByRelation(ps, Relations.PAGE);
149  7 Assert.assertNotNull(pageLink);
150  7 break;
151    }
152    }
153  7 Assert.assertNotNull(pageLink);
154   
155  7 getMethod = executeGet(pageLink.getHref());
156  7 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
157   
158  7 Page page = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
159   
160  7 return page;
161    }
162   
 
163  1 toggle @Override
164    @Test
165    public void testRepresentation() throws Exception
166    {
167  1 Page page = getFirstPage();
168   
169  1 Link link = getFirstLinkByRelation(page, Relations.SELF);
170  1 Assert.assertNotNull(link);
171   
172  1 checkLinks(page);
173    }
174   
 
175  1 toggle @Test
176    public void testGETNotExistingPage() throws Exception
177    {
178  1 GetMethod getMethod =
179    executeGet(buildURI(PageResource.class, getWiki(), Arrays.asList("NOTEXISTING"), "NOTEXISTING").toString());
180  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
181    }
182   
 
183  1 toggle @Test
184    public void testPUTGETPage() throws Exception
185    {
186  1 final String title = String.format("Title (%s)", UUID.randomUUID().toString());
187  1 final String content = String.format("This is a content (%d)", System.currentTimeMillis());
188  1 final String comment = String.format("Updated title and content (%d)", System.currentTimeMillis());
189   
190  1 Page originalPage = getFirstPage();
191   
192  1 Page newPage = this.objectFactory.createPage();
193  1 newPage.setTitle(title);
194  1 newPage.setContent(content);
195  1 newPage.setComment(comment);
196   
197  1 Link link = getFirstLinkByRelation(originalPage, Relations.SELF);
198  1 Assert.assertNotNull(link);
199   
200    // PUT
201  1 PutMethod putMethod = executePutXml(link.getHref(), newPage, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(),
202    TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
203  1 Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
204  1 Page modifiedPage = (Page) this.unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
205   
206  1 Assert.assertEquals(title, modifiedPage.getTitle());
207  1 Assert.assertEquals(content, modifiedPage.getContent());
208  1 Assert.assertEquals(comment, modifiedPage.getComment());
209   
210    // GET
211  1 GetMethod getMethod = executeGet(link.getHref());
212  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
213  1 modifiedPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
214   
215  1 Assert.assertEquals(title, modifiedPage.getTitle());
216  1 Assert.assertEquals(content, modifiedPage.getContent());
217  1 Assert.assertEquals(comment, modifiedPage.getComment());
218    }
219   
 
220  1 toggle @Test
221    public void testPUTGETWithObject() throws Exception
222    {
223  1 String pageURI = buildURI(PageResource.class, getWiki(), Arrays.asList("RESTTest"), "PageWithObject");
224   
225  1 final String title = String.format("Title (%s)", UUID.randomUUID().toString());
226  1 final String content = String.format("This is a content (%d)", System.currentTimeMillis());
227  1 final String comment = String.format("Updated title and content (%d)", System.currentTimeMillis());
228   
229  1 Page newPage = this.objectFactory.createPage();
230  1 newPage.setTitle(title);
231  1 newPage.setContent(content);
232  1 newPage.setComment(comment);
233   
234    // Add object
235  1 final String TAG_VALUE = "TAG";
236  1 Property property = new Property();
237  1 property.setName("tags");
238  1 property.setValue(TAG_VALUE);
239  1 Object object = objectFactory.createObject();
240  1 object.setClassName("XWiki.TagClass");
241  1 object.getProperties().add(property);
242  1 newPage.setObjects(objectFactory.createObjects());
243  1 newPage.getObjects().getObjectSummaries().add(object);
244   
245    // PUT
246  1 PutMethod putMethod = executePutXml(pageURI, newPage, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(),
247    TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
248  1 assertThat(getHttpMethodInfo(putMethod), putMethod.getStatusCode(),
249    isIn(Arrays.asList(HttpStatus.SC_ACCEPTED, HttpStatus.SC_CREATED)));
250   
251  1 Page modifiedPage = (Page) this.unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
252   
253  1 Assert.assertEquals(title, modifiedPage.getTitle());
254  1 Assert.assertEquals(content, modifiedPage.getContent());
255  1 Assert.assertEquals(comment, modifiedPage.getComment());
256   
257    // GET
258  1 GetMethod getMethod = executeGet(pageURI + "?objects=true");
259  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
260  1 modifiedPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
261   
262  1 Assert.assertEquals(title, modifiedPage.getTitle());
263  1 Assert.assertEquals(content, modifiedPage.getContent());
264  1 Assert.assertEquals(comment, modifiedPage.getComment());
265   
266  1 Assert.assertEquals(TAG_VALUE,
267    getProperty((Object) modifiedPage.getObjects().getObjectSummaries().get(0), "tags").getValue());
268   
269    // Send again but with empty object list
270   
271  1 modifiedPage.getObjects().getObjectSummaries().clear();
272   
273    // PUT
274  1 putMethod = executePutXml(pageURI, modifiedPage, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(),
275    TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
276  1 assertThat(getHttpMethodInfo(putMethod), putMethod.getStatusCode(),
277    isIn(Arrays.asList(HttpStatus.SC_ACCEPTED)));
278   
279  1 modifiedPage = (Page) this.unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
280   
281  1 Assert.assertEquals(title, modifiedPage.getTitle());
282  1 Assert.assertEquals(content, modifiedPage.getContent());
283  1 Assert.assertEquals(comment, modifiedPage.getComment());
284   
285    // GET
286  1 getMethod = executeGet(pageURI + "?objects=true");
287  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
288  1 modifiedPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
289   
290  1 Assert.assertEquals(title, modifiedPage.getTitle());
291  1 Assert.assertEquals(content, modifiedPage.getContent());
292  1 Assert.assertEquals(comment, modifiedPage.getComment());
293   
294  1 Assert.assertTrue(modifiedPage.getObjects().getObjectSummaries().isEmpty());
295    }
296   
 
297  1 toggle public Property getProperty(Object object, String propertyName)
298    {
299  1 for (Property property : object.getProperties()) {
300  1 if (property.getName().equals(propertyName)) {
301  1 return property;
302    }
303    }
304   
305  0 return null;
306    }
307   
 
308  1 toggle @Test
309    public void testPUTPageWithTextPlain() throws Exception
310    {
311  1 final String CONTENT = String.format("This is a content (%d)", System.currentTimeMillis());
312   
313  1 Page originalPage = getFirstPage();
314   
315  1 Link link = getFirstLinkByRelation(originalPage, Relations.SELF);
316  1 Assert.assertNotNull(link);
317   
318  1 PutMethod putMethod = executePut(link.getHref(), CONTENT, MediaType.TEXT_PLAIN,
319    TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
320  1 Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
321   
322  1 Page modifiedPage = (Page) this.unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
323   
324  1 Assert.assertEquals(CONTENT, modifiedPage.getContent());
325    }
326   
 
327  1 toggle @Test
328    public void testPUTPageUnauthorized() throws Exception
329    {
330  1 Page page = getFirstPage();
331  1 page.setContent("New content");
332   
333  1 Link link = getFirstLinkByRelation(page, Relations.SELF);
334  1 Assert.assertNotNull(link);
335   
336  1 PutMethod putMethod = executePutXml(link.getHref(), page);
337  1 Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_UNAUTHORIZED, putMethod.getStatusCode());
338    }
339   
 
340  1 toggle @Test
341    public void testPUTNonExistingPage() throws Exception
342    {
343  1 final List<String> SPACE_NAME = Arrays.asList("Test");
344  1 final String PAGE_NAME = String.format("Test-%d", System.currentTimeMillis());
345  1 final String CONTENT = String.format("Content %d", System.currentTimeMillis());
346  1 final String TITLE = String.format("Title %d", System.currentTimeMillis());
347  1 final String PARENT = "Main.WebHome";
348   
349  1 Page page = objectFactory.createPage();
350  1 page.setContent(CONTENT);
351  1 page.setTitle(TITLE);
352  1 page.setParent(PARENT);
353   
354  1 PutMethod putMethod = executePutXml(buildURI(PageResource.class, getWiki(), SPACE_NAME, PAGE_NAME).toString(),
355    page, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
356  1 Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
357   
358  1 Page modifiedPage = (Page) this.unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
359   
360  1 Assert.assertEquals(CONTENT, modifiedPage.getContent());
361  1 Assert.assertEquals(TITLE, modifiedPage.getTitle());
362   
363  1 Assert.assertEquals(PARENT, modifiedPage.getParent());
364    }
365   
 
366  1 toggle @Test
367    public void testPUTWithInvalidRepresentation() throws Exception
368    {
369  1 Page page = getFirstPage();
370  1 Link link = getFirstLinkByRelation(page, Relations.SELF);
371   
372  1 PutMethod putMethod = executePut(link.getHref(),
373    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><invalidPage><content/></invalidPage>", MediaType.TEXT_XML);
374  1 Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_BAD_REQUEST, putMethod.getStatusCode());
375    }
376   
 
377  1 toggle @Test
378    public void testPUTGETTranslation() throws Exception
379    {
380  1 createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME, "Translations");
381   
382    // PUT
383  1 String[] languages = Locale.getISOLanguages();
384  1 final String languageId = languages[random.nextInt(languages.length)];
385   
386  1 Page page = objectFactory.createPage();
387  1 page.setContent(languageId);
388   
389  1 PutMethod putMethod = executePutXml(
390    buildURI(PageTranslationResource.class, getWiki(), TestConstants.TEST_SPACE_NAME,
391    TestConstants.TRANSLATIONS_PAGE_NAME, languageId).toString(),
392    page, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
393  1 Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
394   
395    // GET
396  1 GetMethod getMethod = executeGet(buildURI(PageTranslationResource.class, getWiki(),
397    TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME, languageId).toString());
398  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
399   
400  1 Page modifiedPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
401   
402    // Some of the language codes returned by Locale#getISOLanguages() are deprecated and Locale's constructors map
403    // the new codes to the old ones which means the language code we have submitted can be different than the
404    // actual language code used when the Locale object is created on the server side. Let's go through the Locale
405    // constructor to be safe.
406  1 String expectedLanguage = LocaleUtils.toLocale(languageId).getLanguage();
407  1 Assert.assertEquals(expectedLanguage, modifiedPage.getLanguage());
408  1 Assert.assertTrue(modifiedPage.getTranslations().getTranslations().size() > 0);
409   
410  1 for (Translation translation : modifiedPage.getTranslations().getTranslations()) {
411  1 getMethod = executeGet(getFirstLinkByRelation(translation, Relations.PAGE).getHref());
412  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
413   
414  1 modifiedPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
415   
416  1 Assert.assertEquals(modifiedPage.getLanguage(), translation.getLanguage());
417   
418  1 checkLinks(translation);
419    }
420    }
421   
 
422  1 toggle @Test
423    public void testGETNotExistingTranslation() throws Exception
424    {
425  1 createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME, "Translations");
426   
427  1 GetMethod getMethod = executeGet(
428    buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME)
429    .toString());
430  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
431   
432  1 getMethod = executeGet(buildURI(PageTranslationResource.class, getWiki(), TestConstants.TEST_SPACE_NAME,
433    TestConstants.TRANSLATIONS_PAGE_NAME, "NOT_EXISTING").toString());
434  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
435    }
436   
 
437  1 toggle @Test
438    public void testDELETEPage() throws Exception
439    {
440  1 createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, this.pageName, "Test page");
441   
442  1 DeleteMethod deleteMethod = executeDelete(
443    buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, this.pageName).toString(),
444    TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
445  1 Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode());
446   
447  1 GetMethod getMethod = executeGet(
448    buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, this.pageName).toString());
449  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
450    }
451   
 
452  1 toggle @Test
453    public void testDELETEPageNoRights() throws Exception
454    {
455  1 createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, this.pageName, "Test page");
456   
457  1 DeleteMethod deleteMethod = executeDelete(
458    buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, this.pageName).toString());
459  1 Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED, deleteMethod.getStatusCode());
460   
461  1 GetMethod getMethod = executeGet(
462    buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, this.pageName).toString());
463  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
464    }
465   
 
466  1 toggle @Test
467    public void testPageHistory() throws Exception
468    {
469  1 GetMethod getMethod =
470    executeGet(buildURI(PageResource.class, getWiki(), this.spaces, this.pageName).toString());
471   
472  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
473   
474  1 Page originalPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
475  1 Assert.assertEquals(this.spaces.get(0), originalPage.getSpace());
476   
477  1 String pageHistoryUri =
478    buildURI(PageHistoryResource.class, getWiki(), this.spaces, originalPage.getName()).toString();
479   
480  1 getMethod = executeGet(pageHistoryUri);
481  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
482   
483  1 History history = (History) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
484   
485  1 HistorySummary firstVersion = null;
486  1 for (HistorySummary historySummary : history.getHistorySummaries()) {
487  1 if ("1.1".equals(historySummary.getVersion())) {
488  1 firstVersion = historySummary;
489    }
490   
491  1 getMethod = executeGet(getFirstLinkByRelation(historySummary, Relations.PAGE).getHref());
492  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
493   
494  1 Page page = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
495   
496  1 checkLinks(page);
497   
498  1 for (Translation translation : page.getTranslations().getTranslations()) {
499  0 checkLinks(translation);
500    }
501    }
502   
503  1 Assert.assertNotNull(firstVersion);
504  1 Assert.assertEquals("Test page", firstVersion.getComment());
505    }
506   
 
507  1 toggle @Test
508    public void testPageTranslationHistory() throws Exception
509    {
510  1 String pageHistoryUri = buildURI(PageHistoryResource.class, getWiki(), TestConstants.TEST_SPACE_NAME,
511    TestConstants.TRANSLATIONS_PAGE_NAME).toString();
512   
513  1 GetMethod getMethod = executeGet(pageHistoryUri);
514  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
515   
516  1 History history = (History) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
517   
518  1 for (HistorySummary historySummary : history.getHistorySummaries()) {
519  1 getMethod = executeGet(getFirstLinkByRelation(historySummary, Relations.PAGE).getHref());
520  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
521   
522  1 Page page = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
523   
524  1 checkLinks(page);
525  1 checkLinks(page.getTranslations());
526    }
527    }
528   
 
529  1 toggle @Test
530    public void testGETPageChildren() throws Exception
531    {
532  1 GetMethod getMethod =
533    executeGet(buildURI(PageChildrenResource.class, getWiki(), this.spaces, this.pageName).toString());
534  1 Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
535   
536  1 Pages pages = (Pages) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
537  1 Assert.assertTrue(pages.getPageSummaries().size() > 0);
538   
539  1 for (PageSummary pageSummary : pages.getPageSummaries()) {
540  1 checkLinks(pageSummary);
541    }
542    }
543   
 
544  1 toggle @Test
545    public void testPOSTPageFormUrlEncoded() throws Exception
546    {
547  1 final String CONTENT = String.format("This is a content (%d)", System.currentTimeMillis());
548  1 final String TITLE = String.format("Title (%s)", UUID.randomUUID().toString());
549   
550  1 Page originalPage = getFirstPage();
551   
552  1 Link link = getFirstLinkByRelation(originalPage, Relations.SELF);
553  1 Assert.assertNotNull(link);
554   
555  1 NameValuePair[] nameValuePairs = new NameValuePair[2];
556  1 nameValuePairs[0] = new NameValuePair("title", TITLE);
557  1 nameValuePairs[1] = new NameValuePair("content", CONTENT);
558   
559  1 PostMethod postMethod = executePostForm(String.format("%s?method=PUT", link.getHref()), nameValuePairs,
560    TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
561  1 Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_ACCEPTED, postMethod.getStatusCode());
562   
563  1 Page modifiedPage = (Page) this.unmarshaller.unmarshal(postMethod.getResponseBodyAsStream());
564   
565  1 Assert.assertEquals(CONTENT, modifiedPage.getContent());
566  1 Assert.assertEquals(TITLE, modifiedPage.getTitle());
567    }
568   
 
569  1 toggle @Test
570    public void testPUTPageSyntax() throws Exception
571    {
572  1 Page originalPage = getFirstPage();
573   
574    // Use the plain/1.0 syntax since we are sure that the test page does not already use it.
575  1 String newSyntax = "plain/1.0";
576   
577  1 originalPage.setSyntax(newSyntax);
578   
579  1 Link link = getFirstLinkByRelation(originalPage, Relations.SELF);
580  1 Assert.assertNotNull(link);
581   
582  1 PutMethod putMethod = executePutXml(link.getHref(), originalPage,
583    TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
584  1 Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
585   
586  1 Page modifiedPage = (Page) this.unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
587   
588  1 Assert.assertEquals(newSyntax, modifiedPage.getSyntax());
589    }
590    }