1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.storage; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
|
24 |
|
import org.apache.commons.httpclient.HttpMethod; |
25 |
|
import org.apache.commons.lang.RandomStringUtils; |
26 |
|
import org.junit.Assert; |
27 |
|
import org.junit.Before; |
28 |
|
import org.junit.Test; |
29 |
|
import org.xwiki.test.storage.framework.AbstractTest; |
30 |
|
import org.xwiki.test.storage.framework.StoreTestUtils; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
@since |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (45) |
Complexity: 11 |
Complexity Density: 0.32 |
|
38 |
|
public class DocumentTest extends AbstractTest |
39 |
|
{ |
40 |
|
private String spaceName; |
41 |
|
private String pageName; |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
43 |
8 |
@Before... |
44 |
|
public void setUp() |
45 |
|
{ |
46 |
8 |
this.spaceName = this.getClass().getSimpleName(); |
47 |
8 |
this.pageName = this.getTestMethodName(); |
48 |
|
} |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
50 |
2 |
@Test... |
51 |
|
public void testRollback() throws Exception |
52 |
|
{ |
53 |
2 |
final String spaceName = "DocumentTest"; |
54 |
2 |
final String pageName = "testRollback"; |
55 |
|
|
56 |
2 |
final String versionOne = "This is version one"; |
57 |
2 |
final String versionTwo = "This is version two"; |
58 |
|
|
59 |
2 |
final String pageURL = this.getAddressPrefix() + "get/" + spaceName + "/" + pageName + "?xpage=plain"; |
60 |
|
|
61 |
|
|
62 |
2 |
doPostAsAdmin(spaceName, pageName, null, "delete", "confirm=1", null); |
63 |
|
|
64 |
|
|
65 |
2 |
doPostAsAdmin(spaceName, pageName, null, "save", null, |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
2 |
new HashMap<String, String>() {{... |
67 |
2 |
put("content", versionOne); |
68 |
|
}}); |
69 |
|
|
70 |
|
|
71 |
2 |
doPostAsAdmin(spaceName, pageName, null, "save", null, |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
2 |
new HashMap<String, String>() {{... |
73 |
2 |
put("content", versionTwo); |
74 |
|
}}); |
75 |
|
|
76 |
|
|
77 |
2 |
Assert.assertEquals("<p>" + versionTwo + "</p>", StoreTestUtils.getPageAsString(pageURL)); |
78 |
|
|
79 |
|
|
80 |
2 |
doPostAsAdmin(spaceName, pageName, null, "rollback", "rev=1.1&confirm=1", null); |
81 |
|
|
82 |
|
|
83 |
2 |
Assert.assertEquals("<p>" + versionOne + "</p>", StoreTestUtils.getPageAsString(pageURL)); |
84 |
|
|
85 |
|
|
86 |
2 |
HttpMethod ret = |
87 |
|
doPostAsAdmin(spaceName, pageName, null, "preview", "xpage=plain", |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
2 |
new HashMap<String, String>() {{... |
89 |
2 |
put("content", "{{velocity}}$doc.getVersion(){{/velocity}}"); |
90 |
|
}}); |
91 |
2 |
Assert.assertEquals("<p>3.1</p>", new String(ret.getResponseBody(), "UTF-8")); |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
@since |
99 |
|
@since |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
101 |
2 |
@Test... |
102 |
|
public void testSaveOfThreeHundredKilobyteDocument() throws Exception |
103 |
|
{ |
104 |
2 |
final String content = RandomStringUtils.randomAlphanumeric(300000); |
105 |
2 |
final HttpMethod ret = |
106 |
|
this.doPostAsAdmin(this.spaceName, this.pageName, null, "save", null, |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
2 |
new HashMap<String, String>() {{... |
108 |
2 |
put("content", content); |
109 |
|
}}); |
110 |
|
|
111 |
2 |
Assert.assertEquals(302, ret.getStatusCode()); |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
114 |
2 |
@Test... |
115 |
|
public void testDocumentIsSameAfterSaving() throws Exception |
116 |
|
{ |
117 |
2 |
final String content = |
118 |
|
"{{groovy}}\n" |
119 |
|
+ "def content = 'test content'\n" |
120 |
|
+ "doc.setContent(content);\n" |
121 |
|
+ "doc.saveAsAuthor();\n" |
122 |
|
+ "println(doc.getContent());\n" |
123 |
|
+ "{{/groovy}}"; |
124 |
|
|
125 |
|
|
126 |
2 |
doPostAsAdmin(this.spaceName, this.pageName, null, "delete", "confirm=1", null); |
127 |
|
|
128 |
|
|
129 |
2 |
doPostAsAdmin(this.spaceName, this.pageName, null, "save", null, |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
2 |
new HashMap<String, String>(){{... |
131 |
2 |
put("content", content); |
132 |
|
}}); |
133 |
|
|
134 |
2 |
final String url = |
135 |
|
this.getAddressPrefix() + "view/" + this.spaceName + "/" + this.pageName + "?xpage=plain"; |
136 |
|
|
137 |
2 |
Assert.assertEquals("<p>test content</p>", StoreTestUtils.getPageAsString(url)); |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
140 |
2 |
@Test... |
141 |
|
public void testOtherDocumentIsSameAfterSaving() throws Exception |
142 |
|
{ |
143 |
2 |
final String content = |
144 |
|
"{{groovy}}\n" |
145 |
|
+ "def content = 'test content'\n" |
146 |
|
+ "otherDoc = xwiki.getDocument('" + this.spaceName + "','" + this.pageName + "x')\n" |
147 |
|
+ "otherDoc.setContent(content);\n" |
148 |
|
+ "otherDoc.saveAsAuthor();\n" |
149 |
|
+ "println(otherDoc.getContent());\n" |
150 |
|
+ "{{/groovy}}"; |
151 |
|
|
152 |
|
|
153 |
2 |
doPostAsAdmin(this.spaceName, this.pageName, null, "delete", "confirm=1", null); |
154 |
|
|
155 |
|
|
156 |
2 |
doPostAsAdmin(this.spaceName, this.pageName, null, "save", null, |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
2 |
new HashMap<String, String>(){{... |
158 |
2 |
put("content", content); |
159 |
|
}}); |
160 |
|
|
161 |
2 |
final String url = |
162 |
|
this.getAddressPrefix() + "view/" + this.spaceName + "/" + this.pageName + "?xpage=plain"; |
163 |
|
|
164 |
2 |
Assert.assertEquals("<p>test content</p>", StoreTestUtils.getPageAsString(url)); |
165 |
|
} |
166 |
|
} |