use of org.xwiki.rest.model.jaxb.Comments in project xwiki-platform by xwiki.
the class CommentsResourceTest method testPOSTCommentWithTextPlain.
@Test
public void testPOSTCommentWithTextPlain() throws Exception {
String commentsUri = buildURI(CommentsResource.class, getWiki(), this.spaces, this.pageName).toString();
GetMethod getMethod = executeGet(commentsUri);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Comments comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
int numberOfComments = comments.getComments().size();
PostMethod postMethod = executePost(commentsUri, "Comment", MediaType.TEXT_PLAIN, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode());
getMethod = executeGet(commentsUri);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(numberOfComments + 1, comments.getComments().size());
}
use of org.xwiki.rest.model.jaxb.Comments in project xwiki-platform by xwiki.
the class CommentsResourceTest method testPOSTComment.
@Test
public void testPOSTComment() throws Exception {
String commentsUri = buildURI(CommentsResource.class, getWiki(), this.spaces, this.pageName).toString();
GetMethod getMethod = executeGet(commentsUri);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Comments comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
int numberOfComments = comments.getComments().size();
Comment comment = objectFactory.createComment();
comment.setText("Comment");
PostMethod postMethod = executePostXml(commentsUri, comment, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode());
getMethod = executeGet(commentsUri);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(numberOfComments + 1, comments.getComments().size());
}
use of org.xwiki.rest.model.jaxb.Comments in project xwiki-platform by xwiki.
the class CommentsResourceTest method testPOSTCommentFormUrlEncoded.
@Test
public void testPOSTCommentFormUrlEncoded() throws Exception {
String commentsUri = buildURI(CommentsResource.class, getWiki(), this.spaces, this.pageName).toString();
GetMethod getMethod = executeGet(commentsUri);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Comments comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
int numberOfComments = comments.getComments().size();
NameValuePair[] nameValuePairs = new NameValuePair[1];
nameValuePairs[0] = new NameValuePair("text", "Comment");
PostMethod postMethod = executePostForm(commentsUri, nameValuePairs, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode());
getMethod = executeGet(commentsUri);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(numberOfComments + 1, comments.getComments().size());
}
use of org.xwiki.rest.model.jaxb.Comments in project xwiki-platform by xwiki.
the class CommentsResourceTest method testGETComment.
@Test
public void testGETComment() throws Exception {
String commentsUri = buildURI(CommentsResource.class, getWiki(), this.spaces, this.pageName).toString();
GetMethod getMethod = executeGet(commentsUri);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Comments comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
for (Comment comment : comments.getComments()) {
checkLinks(comment);
}
}
use of org.xwiki.rest.model.jaxb.Comments in project xwiki-platform by xwiki.
the class CommentsResourceImpl method getComments.
@Override
public Comments getComments(String wikiName, String spaceName, String pageName, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
Comments comments = objectFactory.createComments();
Vector<com.xpn.xwiki.api.Object> xwikiComments = doc.getComments();
RangeIterable<com.xpn.xwiki.api.Object> ri = new RangeIterable<com.xpn.xwiki.api.Object>(xwikiComments, start, number);
for (com.xpn.xwiki.api.Object xwikiComment : ri) {
comments.getComments().add(DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, xwikiComment, Utils.getXWikiApi(componentManager), withPrettyNames));
}
return comments;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
Aggregations