1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (39) |
Complexity: 4 |
Complexity Density: 0.11 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
56 |
3 |
@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 |
|
|
70 |
3 |
this.testUtils.rest().delete(this.referenceFR); |
71 |
3 |
this.testUtils.rest().delete(this.referenceDefault); |
72 |
|
} |
73 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
74 |
1 |
@Override... |
75 |
|
@Test |
76 |
|
public void testRepresentation() throws Exception |
77 |
|
{ |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
80 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
88 |
1 |
@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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
} |