aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-ws-client/src')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java10
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java17
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java7
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java15
-rw-r--r--sonar-ws-client/src/test/resources/violations/false-positive.json2
5 files changed, 42 insertions, 9 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
index 1c74a823b52..704bc76efa8 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
@@ -34,7 +34,7 @@ public class Violation extends Model {
private String resourceQualifier = null;
private Date createdAt = null;
private boolean switchedOff;
- private Long reviewId = null;
+ private Review review = null;
public String getMessage() {
return message;
@@ -195,15 +195,15 @@ public class Violation extends Model {
/**
* @since 2.8
*/
- public Long getReviewId() {
- return reviewId;
+ public Review getReview() {
+ return review;
}
/**
* @since 2.8
*/
- public Violation setReviewId(Long l) {
- this.reviewId = l;
+ public Violation setReview(Review review) {
+ this.review = review;
return this;
}
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
index d75e2b64808..e3eb5dd60de 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
@@ -31,6 +31,7 @@ public class ViolationQuery extends Query<Violation> {
private String[] categories;
private String[] severities;
private Integer limit;
+ private Boolean includeReview;
public ViolationQuery(String resourceKeyOrId) {
this.resourceKeyOrId = resourceKeyOrId;
@@ -128,6 +129,21 @@ public class ViolationQuery extends Query<Violation> {
return this;
}
+ /**
+ * @since 2.8
+ */
+ public Boolean getIncludeReview() {
+ return includeReview;
+ }
+
+ /**
+ * @since 2.8
+ */
+ public ViolationQuery setIncludeReview(Boolean includeReview) {
+ this.includeReview = includeReview;
+ return this;
+ }
+
@Override
public String getUrl() {
StringBuilder url = new StringBuilder(BASE_URL);
@@ -142,6 +158,7 @@ public class ViolationQuery extends Query<Violation> {
appendUrlParameter(url, "rules", ruleKeys);
appendUrlParameter(url, "categories", categories);
appendUrlParameter(url, "priorities", severities);
+ appendUrlParameter(url, "include_review", includeReview);
return url.toString();
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
index a73d4b3c4fa..c8b5558eb22 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
@@ -34,7 +34,12 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> {
violation.setSeverity(utils.getString(json, "priority"));
violation.setCreatedAt(utils.getDateTime(json, "createdAt"));
violation.setSwitchedOff(utils.getBoolean(json, "switchedOff"));
- violation.setReviewId(utils.getLong(json, "review"));
+
+ Object review = utils.getField(json, "review");
+ if (review != null) {
+ ReviewUnmarshaller reviewUnmarshaller = new ReviewUnmarshaller();
+ violation.setReview(reviewUnmarshaller.parse(review));
+ }
Object rule = utils.getField(json, "rule");
if (rule != null) {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java
index 16e07efff38..32e00d2dbd8 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java
@@ -20,6 +20,7 @@
package org.sonar.wsclient.unmarshallers;
import org.junit.Test;
+import org.sonar.wsclient.services.Review;
import org.sonar.wsclient.services.Violation;
import java.util.List;
@@ -28,6 +29,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
public class ViolationUnmarshallerTest extends UnmarshallerTestCase {
@@ -54,7 +56,7 @@ public class ViolationUnmarshallerTest extends UnmarshallerTestCase {
assertThat(violation.getResourceQualifier(), is("CLA"));
assertThat(violation.getResourceScope(), is("FIL"));
assertThat(violation.isSwitchedOff(), is(false));
- assertThat(violation.getReviewId(), nullValue());
+ assertThat(violation.getReview(), nullValue());
}
@Test
@@ -70,7 +72,16 @@ public class ViolationUnmarshallerTest extends UnmarshallerTestCase {
public void testSwitchedOff() {
Violation violation = new ViolationUnmarshaller().toModel(loadFile("/violations/false-positive.json"));
assertThat(violation.isSwitchedOff(), is(true));
- assertThat(violation.getReviewId(), is(123L));
+ }
+
+ @Test
+ public void testViolationDecoratedWithReview() {
+ Violation violation = new ViolationUnmarshaller().toModel(loadFile("/violations/violation-with-review.json"));
+ Review review = violation.getReview();
+ assertNotNull(review);
+ assertThat(review.getId(), is(3L));
+ assertThat(review.getComments().size(), is(4));
+ assertThat(review.getComments().get(1).getText(), is("<em>Bold on multiple line?</em>"));
}
/**
diff --git a/sonar-ws-client/src/test/resources/violations/false-positive.json b/sonar-ws-client/src/test/resources/violations/false-positive.json
index 2165e9455c1..e96a394d911 100644
--- a/sonar-ws-client/src/test/resources/violations/false-positive.json
+++ b/sonar-ws-client/src/test/resources/violations/false-positive.json
@@ -1,3 +1,3 @@
[
- {"message":"throw java.lang.Exception","switchedOff": true, "review": 123, "priority":"MAJOR","rule":{"key":"pmd:SignatureDeclareThrowsException","name":"Signature Declare Throws Exception","category":"Maintainability"},"resource":{"key":"org.apache.excalibur.components:excalibur-pool-instrumented:org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool","name":"TraceableResourceLimitingPool","scope":"FIL","qualifier":"CLA","language":"java"}}
+ {"message":"throw java.lang.Exception","switchedOff": true, "priority":"MAJOR","rule":{"key":"pmd:SignatureDeclareThrowsException","name":"Signature Declare Throws Exception","category":"Maintainability"},"resource":{"key":"org.apache.excalibur.components:excalibur-pool-instrumented:org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool","name":"TraceableResourceLimitingPool","scope":"FIL","qualifier":"CLA","language":"java"}}
] \ No newline at end of file