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

File PageTranslationResourceTest.java

 

Code metrics

0
35
4
1
131
84
4
0.11
8.75
4
1

Classes

Class Line # Actions
PageTranslationResourceTest 42 35 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 3 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   
26    import org.apache.commons.httpclient.HttpStatus;
27    import org.apache.commons.httpclient.methods.DeleteMethod;
28    import org.apache.commons.httpclient.methods.GetMethod;
29    import org.apache.commons.httpclient.methods.PutMethod;
30    import org.junit.Before;
31    import org.junit.Test;
32    import org.xwiki.model.reference.DocumentReference;
33    import org.xwiki.rest.model.jaxb.Page;
34    import org.xwiki.rest.resources.pages.PageTranslationResource;
35    import org.xwiki.test.rest.framework.AbstractHttpTest;
36    import org.xwiki.test.ui.TestUtils;
37   
38    import static org.junit.Assert.assertEquals;
39    import static org.junit.Assert.assertFalse;
40    import static org.junit.Assert.assertTrue;
41   
 
42    public class PageTranslationResourceTest extends AbstractHttpTest
43    {
44    private String wikiName;
45   
46    private String space;
47   
48    private List<String> spaces;
49   
50    private String pageName;
51   
52    private DocumentReference referenceDefault;
53   
54    private DocumentReference referenceFR;
55   
 
56  3 toggle @Before
57    @Override
58    public void setUp() throws Exception
59    {
60  3 super.setUp();
61   
62  3 this.wikiName = getWiki();
63  3 this.space = getTestClassName();
64  3 this.spaces = Arrays.asList(this.space);
65  3 this.pageName = getTestMethodName();
66  3 this.referenceDefault = new DocumentReference(this.wikiName, this.spaces, this.pageName);
67  3 this.referenceFR = new DocumentReference(this.wikiName, this.spaces, this.pageName, Locale.FRENCH);
68   
69    // Clean
70  3 this.testUtils.rest().delete(this.referenceFR);
71  3 this.testUtils.rest().delete(this.referenceDefault);
72    }
73   
 
74  1 toggle @Override
75    @Test
76    public void testRepresentation() throws Exception
77    {
78    }
79   
 
80  1 toggle @Test
81    public void testGETNotExistingPage() throws Exception
82    {
83  1 GetMethod getMethod = executeGet(buildURI(PageTranslationResource.class, getWiki(),
84    Arrays.asList("NOTEXISTING"), "NOTEXISTING", Locale.FRENCH).toString());
85  1 assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
86    }
87   
 
88  1 toggle @Test
89    public void testPUTGETDELETETranslation() throws Exception
90    {
91  1 Page newPage = this.objectFactory.createPage();
92  1 newPage.setTitle("fr titre");
93  1 newPage.setContent("fr contenue");
94  1 newPage.setLanguage(Locale.FRENCH.toString());
95   
96  1 assertFalse(this.testUtils.rest().exists(this.referenceDefault));
97   
98  1 String uri =
99    buildURI(PageTranslationResource.class, getWiki(), this.spaces, this.pageName, Locale.FRENCH).toString();
100   
101    // PUT
102  1 PutMethod putMethod = executePutXml(uri, newPage, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(),
103    TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
104  1 assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
105  1 Page modifiedPage = (Page) this.unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
106   
107  1 assertEquals("fr titre", modifiedPage.getTitle());
108  1 assertEquals("fr contenue", modifiedPage.getContent());
109  1 assertEquals(Locale.FRENCH.toString(), modifiedPage.getLanguage());
110   
111  1 assertTrue(this.testUtils.rest().exists(this.referenceFR));
112  1 assertFalse(this.testUtils.rest().exists(this.referenceDefault));
113   
114    // GET
115  1 GetMethod getMethod = executeGet(uri);
116  1 assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
117  1 modifiedPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
118   
119  1 assertEquals("fr titre", modifiedPage.getTitle());
120  1 assertEquals("fr contenue", modifiedPage.getContent());
121  1 assertEquals(Locale.FRENCH.toString(), modifiedPage.getLanguage());
122   
123    // DELETE
124  1 DeleteMethod deleteMethod = executeDelete(uri, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(),
125    TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
126  1 assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode());
127   
128  1 assertFalse(this.testUtils.rest().exists(this.referenceDefault));
129  1 assertFalse(this.testUtils.rest().exists(this.referenceFR));
130    }
131    }