aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-05-26 12:10:38 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-05-26 13:49:26 +0200
commitf769fb5f2e558c027c92b87c5ad989913793d224 (patch)
tree397947cb9b20057e44afe6cba4d1d20a0198ba4f /sonar-ws-client
parent235d3e745d68bf549ce0c5353d76f936572f7c93 (diff)
downloadsonarqube-f769fb5f2e558c027c92b87c5ad989913793d224.tar.gz
sonarqube-f769fb5f2e558c027c92b87c5ad989913793d224.zip
SONAR-2453 Update the way "FALSE-POSITIVE" reviews are managed
1- Update the DB, migration scripts & co. 2- Update the model, controller & co. 3- Update the WS Client
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java27
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java65
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java3
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java13
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshallerTest.java41
-rw-r--r--sonar-ws-client/src/test/resources/reviews/reviews-2.8.json (renamed from sonar-ws-client/src/test/resources/reviews/reviews.json)0
-rw-r--r--sonar-ws-client/src/test/resources/reviews/reviews-2.9.json1
7 files changed, 130 insertions, 20 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java
index eef8c5a475b..91c84411c83 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java
@@ -39,6 +39,7 @@ public class Review extends Model {
private String severity = null;
private String resourceKee = null;
private Integer line = null;
+ private Boolean falsePositive = null;
private List<Review.Comment> comments = new ArrayList<Review.Comment>();
/**
@@ -138,6 +139,7 @@ public class Review extends Model {
}
/**
+ * @deprecated since 2.9. Use {@link #getFalsePositive()} instead.
* @return the type
*/
public String getType() {
@@ -145,11 +147,18 @@ public class Review extends Model {
}
/**
+ * @deprecated since 2.9. Use {@link #setFalsePositive(Boolean)} instead.
* @param s
* the type to set
*/
public Review setType(String s) {
this.type = s;
+ // the following code is only here to ensure backward compatibility with 2.8
+ if ("FALSE_POSITIVE".equals(type)) {
+ falsePositive = Boolean.TRUE;
+ } else if ("VIOLATION".equals(type)) {
+ falsePositive = Boolean.FALSE;
+ }
return this;
}
@@ -218,6 +227,24 @@ public class Review extends Model {
}
/**
+ * @since 2.9
+ * @return the falsePositive
+ */
+ public Boolean getFalsePositive() {
+ return falsePositive;
+ }
+
+ /**
+ * @since 2.9
+ * @param falsePositive
+ * true if false positive
+ */
+ public Review setFalsePositive(Boolean falsePositive) {
+ this.falsePositive = falsePositive;
+ return this;
+ }
+
+ /**
* @return the comments
*/
public List<Review.Comment> getComments() {
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java
index dda32f50a08..a6701d4a18e 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java
@@ -29,6 +29,7 @@ public class ReviewQuery extends Query<Review> {
public static final String OUTPUT_PLAIN = "PLAIN";
public static final String OUTPUT_HTML = "HTML";
+ @Deprecated
private String reviewType;
private Long id;
private Long[] ids;
@@ -39,18 +40,21 @@ public class ReviewQuery extends Query<Review> {
private String[] authorLoginsOrIds;
private String[] assigneeLoginsOrIds;
private String output;
+ private String falsePositives;
public ReviewQuery() {
}
/**
- * @return the reviewType
+ * @deprecated since 2.9
+ * @return NULL
*/
public String getReviewType() {
return reviewType;
}
/**
+ * @deprecated since 2.9
* @param reviewType
* the reviewType to set
*/
@@ -122,8 +126,7 @@ public class ReviewQuery extends Query<Review> {
this.severities = severities;
return this;
}
-
-
+
/**
* @return the projectKeysOrIds
*/
@@ -131,16 +134,15 @@ public class ReviewQuery extends Query<Review> {
return projectKeysOrIds;
}
-
/**
- * @param projectKeysOrIds the projectKeysOrIds to set
+ * @param projectKeysOrIds
+ * the projectKeysOrIds to set
*/
public ReviewQuery setProjectKeysOrIds(String... projectKeysOrIds) {
this.projectKeysOrIds = projectKeysOrIds;
return this;
}
-
/**
* @return the resourceKeysOrIds
*/
@@ -148,16 +150,15 @@ public class ReviewQuery extends Query<Review> {
return resourceKeysOrIds;
}
-
/**
- * @param resourceKeysOrIds the resourceKeysOrIds to set
+ * @param resourceKeysOrIds
+ * the resourceKeysOrIds to set
*/
public ReviewQuery setResourceKeysOrIds(String... resourceKeysOrIds) {
this.resourceKeysOrIds = resourceKeysOrIds;
return this;
}
-
/**
* @return the authorLoginsOrIds
*/
@@ -165,16 +166,15 @@ public class ReviewQuery extends Query<Review> {
return authorLoginsOrIds;
}
-
/**
- * @param authorLoginsOrIds the authorLoginsOrIds to set
+ * @param authorLoginsOrIds
+ * the authorLoginsOrIds to set
*/
public ReviewQuery setAuthorLoginsOrIds(String... authorLoginsOrIds) {
this.authorLoginsOrIds = authorLoginsOrIds;
return this;
}
-
/**
* @return the assigneeLoginsOrIds
*/
@@ -182,9 +182,9 @@ public class ReviewQuery extends Query<Review> {
return assigneeLoginsOrIds;
}
-
/**
- * @param assigneeLoginsOrIds the assigneeLoginsOrIds to set
+ * @param assigneeLoginsOrIds
+ * the assigneeLoginsOrIds to set
*/
public ReviewQuery setAssigneeLoginsOrIds(String... assigneeLoginsOrIds) {
this.assigneeLoginsOrIds = assigneeLoginsOrIds;
@@ -198,11 +198,42 @@ public class ReviewQuery extends Query<Review> {
return output;
}
+ /**
+ *
+ * @param output
+ * the output
+ */
public ReviewQuery setOutput(String output) {
this.output = output;
return this;
}
+ /**
+ * @since 2.9
+ * @return the false_positives
+ */
+ public String getFalsePositives() {
+ return falsePositives;
+ }
+
+ /**
+ * Sets the 'false_positives' parameter that can be:
+ * <ul>
+ * <li>only</li>
+ * <li>with</li>
+ * <li>without</li>
+ * </ul>
+ * , 'with' being the default one on the server side. <br>
+ * <br>
+ *
+ * @since 2.9
+ * @param falsePositives
+ * the false_positives
+ */
+ public void setFalsePositives(String falsePositives) {
+ this.falsePositives = falsePositives;
+ }
+
@Override
public String getUrl() {
StringBuilder url = new StringBuilder(BASE_URL);
@@ -212,7 +243,6 @@ public class ReviewQuery extends Query<Review> {
} else if (ids != null) {
appendUrlParameter(url, "ids", ids);
}
- appendUrlParameter(url, "review_type", reviewType);
appendUrlParameter(url, "statuses", statuses);
appendUrlParameter(url, "severities", severities);
appendUrlParameter(url, "projects", projectKeysOrIds);
@@ -220,6 +250,11 @@ public class ReviewQuery extends Query<Review> {
appendUrlParameter(url, "authors", authorLoginsOrIds);
appendUrlParameter(url, "assignees", assigneeLoginsOrIds);
appendUrlParameter(url, "output", output);
+ appendUrlParameter(url, "false_positives", falsePositives);
+ if (falsePositives == null && reviewType != null) {
+ // Use of the 2.8 deprecated API: handle backward compatibility
+ appendUrlParameter(url, "review_type", reviewType);
+ }
return url.toString();
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java
index cdaf3c2bb63..449d45b3f3b 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshaller.java
@@ -38,11 +38,12 @@ public class ReviewUnmarshaller extends AbstractUnmarshaller<Review> {
review.setAuthorLogin(utils.getString(json, "author"));
review.setAssigneeLogin(utils.getString(json, "assignee"));
review.setTitle(utils.getString(json, "title"));
- review.setType(utils.getString(json, "type"));
review.setStatus(utils.getString(json, "status"));
review.setSeverity(utils.getString(json, "severity"));
review.setResourceKee(utils.getString(json, "resource"));
review.setLine(utils.getInteger(json, "line"));
+ review.setFalsePositive(utils.getBoolean(json, "falsePositive"));
+ review.setType(utils.getString(json, "type"));
Object comments = utils.getField(json, "comments");
if (comments != null) {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java
index c347fac60b3..ddb58c41d83 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java
@@ -40,11 +40,22 @@ public class ReviewQueryTest extends QueryTestCase {
@Test
public void resourceTreeViolations() {
ReviewQuery query = new ReviewQuery();
+ query.setIds(10L, 11L).setStatuses("OPEN").setSeverities("MINOR", "INFO").setProjectKeysOrIds("com.sonar.foo:bar")
+ .setResourceKeysOrIds("2", "3").setAuthorLoginsOrIds("20").setAssigneeLoginsOrIds("admin").setOutput("html")
+ .setFalsePositives("without");
+ assertThat(
+ query.getUrl(),
+ is("/api/reviews?ids=10,11&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&false_positives=without&"));
+ }
+
+ @Test
+ public void resourceTreeViolationsForSonar2_8() {
+ ReviewQuery query = new ReviewQuery();
query.setIds(10L, 11L).setReviewType("FALSE_POSITIVE").setStatuses("OPEN").setSeverities("MINOR", "INFO")
.setProjectKeysOrIds("com.sonar.foo:bar").setResourceKeysOrIds("2", "3").setAuthorLoginsOrIds("20").setAssigneeLoginsOrIds("admin")
.setOutput("html");
assertThat(
query.getUrl(),
- is("/api/reviews?ids=10,11&review_type=FALSE_POSITIVE&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&"));
+ is("/api/reviews?ids=10,11&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&review_type=FALSE_POSITIVE&"));
}
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshallerTest.java
index 22a6ae0ad48..d3f543b984c 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshallerTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshallerTest.java
@@ -33,14 +33,49 @@ import org.sonar.wsclient.services.Review.Comment;
public class ReviewUnmarshallerTest extends UnmarshallerTestCase {
@Test
- public void testToModels() {
+ public void testEmptyJSON() {
Review review = new ReviewUnmarshaller().toModel("[]");
assertThat(review, nullValue());
+ }
+
+ @Test
+ public void testToModels() {
+ List<Review> reviews = new ReviewUnmarshaller().toModels(loadFile("/reviews/reviews-2.9.json"));
+ assertThat(reviews.size(), is(2));
+
+ Review review = reviews.get(0);
+ assertThat(review.getId(), is(3L));
+ assertNotNull(review.getCreatedAt());
+ assertNotNull(review.getUpdatedAt());
+ assertThat(review.getAuthorLogin(), is("admin"));
+ assertThat(review.getAssigneeLogin(), is("admin"));
+ assertThat(review.getTitle(), is("'static' modifier out of order with the JLS suggestions."));
+ assertThat(review.getFalsePositive(), is(Boolean.FALSE));
+ assertThat(review.getStatus(), is("OPEN"));
+ assertThat(review.getSeverity(), is("MINOR"));
+ assertThat(review.getResourceKee(), is("org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration"));
+ assertThat(review.getLine(), is(33));
+ List<Comment> comments = review.getComments();
+ assertThat(comments.size(), is(4));
+ Comment comment = comments.get(0);
+ 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>"));
- List<Review> reviews = new ReviewUnmarshaller().toModels(loadFile("/reviews/reviews.json"));
+ review = reviews.get(1);
+ assertThat(review.getAssigneeLogin(), nullValue());
+ assertThat(review.getFalsePositive(), is(Boolean.TRUE));
+ }
+
+ /*
+ * Test Unmarshaller with JSON data received from a Sonar 2.8
+ */
+ @Test
+ public void testToModelsForSonar2_8() {
+ List<Review> reviews = new ReviewUnmarshaller().toModels(loadFile("/reviews/reviews-2.8.json"));
assertThat(reviews.size(), is(2));
- review = reviews.get(0);
+ Review review = reviews.get(0);
assertThat(review.getAssigneeLogin(), nullValue());
review = reviews.get(1);
diff --git a/sonar-ws-client/src/test/resources/reviews/reviews.json b/sonar-ws-client/src/test/resources/reviews/reviews-2.8.json
index 83a90bb5f74..83a90bb5f74 100644
--- a/sonar-ws-client/src/test/resources/reviews/reviews.json
+++ b/sonar-ws-client/src/test/resources/reviews/reviews-2.8.json
diff --git a/sonar-ws-client/src/test/resources/reviews/reviews-2.9.json b/sonar-ws-client/src/test/resources/reviews/reviews-2.9.json
new file mode 100644
index 00000000000..371a15119c9
--- /dev/null
+++ b/sonar-ws-client/src/test/resources/reviews/reviews-2.9.json
@@ -0,0 +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