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 |
|
|
25 |
|
import javax.ws.rs.core.MediaType; |
26 |
|
|
27 |
|
import org.apache.commons.httpclient.HttpStatus; |
28 |
|
import org.apache.commons.httpclient.NameValuePair; |
29 |
|
import org.apache.commons.httpclient.methods.GetMethod; |
30 |
|
import org.apache.commons.httpclient.methods.PostMethod; |
31 |
|
import org.junit.Assert; |
32 |
|
import org.junit.Before; |
33 |
|
import org.junit.Test; |
34 |
|
import org.xwiki.model.reference.DocumentReference; |
35 |
|
import org.xwiki.rest.Relations; |
36 |
|
import org.xwiki.rest.model.jaxb.Comment; |
37 |
|
import org.xwiki.rest.model.jaxb.Comments; |
38 |
|
import org.xwiki.rest.model.jaxb.History; |
39 |
|
import org.xwiki.rest.model.jaxb.HistorySummary; |
40 |
|
import org.xwiki.rest.model.jaxb.Page; |
41 |
|
import org.xwiki.rest.resources.comments.CommentsResource; |
42 |
|
import org.xwiki.rest.resources.pages.PageHistoryResource; |
43 |
|
import org.xwiki.test.rest.framework.AbstractHttpTest; |
44 |
|
import org.xwiki.test.ui.TestUtils; |
45 |
|
|
|
|
| 94.3% |
Uncovered Elements: 4 (70) |
Complexity: 8 |
Complexity Density: 0.13 |
|
46 |
|
public class CommentsResourceTest extends AbstractHttpTest |
47 |
|
{ |
48 |
|
private String wikiName; |
49 |
|
|
50 |
|
private List<String> spaces; |
51 |
|
|
52 |
|
private String pageName; |
53 |
|
|
54 |
|
private DocumentReference reference; |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
56 |
6 |
@Before... |
57 |
|
@Override |
58 |
|
public void setUp() throws Exception |
59 |
|
{ |
60 |
6 |
super.setUp(); |
61 |
|
|
62 |
6 |
this.wikiName = getWiki(); |
63 |
6 |
this.spaces = Arrays.asList(getTestClassName()); |
64 |
6 |
this.pageName = getTestMethodName(); |
65 |
|
|
66 |
6 |
this.reference = new DocumentReference(this.wikiName, this.spaces, this.pageName); |
67 |
|
|
68 |
|
|
69 |
6 |
this.testUtils.rest().delete(this.reference); |
70 |
6 |
this.testUtils.rest().savePage(this.reference); |
71 |
|
} |
72 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1PASS
|
|
73 |
1 |
@Override... |
74 |
|
@Test |
75 |
|
public void testRepresentation() throws Exception |
76 |
|
{ |
77 |
|
|
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void testPOSTComment() throws Exception |
82 |
|
{ |
83 |
1 |
String commentsUri = buildURI(CommentsResource.class, getWiki(), this.spaces, this.pageName).toString(); |
84 |
|
|
85 |
1 |
GetMethod getMethod = executeGet(commentsUri); |
86 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
87 |
|
|
88 |
1 |
Comments comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
89 |
|
|
90 |
1 |
int numberOfComments = comments.getComments().size(); |
91 |
|
|
92 |
1 |
Comment comment = objectFactory.createComment(); |
93 |
1 |
comment.setText("Comment"); |
94 |
|
|
95 |
1 |
PostMethod postMethod = executePostXml(commentsUri, comment, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), |
96 |
|
TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword()); |
97 |
1 |
Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode()); |
98 |
|
|
99 |
1 |
getMethod = executeGet(commentsUri); |
100 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
101 |
|
|
102 |
1 |
comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
103 |
|
|
104 |
1 |
Assert.assertEquals(numberOfComments + 1, comments.getComments().size()); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
107 |
1 |
@Test... |
108 |
|
public void testPOSTCommentWithTextPlain() throws Exception |
109 |
|
{ |
110 |
1 |
String commentsUri = buildURI(CommentsResource.class, getWiki(), this.spaces, this.pageName).toString(); |
111 |
|
|
112 |
1 |
GetMethod getMethod = executeGet(commentsUri); |
113 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
114 |
|
|
115 |
1 |
Comments comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
116 |
|
|
117 |
1 |
int numberOfComments = comments.getComments().size(); |
118 |
|
|
119 |
1 |
PostMethod postMethod = executePost(commentsUri, "Comment", MediaType.TEXT_PLAIN, |
120 |
|
TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword()); |
121 |
1 |
Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode()); |
122 |
|
|
123 |
1 |
getMethod = executeGet(commentsUri); |
124 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
125 |
|
|
126 |
1 |
comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
127 |
|
|
128 |
1 |
Assert.assertEquals(numberOfComments + 1, comments.getComments().size()); |
129 |
|
} |
130 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
131 |
1 |
@Test... |
132 |
|
public void testGETComment() throws Exception |
133 |
|
{ |
134 |
1 |
String commentsUri = buildURI(CommentsResource.class, getWiki(), this.spaces, this.pageName).toString(); |
135 |
|
|
136 |
1 |
GetMethod getMethod = executeGet(commentsUri); |
137 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
138 |
|
|
139 |
1 |
Comments comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
140 |
|
|
141 |
1 |
for (Comment comment : comments.getComments()) { |
142 |
0 |
checkLinks(comment); |
143 |
|
} |
144 |
|
} |
145 |
|
|
|
|
| 76.9% |
Uncovered Elements: 3 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
1PASS
|
|
146 |
1 |
@Test... |
147 |
|
public void testGETCommentsAtPreviousVersions() throws Exception |
148 |
|
{ |
149 |
1 |
String pageHistoryUri = buildURI(PageHistoryResource.class, getWiki(), this.spaces, this.pageName).toString(); |
150 |
|
|
151 |
1 |
GetMethod getMethod = executeGet(pageHistoryUri); |
152 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
153 |
|
|
154 |
1 |
History history = (History) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
155 |
|
|
156 |
1 |
for (HistorySummary historySummary : history.getHistorySummaries()) { |
157 |
1 |
getMethod = executeGet(getFirstLinkByRelation(historySummary, Relations.PAGE).getHref()); |
158 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
159 |
|
|
160 |
1 |
Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
161 |
|
|
162 |
1 |
if (getFirstLinkByRelation(page, Relations.COMMENTS) != null) { |
163 |
0 |
getMethod = executeGet(getFirstLinkByRelation(page, Relations.COMMENTS).getHref()); |
164 |
0 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
165 |
|
} |
166 |
|
} |
167 |
|
} |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
169 |
1 |
@Test... |
170 |
|
public void testPOSTCommentFormUrlEncoded() throws Exception |
171 |
|
{ |
172 |
1 |
String commentsUri = buildURI(CommentsResource.class, getWiki(), this.spaces, this.pageName).toString(); |
173 |
|
|
174 |
1 |
GetMethod getMethod = executeGet(commentsUri); |
175 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
176 |
|
|
177 |
1 |
Comments comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
178 |
|
|
179 |
1 |
int numberOfComments = comments.getComments().size(); |
180 |
|
|
181 |
1 |
NameValuePair[] nameValuePairs = new NameValuePair[1]; |
182 |
1 |
nameValuePairs[0] = new NameValuePair("text", "Comment"); |
183 |
|
|
184 |
1 |
PostMethod postMethod = executePostForm(commentsUri, nameValuePairs, |
185 |
|
TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword()); |
186 |
1 |
Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode()); |
187 |
|
|
188 |
1 |
getMethod = executeGet(commentsUri); |
189 |
1 |
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); |
190 |
|
|
191 |
1 |
comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); |
192 |
|
|
193 |
1 |
Assert.assertEquals(numberOfComments + 1, comments.getComments().size()); |
194 |
|
} |
195 |
|
} |