Permalink
Browse files

Add delete comments in batch mode

  • Loading branch information...
1 parent 5ebdf5b commit 70012c6f34bbe5db79b226c13ec73726ffd84e0f @vergnesOL vergnesOL committed Feb 29, 2012
@@ -26,6 +26,8 @@ Comment createComment(long id, String comment,
Comment deleteComment(long id);
+ List<Comment> deleteComments(List<Long> ids);
+
CursoredList<Comment> getCommentsByMe();
CursoredList<Comment> getCommentsByMe(int pageSize, int pageNumber);
@@ -68,6 +68,18 @@ public Comment deleteComment(long id) {
}
@Override
+ public List<Comment> deleteComments(List<Long> ids) {
+ requireAuthorization();
+ MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>(
+ 1);
+ request.add("cids", StringUtils.join(ids));
+ JsonNode dataNode = restTemplate.postForObject(
+ buildUri("comments/destroy_batch.json"), request,
+ JsonNode.class);
+ return deserializeDataList(dataNode, Comment.class);
+ }
+
+ @Override
public CursoredList<Comment> getCommentsByMe() {
requireAuthorization();
JsonNode dataNode = restTemplate.getForObject(
@@ -287,4 +287,18 @@ private void verifyComment(Comment comment) {
assertNotNull(comment.getUser());
assertNotNull(comment.getStatus());
}
+
+ @Test
+ public void testDeleteComments() {
+ mockServer
+ .expect(requestTo("https://api.weibo.com/2/comments/destroy_batch.json"))
+ .andExpect(method(POST))
+ .andExpect(body("cids=1%2C2%2C3%2C4%2C5"))
+ .andRespond(
+ withResponse(jsonResource("comments"), responseHeaders));
+ List<Comment> comments = commentTemplate.deleteComments(Arrays.asList(
+ 1L, 2L, 3L, 4L, 5L));
+ verifyComment(comments.iterator().next());
+ assertEquals(2, comments.size());
+ }
}

0 comments on commit 70012c6

Please sign in to comment.