Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
Add delete comment feature
Browse files Browse the repository at this point in the history
  • Loading branch information
vergnesOL committed Feb 29, 2012
1 parent 0166246 commit 5ebdf5b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public interface CommentOperations {
Comment createComment(long id, String comment,
boolean commentFromExternalSource);

Comment deleteComment(long id);

CursoredList<Comment> getCommentsByMe();

CursoredList<Comment> getCommentsByMe(int pageSize, int pageNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public Comment createComment(long id, String comment,
request, Comment.class);
}

@Override
public Comment deleteComment(long id) {
requireAuthorization();
MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>(
1);
request.add("cid", String.valueOf(id));
return restTemplate.postForObject(buildUri("comments/destroy.json"),
request, Comment.class);
}

@Override
public CursoredList<Comment> getCommentsByMe() {
requireAuthorization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ public void setUp() {
getRestTemplate(), true);
}

@Test
public void testCreateComment() {
mockServer
.expect(requestTo("https://api.weibo.com/2/comments/create.json"))
.andExpect(method(POST))
.andExpect(
body("id=1&comment=%E6%88%91%E5%96%9C%E6%AC%A2%E4%BD%A0%E5%81%9A%E7%9A%84&comment_ori=0"))
.andRespond(
withResponse(jsonResource("comment"), responseHeaders));
Comment comment = commentTemplate.createComment(1, "我喜欢你做的");
verifyComment(comment);
}

@Test
public void testDeleteComment() {
mockServer
.expect(requestTo("https://api.weibo.com/2/comments/destroy.json"))
.andExpect(method(POST))
.andExpect(body("cid=1"))
.andRespond(
withResponse(jsonResource("comment"), responseHeaders));
Comment comment = commentTemplate.deleteComment(1);
verifyComment(comment);
}

@Test
public void testGetCommentsByMe() {
mockServer
Expand Down Expand Up @@ -92,6 +117,19 @@ public void testGetCommentsOnStatus() {
assertEquals(10, comments.getNextCursor());
}

@Test
public void testGetCommentsOnStatuses() {
mockServer
.expect(requestTo("https://api.weibo.com/2/comments/show_batch.json?cids=1%2C2%2C3%2C4%2C5%2C6"))
.andExpect(method(GET))
.andRespond(
withResponse(jsonResource("comments"), responseHeaders));
List<Comment> comments = commentTemplate.getCommentsOnStatuses(Arrays
.asList(1L, 2L, 3L, 4L, 5L, 6L));
verifyComment(comments.iterator().next());
assertEquals(2, comments.size());
}

@Test
public void testGetCommentsOnStatusPagination() {
mockServer
Expand Down Expand Up @@ -249,30 +287,4 @@ private void verifyComment(Comment comment) {
assertNotNull(comment.getUser());
assertNotNull(comment.getStatus());
}

@Test
public void testGetCommentsOnStatuses() {
mockServer
.expect(requestTo("https://api.weibo.com/2/comments/show_batch.json?cids=1%2C2%2C3%2C4%2C5%2C6"))
.andExpect(method(GET))
.andRespond(
withResponse(jsonResource("comments"), responseHeaders));
List<Comment> comments = commentTemplate.getCommentsOnStatuses(Arrays
.asList(1L, 2L, 3L, 4L, 5L, 6L));
verifyComment(comments.iterator().next());
assertEquals(2, comments.size());
}

@Test
public void testCreateComment() {
mockServer
.expect(requestTo("https://api.weibo.com/2/comments/create.json"))
.andExpect(method(POST))
.andExpect(
body("id=1&comment=%E6%88%91%E5%96%9C%E6%AC%A2%E4%BD%A0%E5%81%9A%E7%9A%84&comment_ori=0"))
.andRespond(
withResponse(jsonResource("comment"), responseHeaders));
Comment comment = commentTemplate.createComment(1, "我喜欢你做的");
verifyComment(comment);
}
}

0 comments on commit 5ebdf5b

Please sign in to comment.