Search in sources :

Example 1 with Comments

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());
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) Comments(org.xwiki.rest.model.jaxb.Comments) GetMethod(org.apache.commons.httpclient.methods.GetMethod) CommentsResource(org.xwiki.rest.resources.comments.CommentsResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 2 with Comments

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());
}
Also used : Comment(org.xwiki.rest.model.jaxb.Comment) PostMethod(org.apache.commons.httpclient.methods.PostMethod) Comments(org.xwiki.rest.model.jaxb.Comments) GetMethod(org.apache.commons.httpclient.methods.GetMethod) CommentsResource(org.xwiki.rest.resources.comments.CommentsResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 3 with Comments

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());
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) Comments(org.xwiki.rest.model.jaxb.Comments) GetMethod(org.apache.commons.httpclient.methods.GetMethod) CommentsResource(org.xwiki.rest.resources.comments.CommentsResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 4 with Comments

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);
    }
}
Also used : Comment(org.xwiki.rest.model.jaxb.Comment) Comments(org.xwiki.rest.model.jaxb.Comments) GetMethod(org.apache.commons.httpclient.methods.GetMethod) CommentsResource(org.xwiki.rest.resources.comments.CommentsResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 5 with Comments

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);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) Comments(org.xwiki.rest.model.jaxb.Comments) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

Comments (org.xwiki.rest.model.jaxb.Comments)6 GetMethod (org.apache.commons.httpclient.methods.GetMethod)4 Test (org.junit.Test)4 CommentsResource (org.xwiki.rest.resources.comments.CommentsResource)4 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)4 PostMethod (org.apache.commons.httpclient.methods.PostMethod)3 XWikiException (com.xpn.xwiki.XWikiException)2 Document (com.xpn.xwiki.api.Document)2 XWikiRestException (org.xwiki.rest.XWikiRestException)2 RangeIterable (org.xwiki.rest.internal.RangeIterable)2 Comment (org.xwiki.rest.model.jaxb.Comment)2 NameValuePair (org.apache.commons.httpclient.NameValuePair)1