From 9f16852c3d219379989f7480f90d66ffa5fb6509 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Tue, 31 May 2011 14:05:06 +0200 Subject: SONAR-2488 Add the id for violations in the WS Client --- .../java/org/sonar/wsclient/services/Violation.java | 19 +++++++++++++++++-- .../wsclient/unmarshallers/ViolationUnmarshaller.java | 1 + .../unmarshallers/ViolationUnmarshallerTest.java | 13 +++++++------ .../src/test/resources/violations/false-positive.json | 2 +- .../violations/violation-with-incorrect-line.json | 1 + .../resources/violations/violation-with-review.json | 2 +- .../violations/violation-without-optional-fields.json | 2 +- .../src/test/resources/violations/violations.json | 4 ++-- 8 files changed, 31 insertions(+), 13 deletions(-) (limited to 'sonar-ws-client/src') 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 704bc76efa8..f88a3157ff1 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 @@ -23,6 +23,7 @@ import java.util.Date; public class Violation extends Model { + private Long id = null; private String message = null; private String severity = null; private Integer line = null; @@ -85,8 +86,8 @@ public class Violation extends Model { public void setLine(Integer line) { if (line != null && line < 1) { /* - * This shouldn't happen, however line would be normalized to null if web service returns incorrect value (less than 1) - * in compliance with a contract for getLine method. Normalization added in 2.8 - see http://jira.codehaus.org/browse/SONAR-2386 + * This shouldn't happen, however line would be normalized to null if web service returns incorrect value (less than 1) in compliance + * with a contract for getLine method. Normalization added in 2.8 - see http://jira.codehaus.org/browse/SONAR-2386 */ this.line = null; } else { @@ -206,4 +207,18 @@ public class Violation extends Model { this.review = review; return this; } + + /** + * @since 2.9 + */ + public Long getId() { + return id; + } + + /** + * @since 2.9 + */ + public void setId(Long id) { + this.id = id; + } } 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 c8b5558eb22..f721c7135c1 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 @@ -29,6 +29,7 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller { WSUtils utils = WSUtils.getINSTANCE(); Violation violation = new Violation(); + violation.setId(utils.getLong(json, "id")); violation.setMessage(utils.getString(json, "message")); violation.setLine(utils.getInteger(json, "line")); violation.setSeverity(utils.getString(json, "priority")); 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 32e00d2dbd8..1abfaa662c2 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,12 +19,6 @@ */ 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; - import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.notNullValue; @@ -32,6 +26,12 @@ import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +import java.util.List; + +import org.junit.Test; +import org.sonar.wsclient.services.Review; +import org.sonar.wsclient.services.Violation; + public class ViolationUnmarshallerTest extends UnmarshallerTestCase { @Test @@ -43,6 +43,7 @@ public class ViolationUnmarshallerTest extends UnmarshallerTestCase { assertThat(violations.size(), is(2)); violation = violations.get(0); + assertThat(violation.getId(), is(1L)); assertThat(violation.getMessage(), is("throw java.lang.Exception")); assertThat(violation.hasLine(), is(true)); assertThat(violation.getLine(), is(97)); 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 e96a394d911..ee3293087b3 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, "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"}} + {"id":1,"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 diff --git a/sonar-ws-client/src/test/resources/violations/violation-with-incorrect-line.json b/sonar-ws-client/src/test/resources/violations/violation-with-incorrect-line.json index ef2ed50b85c..aa6b51c062e 100644 --- a/sonar-ws-client/src/test/resources/violations/violation-with-incorrect-line.json +++ b/sonar-ws-client/src/test/resources/violations/violation-with-incorrect-line.json @@ -1,5 +1,6 @@ [ { + "id":1, "message":"1 branches need to be covered by unit tests to reach the minimum threshold of 65.0% branch coverage.", "line":0, "priority":"MAJOR", diff --git a/sonar-ws-client/src/test/resources/violations/violation-with-review.json b/sonar-ws-client/src/test/resources/violations/violation-with-review.json index 4de5df67356..1cc185766f4 100644 --- a/sonar-ws-client/src/test/resources/violations/violation-with-review.json +++ b/sonar-ws-client/src/test/resources/violations/violation-with-review.json @@ -1 +1 @@ -[{"message":"'static' modifier out of order with the JLS suggestions.","line":33,"priority":"MINOR","createdAt":"2011-04-26T15:17:46+0200","rule":{"key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck","name":"Modifier Order"},"resource":{"key":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","name":"CodeReaderConfiguration","scope":"FIL","qualifier":"CLA","language":"java"},"review":{"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.","type":"VIOLATION","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.
And this is on multiple lines...

''Wouhou!!!!!''"},{"author":"admin","updatedAt":"2011-04-26T17:10:19+0200","text":"Bold on multiple line?"},{"author":"admin","updatedAt":"2011-04-26T17:11:02+0200","text":"And the bullets:
"},{"author":"admin","updatedAt":"2011-04-26T17:27:37+0200","text":"Wazzaa"}]}}] \ No newline at end of file +[{"id":1,"message":"'static' modifier out of order with the JLS suggestions.","line":33,"priority":"MINOR","createdAt":"2011-04-26T15:17:46+0200","rule":{"key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck","name":"Modifier Order"},"resource":{"key":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","name":"CodeReaderConfiguration","scope":"FIL","qualifier":"CLA","language":"java"},"review":{"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.","type":"VIOLATION","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.
And this is on multiple lines...

''Wouhou!!!!!''"},{"author":"admin","updatedAt":"2011-04-26T17:10:19+0200","text":"Bold on multiple line?"},{"author":"admin","updatedAt":"2011-04-26T17:11:02+0200","text":"And the bullets:
"},{"author":"admin","updatedAt":"2011-04-26T17:27:37+0200","text":"Wazzaa"}]}}] \ 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 7923febf306..c787433e07c 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","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"}} + {"id":1,"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 92c98b332f0..66353635fab 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","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"}} + {"id":1,"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"}}, + {"id":2,"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 -- cgit v1.2.3