diff options
Diffstat (limited to 'sonar-ws-client')
6 files changed, 37 insertions, 17 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 e29c37396ba..0d5b816425f 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 @@ -33,7 +33,8 @@ public class Violation extends Model { private String resourceScope = null; private String resourceQualifier = null; private Date createdAt = null; - private boolean switchedOff; + private boolean falsePositive; + private Long reviewId = null; public String getMessage() { return message; @@ -159,16 +160,24 @@ public class Violation extends Model { /** * @since 2.8 */ - public Violation setSwitchedOff(boolean switchedOff) { - this.switchedOff = switchedOff; + public Violation setFalsePositive(Boolean b) { + this.falsePositive = (b != null && b); return this; } /** * @since 2.8 */ - public boolean isSwitchedOff() { - return switchedOff; + public boolean isFalsePositive() { + return falsePositive; } + public Long getReviewId() { + return reviewId; + } + + public Violation setReviewId(Long l) { + this.reviewId = l; + return this; + } } 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 df62e5c0e16..45f692b582c 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 @@ -33,7 +33,8 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> { violation.setLine(utils.getInteger(json, "line")); violation.setSeverity(utils.getString(json, "priority")); violation.setCreatedAt(utils.getDateTime(json, "createdAt")); - violation.setSwitchedOff(utils.getBoolean(json, "switchedOff")); + violation.setFalsePositive(utils.getBoolean(json, "falsePositive")); + violation.setReviewId(utils.getLong(json, "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 3f3da0e81fc..dc9a8c4cc2d 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 @@ -19,21 +19,21 @@ */ package org.sonar.wsclient.unmarshallers; +import org.junit.Test; +import org.sonar.wsclient.services.Violation; + +import java.util.List; + 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.assertThat; -import java.util.List; - -import org.junit.Test; -import org.sonar.wsclient.services.Violation; - public class ViolationUnmarshallerTest extends UnmarshallerTestCase { @Test - public void toModels() { + public void testToModels() { Violation violation = new ViolationUnmarshaller().toModel("[]"); assertThat(violation, nullValue()); @@ -52,15 +52,22 @@ public class ViolationUnmarshallerTest extends UnmarshallerTestCase { assertThat(violation.getResourceName(), is("TraceableResourceLimitingPool")); assertThat(violation.getResourceQualifier(), is("CLA")); assertThat(violation.getResourceScope(), is("FIL")); - assertThat(violation.isSwitchedOff(), is(true)); + assertThat(violation.isFalsePositive(), is(false)); + assertThat(violation.getReviewId(), nullValue()); } @Test - public void violationWithoutLineNumber() { + public void testViolationWithoutLineNumber() { Violation violation = new ViolationUnmarshaller().toModel(loadFile("/violations/violation-without-optional-fields.json")); assertThat(violation.getMessage(), not(nullValue())); assertThat(violation.getLine(), nullValue()); assertThat(violation.getCreatedAt(), nullValue()); } + @Test + public void testFalsePositive() { + Violation violation = new ViolationUnmarshaller().toModel(loadFile("/violations/false-positive.json")); + assertThat(violation.isFalsePositive(), is(true)); + assertThat(violation.getReviewId(), is(123L)); + } } diff --git a/sonar-ws-client/src/test/resources/violations/false-positive.json b/sonar-ws-client/src/test/resources/violations/false-positive.json new file mode 100644 index 00000000000..d84cb1528d5 --- /dev/null +++ b/sonar-ws-client/src/test/resources/violations/false-positive.json @@ -0,0 +1,3 @@ +[ + {"message":"throw java.lang.Exception","falsePositive": 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"}} +]
\ No newline at end of file diff --git a/sonar-ws-client/src/test/resources/violations/violation-without-optional-fields.json b/sonar-ws-client/src/test/resources/violations/violation-without-optional-fields.json index 7c8aa24b70a..7923febf306 100644 --- a/sonar-ws-client/src/test/resources/violations/violation-without-optional-fields.json +++ b/sonar-ws-client/src/test/resources/violations/violation-without-optional-fields.json @@ -1,3 +1,3 @@ [ - {"message":"throw java.lang.Exception","priority":"MAJOR","switchedOff":true,"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","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 diff --git a/sonar-ws-client/src/test/resources/violations/violations.json b/sonar-ws-client/src/test/resources/violations/violations.json index 1dbad54bb6e..92c98b332f0 100644 --- a/sonar-ws-client/src/test/resources/violations/violations.json +++ b/sonar-ws-client/src/test/resources/violations/violations.json @@ -1,4 +1,4 @@ [ - {"message":"throw java.lang.Exception","line":97,"createdAt":"2010-12-01T13:55:22+0300","priority":"MAJOR","switchedOff":true,"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":"The user-supplied array 'threads' is stored directly.","line":242,"createdAt":"2010-12-01T13:55:22+0300","priority":"MAJOR","switchedOff":false,"rule":{"key":"pmd:ArrayIsStoredDirectly","name":"Security - Array is stored directly","category":"Reliability"},"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","line":97,"createdAt":"2010-12-01T13:55:22+0300","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":"The user-supplied array 'threads' is stored directly.","line":242,"createdAt":"2010-12-01T13:55:22+0300","priority":"MAJOR","rule":{"key":"pmd:ArrayIsStoredDirectly","name":"Security - Array is stored directly","category":"Reliability"},"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 |