]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2404 Extend the Review web service API to create & update
authorFabrice Bellingard <bellingard@gmail.com>
Mon, 30 May 2011 12:58:02 +0000 (14:58 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 30 May 2011 17:19:11 +0000 (19:19 +0200)
- Java client WS: create, update and delete queries
- Added the ID of each comment on a review (JSON and XML) to be able
  to cleanly delete the last comment of a review

12 files changed:
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java
sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewCreateQuery.java [new file with mode: 0644]
sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewDeleteQuery.java [new file with mode: 0644]
sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewUpdateQuery.java [new file with mode: 0644]
sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java
sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewCreateQueryTest.java [new file with mode: 0644]
sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewDeleteQueryTest.java [new file with mode: 0644]
sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewUpdateQueryTest.java [new file with mode: 0644]
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshallerTest.java
sonar-ws-client/src/test/resources/reviews/reviews-2.9.json

index 4d485008464391edefbc711de9d9e92538636013..50341983fd331b211856fc21a4c383a38c83424e 100644 (file)
@@ -173,18 +173,17 @@ class Api::ReviewsController < Api::ApiController
   # DELETE /api/reviews
   # Required parameters:
   # - 'id' : the review id
-  # - 'comment_id' : for the moment, only 'last_comment' value is accepted
+  # - 'comment_id' : the id of the comment to delete (for the moment, only the last comment can be deleted)
   #
   # Example :
-  # - DELETE "/api/reviews/update?id=1&comment=last_comment
+  # - DELETE "/api/reviews/update?id=1&comment=5
   #
   def delete
     begin
       # 1- Get some parameters
       convert_markdown=(params[:output]=='HTML')
       comment_id = params[:comment_id]
-      raise "'comment' parameter is missing." unless comment_id
-      raise "Currently, only 'last_comment' is accepted for the 'comment' parameter." unless comment_id == 'last_comment'
+      raise "'comment_id' parameter is missing." unless comment_id
         
       # 2- Get the review or create one
       raise "No 'id' parameter has been provided." unless params[:id]
@@ -197,6 +196,7 @@ class Api::ReviewsController < Api::ApiController
       # 3- Delete the last comment if possible
       raise "Cannot delete the only existing comment of this review." if review.comments.size == 1
       last_comment = review.comments.last
+      raise "Only the last comment of a review can be deleted" unless last_comment.id == comment_id
       raise "You do not have the rights to edit this comment as it is not yours." unless last_comment.user == current_user
       review.delete_comment(last_comment.id)
       
index fe2d2073f4d0822318cc7808ab6af8427a504041..d28b1de6a738885662c38c69f876013865364dcc 100644 (file)
@@ -260,6 +260,7 @@ class Review < ActiveRecord::Base
       xml.comments do
         review_comments.each do |comment|
           xml.comment do
+            xml.id(comment.id)
             xml.author(comment.user.login)
             xml.updatedAt(Api::Utils.format_datetime(comment.updated_at))
             if convert_markdown 
@@ -293,6 +294,7 @@ class Review < ActiveRecord::Base
     comments = []
     review_comments.each do |comment|
       comments << {
+        'id' => comment.id,
         'author' => comment.user.login,
         'updatedAt' => Api::Utils.format_datetime(comment.updated_at),
         'text' => convert_markdown ? comment.html_text : comment.plain_text
index 91c84411c831de0121c30183e907f437b9b176c2..ba17f28d376d49319af205cfad0dc8e4b7c280bd 100644 (file)
@@ -251,8 +251,8 @@ public class Review extends Model {
     return comments;
   }
 
-  public Review addComments(Date updatedAt, String authorLogin, String text) {
-    this.comments.add(new Review.Comment(updatedAt, authorLogin, text));
+  public Review addComments(Long id, Date updatedAt, String authorLogin, String text) {
+    this.comments.add(new Review.Comment(id, updatedAt, authorLogin, text));
     return this;
   }
 
@@ -261,16 +261,26 @@ public class Review extends Model {
    */
   public static final class Comment extends Model {
 
+    private Long id = null;
     private String authorLogin = null;
     private Date updatedAt = null;
     private String text = null;
 
-    private Comment(Date updatedAt, String authorLogin, String text) {
+    private Comment(Long id, Date updatedAt, String authorLogin, String text) {
+      this.id = id;
       this.updatedAt = updatedAt;
       this.authorLogin = authorLogin;
       this.text = text;
     }
 
+    /**
+     * @since 2.9
+     * @return the id
+     */
+    public Long getId() {
+      return id;
+    }
+
     /**
      * @return the authorLogin
      */
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewCreateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewCreateQuery.java
new file mode 100644 (file)
index 0000000..96d7a57
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.9
+ */
+public class ReviewCreateQuery extends UpdateQuery<Review> {
+
+  private Long violationId;
+  private String text;
+  private String assignee;
+  private Boolean falsePositive;
+
+  public ReviewCreateQuery() {
+  }
+
+  /**
+   * Builds a request that will create a simple review on a violation, without any assignee.
+   * 
+   * @param violationId
+   *          The id of the violation that is reviewed
+   * @param text
+   *          The comment of the review
+   */
+  public static ReviewCreateQuery createSimpleReviewQuery(Long violationId, String text) {
+    ReviewCreateQuery query = new ReviewCreateQuery();
+    query.setText(text);
+    query.setViolationId(violationId);
+    return query;
+  }
+
+  /**
+   * Builds a request that will create a simple review on a violation and that will be assigned to the given user.
+   * 
+   * @param violationId
+   *          The id of the violation that is reviewed
+   * @param text
+   *          The comment of the review
+   * @param userLogin
+   *          The login of the user whom this review will be assigned to
+   */
+  public static ReviewCreateQuery createAssignedReviewQuery(Long violationId, String text, String userLogin) {
+    ReviewCreateQuery query = createSimpleReviewQuery(violationId, text);
+    query.setAssignee(userLogin);
+    return query;
+  }
+
+  /**
+   * Builds a request that will create a false-positive review on a violation.
+   * 
+   * @param violationId
+   *          The id of the violation that is reviewed
+   * @param text
+   *          The comment of the review
+   */
+  public static ReviewCreateQuery createFalsePositiveReviewQuery(Long violationId, String text) {
+    ReviewCreateQuery query = createSimpleReviewQuery(violationId, text);
+    query.setFalsePositive(Boolean.TRUE);
+    return query;
+  }
+
+  public Long getViolationId() {
+    return violationId;
+  }
+
+  public ReviewCreateQuery setViolationId(Long violationId) {
+    this.violationId = violationId;
+    return this;
+  }
+
+  public String getText() {
+    return text;
+  }
+
+  public ReviewCreateQuery setText(String text) {
+    this.text = text;
+    return this;
+  }
+
+  public String getAssignee() {
+    return assignee;
+  }
+
+  public ReviewCreateQuery setAssignee(String userLogin) {
+    this.assignee = userLogin;
+    return this;
+  }
+
+  public Boolean getFalsePositive() {
+    return falsePositive;
+  }
+
+  public ReviewCreateQuery setFalsePositive(Boolean falsePositive) {
+    this.falsePositive = falsePositive;
+    return this;
+  }
+
+  @Override
+  public String getUrl() {
+    StringBuilder url = new StringBuilder();
+    url.append(ReviewQuery.BASE_URL);
+    url.append("/");
+    url.append('?');
+    appendUrlParameter(url, "violation_id", getViolationId());
+    appendUrlParameter(url, "text", getText());
+    appendUrlParameter(url, "assignee", getAssignee());
+    appendUrlParameter(url, "false_positive", getFalsePositive());
+    return url.toString();
+  }
+
+  /**
+   * Property 'text' is transmitted through request body as content may exceed URL size allowed by the server.
+   */
+  @Override
+  public String getBody() {
+    return text;
+  }
+
+  @Override
+  public Class<Review> getModelClass() {
+    return Review.class;
+  }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewDeleteQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewDeleteQuery.java
new file mode 100644 (file)
index 0000000..fc919b0
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.9
+ */
+public class ReviewDeleteQuery extends CreateQuery<Review> {
+
+  private Long reviewId;
+  private Long commentId;
+
+  public ReviewDeleteQuery() {
+  }
+
+  /**
+   * Builds a request that will delete the comment of a review. For the moment, only the last comment can be deleted, and only the author of
+   * this comment is allowed to do so.
+   * 
+   * @param reviewId
+   *          the id of the review
+   * @param commentId
+   *          the id of the comment to delete
+   */
+  public static ReviewDeleteQuery deleteCommentQuery(Long reviewId, Long commentId) {
+    ReviewDeleteQuery query = new ReviewDeleteQuery();
+    query.reviewId = reviewId;
+    query.commentId = commentId;
+    return query;
+  }
+
+  public Long getReviewId() {
+    return reviewId;
+  }
+
+  public ReviewDeleteQuery setReviewId(Long reviewId) {
+    this.reviewId = reviewId;
+    return this;
+  }
+
+  public Long getCommentId() {
+    return commentId;
+  }
+
+  public ReviewDeleteQuery setCommentId(Long commentId) {
+    this.commentId = commentId;
+    return this;
+  }
+
+  @Override
+  public String getUrl() {
+    StringBuilder url = new StringBuilder();
+    url.append(ReviewQuery.BASE_URL);
+    url.append("/");
+    url.append('?');
+    appendUrlParameter(url, "id", getReviewId());
+    appendUrlParameter(url, "comment_id", getCommentId());
+    return url.toString();
+  }
+
+  @Override
+  public Class<Review> getModelClass() {
+    return Review.class;
+  }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewUpdateQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewUpdateQuery.java
new file mode 100644 (file)
index 0000000..328ec29
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.9
+ */
+public class ReviewUpdateQuery extends CreateQuery<Review> {
+
+  private Long reviewId;
+  private String text;
+  private String newText;
+  private String assignee;
+  private Boolean falsePositive;
+
+  public ReviewUpdateQuery() {
+  }
+
+  /**
+   * Builds a request that will add a comment on a an existing review.
+   * 
+   * @param reviewId
+   *          The id of the review
+   * @param text
+   *          The new comment
+   */
+  public static ReviewUpdateQuery addCommentQuery(Long reviewId, String text) {
+    ReviewUpdateQuery query = new ReviewUpdateQuery();
+    query.setReviewId(reviewId);
+    query.setNewText(text);
+    return query;
+  }
+
+  /**
+   * Builds a request that will update the false-positive status of an existing review.
+   * 
+   * @param reviewId
+   *          The id of the review
+   * @param text
+   *          The comment for this modification
+   * @param falsePositive
+   *          the new false positive status of the review
+   */
+  public static ReviewUpdateQuery updateFalsePositiveQuery(Long reviewId, String text, Boolean falsePositive) {
+    ReviewUpdateQuery query = addCommentQuery(reviewId, text);
+    query.setFalsePositive(falsePositive);
+    return query;
+  }
+
+  /**
+   * Builds a request that will reassign an existing review to the given user. <br/>
+   * <br/>
+   * To unassign the review, simply pass "none" for the user login.
+   * 
+   * @param reviewId
+   *          The id of the review that is reviewed
+   * @param userLogin
+   *          The login of the user whom this review will be assigned to, or "none" to unassign
+   */
+  public static ReviewUpdateQuery reassignQuery(Long reviewId, String userLogin) {
+    ReviewUpdateQuery query = new ReviewUpdateQuery();
+    query.setReviewId(reviewId);
+    query.setAssignee(userLogin);
+    return query;
+  }
+
+  /**
+   * Builds a request that will edit the last comment of a an existing review (if the last comment belongs to the current user).
+   * 
+   * @param reviewId
+   *          The id of the review
+   * @param text
+   *          The new text for the last comment
+   */
+  public static ReviewUpdateQuery editLastCommentQuery(Long reviewId, String text) {
+    ReviewUpdateQuery query = new ReviewUpdateQuery();
+    query.setReviewId(reviewId);
+    query.setText(text);
+    return query;
+  }
+
+  public Long getReviewId() {
+    return reviewId;
+  }
+
+  public ReviewUpdateQuery setReviewId(Long reviewId) {
+    this.reviewId = reviewId;
+    return this;
+  }
+
+  public String getText() {
+    return text;
+  }
+
+  public ReviewUpdateQuery setText(String text) {
+    this.text = text;
+    return this;
+  }
+
+  public String getNewText() {
+    return newText;
+  }
+
+  public ReviewUpdateQuery setNewText(String text) {
+    this.newText = text;
+    return this;
+  }
+
+  public String getAssignee() {
+    return assignee;
+  }
+
+  public ReviewUpdateQuery setAssignee(String userLogin) {
+    this.assignee = userLogin;
+    return this;
+  }
+
+  public Boolean getFalsePositive() {
+    return falsePositive;
+  }
+
+  public ReviewUpdateQuery setFalsePositive(Boolean falsePositive) {
+    this.falsePositive = falsePositive;
+    return this;
+  }
+
+  @Override
+  public String getUrl() {
+    StringBuilder url = new StringBuilder();
+    url.append(ReviewQuery.BASE_URL);
+    url.append("/");
+    url.append('?');
+    appendUrlParameter(url, "id", getReviewId());
+    appendUrlParameter(url, "text", getText());
+    appendUrlParameter(url, "new_text", getNewText());
+    appendUrlParameter(url, "assignee", getAssignee());
+    appendUrlParameter(url, "false_positive", getFalsePositive());
+    return url.toString();
+  }
+
+  /**
+   * Properties 'text' or 'new_text' are transmitted through request body as content may exceed URL size allowed by the server.
+   */
+  @Override
+  public String getBody() {
+    return text == null ? newText : text;
+  }
+
+  @Override
+  public Class<Review> getModelClass() {
+    return Review.class;
+  }
+}
index 449d45b3f3bff87bb6572990c15a6e45322852cc..f3fbb3a57e4060482abcf0b1a44c4e9e4183c6aa 100644 (file)
@@ -49,7 +49,8 @@ public class ReviewUnmarshaller extends AbstractUnmarshaller<Review> {
     if (comments != null) {
       for (int i = 0; i < utils.getArraySize(comments); i++) {
         Object comment = utils.getArrayElement(comments, i);
-        review.addComments(utils.getDateTime(comment, "updatedAt"), utils.getString(comment, "author"), utils.getString(comment, "text"));
+        review.addComments(utils.getLong(comment, "id"), utils.getDateTime(comment, "updatedAt"), utils.getString(comment, "author"),
+            utils.getString(comment, "text"));
       }
     }
 
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewCreateQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewCreateQueryTest.java
new file mode 100644 (file)
index 0000000..fd3ae93
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.wsclient.services;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ReviewCreateQueryTest extends QueryTestCase {
+
+  @Test
+  public void testCreateSimpleReview() {
+    ReviewCreateQuery query = ReviewCreateQuery.createSimpleReviewQuery(13L, "Hello World!");
+    assertThat(query.getUrl(), is("/api/reviews/?violation_id=13&text=Hello+World%21&"));
+    assertThat(query.getModelClass().getName(), is(Review.class.getName()));
+  }
+
+  @Test
+  public void testCreateAssignedReview() {
+    ReviewCreateQuery query = ReviewCreateQuery.createAssignedReviewQuery(13L, "Hello World!", "fabrice");
+    assertThat(query.getUrl(), is("/api/reviews/?violation_id=13&text=Hello+World%21&assignee=fabrice&"));
+  }
+
+  @Test
+  public void testCreateFalsePositiveReview() {
+    ReviewCreateQuery query = ReviewCreateQuery.createFalsePositiveReviewQuery(13L, "Hello World!");
+    assertThat(query.getUrl(), is("/api/reviews/?violation_id=13&text=Hello+World%21&false_positive=true&"));
+  }
+
+}
\ No newline at end of file
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewDeleteQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewDeleteQueryTest.java
new file mode 100644 (file)
index 0000000..ff2b22d
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.wsclient.services;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ReviewDeleteQueryTest extends QueryTestCase {
+
+  @Test
+  public void testAddComment() {
+    ReviewDeleteQuery query = ReviewDeleteQuery.deleteCommentQuery(13L, 2L);
+    assertThat(query.getUrl(), is("/api/reviews/?id=13&comment_id=2&"));
+    assertThat(query.getModelClass().getName(), is(Review.class.getName()));
+  }
+
+}
\ No newline at end of file
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewUpdateQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewUpdateQueryTest.java
new file mode 100644 (file)
index 0000000..ee28a90
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.wsclient.services;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ReviewUpdateQueryTest extends QueryTestCase {
+
+  @Test
+  public void testAddComment() {
+    ReviewUpdateQuery query = ReviewUpdateQuery.addCommentQuery(13L, "Hello World!");
+    assertThat(query.getUrl(), is("/api/reviews/?id=13&new_text=Hello+World%21&"));
+    assertThat(query.getModelClass().getName(), is(Review.class.getName()));
+  }
+
+  @Test
+  public void testEditLastComment() {
+    ReviewUpdateQuery query = ReviewUpdateQuery.editLastCommentQuery(13L, "Hello World!");
+    assertThat(query.getUrl(), is("/api/reviews/?id=13&text=Hello+World%21&"));
+  }
+
+  @Test
+  public void testReassign() {
+    ReviewUpdateQuery query = ReviewUpdateQuery.reassignQuery(13L, "fabrice");
+    assertThat(query.getUrl(), is("/api/reviews/?id=13&assignee=fabrice&"));
+  }
+
+  @Test
+  public void testUpdateFalsePositive() {
+    ReviewUpdateQuery query = ReviewUpdateQuery.updateFalsePositiveQuery(13L, "Hello World!", Boolean.TRUE);
+    assertThat(query.getUrl(), is("/api/reviews/?id=13&new_text=Hello+World%21&false_positive=true&"));
+  }
+
+}
\ No newline at end of file
index d3f543b984cf984aa0b514c895eabdfd27b9cfce..d2c4cc7356490a9605c020cd466d112407e0d50f 100644 (file)
@@ -58,6 +58,7 @@ public class ReviewUnmarshallerTest extends UnmarshallerTestCase {
     List<Comment> comments = review.getComments();
     assertThat(comments.size(), is(4));
     Comment comment = comments.get(0);
+    assertThat(comment.getId(), is(1L));
     assertNotNull(comment.getUpdatedAt());
     assertThat(comment.getAuthorLogin(), is("admin"));
     assertThat(comment.getText(), is("This is a review.<br/>And this is on multiple lines...<br/><br/><code>Wouhou!!!!!</code>"));
index 371a15119c9becbc41120c1eda6266af64cf2fcd..707438bbd310392da34c74b9eae2bc60c0c665bf 100644 (file)
@@ -1 +1 @@
-[{"id":3,"createdAt":"2011-04-26T15:44:42+0200","updatedAt":"2011-04-26T15:44:42+0200","author":"admin","assignee":"admin","title":"'static' modifier out of order with the JLS suggestions.","falsePositive":false,"status":"OPEN","severity":"MINOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","line":33,"comments":[{"author":"admin","updatedAt":"2011-04-26T15:44:42+0200","text":"This is a review.<br/>And this is on multiple lines...<br/><br/><code>Wouhou!!!!!</code>"},{"author":"admin","updatedAt":"2011-04-26T17:10:19+0200","text":"<em>Bold on multiple line?</em>"},{"author":"admin","updatedAt":"2011-04-26T17:11:02+0200","text":"And the bullets:<br/><ul><li>1 bullet</li>\n<li>2 bullets</li></ul>"},{"author":"admin","updatedAt":"2011-04-26T17:27:37+0200","text":"Wazzaa"}]},{"id":9,"createdAt":"2011-04-27T14:37:20+0200","updatedAt":"2011-04-27T14:37:20+0200","author":"admin","title":"New exception is thrown in catch block, original stack trace may be lost","falsePositive":true,"status":"OPEN","severity":"MAJOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReader","line":84,"comments":[{"author":"admin","updatedAt":"2011-04-27T14:37:20+0200","text":"Wazzaaaa"}]}]
\ No newline at end of file
+[{"id":3,"createdAt":"2011-04-26T15:44:42+0200","updatedAt":"2011-04-26T15:44:42+0200","author":"admin","assignee":"admin","title":"'static' modifier out of order with the JLS suggestions.","falsePositive":false,"status":"OPEN","severity":"MINOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","line":33,"comments":[{"id":1,"author":"admin","updatedAt":"2011-04-26T15:44:42+0200","text":"This is a review.<br/>And this is on multiple lines...<br/><br/><code>Wouhou!!!!!</code>"},{"id":2,"author":"admin","updatedAt":"2011-04-26T17:10:19+0200","text":"<em>Bold on multiple line?</em>"},{"id":3,"author":"admin","updatedAt":"2011-04-26T17:11:02+0200","text":"And the bullets:<br/><ul><li>1 bullet</li>\n<li>2 bullets</li></ul>"},{"id":4,"author":"admin","updatedAt":"2011-04-26T17:27:37+0200","text":"Wazzaa"}]},{"id":9,"createdAt":"2011-04-27T14:37:20+0200","updatedAt":"2011-04-27T14:37:20+0200","author":"admin","title":"New exception is thrown in catch block, original stack trace may be lost","falsePositive":true,"status":"OPEN","severity":"MAJOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReader","line":84,"comments":[{"id":5,"author":"admin","updatedAt":"2011-04-27T14:37:20+0200","text":"Wazzaaaa"}]}]
\ No newline at end of file