diff options
16 files changed, 205 insertions, 45 deletions
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest/shouldCloseReviewWithoutCorrespondingViolation-result.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest/shouldCloseReviewWithoutCorrespondingViolation-result.xml index 49123b1a1a9..7b3d60ec42c 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest/shouldCloseReviewWithoutCorrespondingViolation-result.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest/shouldCloseReviewWithoutCorrespondingViolation-result.xml @@ -5,24 +5,24 @@ status="OPEN" rule_failure_permanent_id="1" resource_id="555" - created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/> + created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/> <reviews id="2" status="CLOSED" rule_failure_permanent_id="2" resource_id="666" - created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/> + created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/> <reviews id="3" status="OPEN" rule_failure_permanent_id="3" resource_id="666" - created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/> + created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/> <reviews id="4" status="CLOSED" rule_failure_permanent_id="2" resource_id="666" - created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/> + created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/> </dataset>
\ No newline at end of file diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanReviewsTest/purgeOrphanReviews-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanReviewsTest/purgeOrphanReviews-result.xml index 7680bdd39c0..50fc18b74c4 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanReviewsTest/purgeOrphanReviews-result.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanReviewsTest/purgeOrphanReviews-result.xml @@ -16,7 +16,7 @@ rule_failure_permanent_id="1" resource_id="555" project_id="1" - created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/> + created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]"/> <!-- Following must have been deleted <reviews @@ -25,7 +25,7 @@ rule_failure_permanent_id="2" resource_id="666" project_id="2" - created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/> + created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]"/> --> <review_comments diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanReviewsTest/purgeOrphanReviews.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanReviewsTest/purgeOrphanReviews.xml index 01da1669b40..6408b5a1947 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanReviewsTest/purgeOrphanReviews.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanReviewsTest/purgeOrphanReviews.xml @@ -16,14 +16,14 @@ rule_failure_permanent_id="1" resource_id="555" project_id="1" - created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/> + created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]"/> <reviews id="2" status="CLOSED" rule_failure_permanent_id="2" resource_id="666" project_id="2" - created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/> + created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" false_positive="[null]" severity="[null]" resource_line="[null]"/> <review_comments id="1" diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java index c5d25eb586f..039029276d7 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java +++ b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java @@ -40,7 +40,7 @@ public class SchemaMigration { - complete the Derby DDL file used for unit tests : sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl */ - public static final int LAST_VERSION = 200; + public static final int LAST_VERSION = 201; public final static String TABLE_NAME = "schema_migrations"; diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb index 742b81c7d2f..ddf519dca1e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb @@ -123,7 +123,7 @@ class ReviewsController < ApplicationController violation.save! end - @review.review_type = (false_positive ? Review::TYPE_FALSE_POSITIVE : Review::TYPE_VIOLATION) + @review.false_positive = false_positive @review.assignee = nil @review.save! unless params[:comment].blank? @@ -203,7 +203,7 @@ class ReviewsController < ApplicationController if violation.review.nil? violation.build_review(:user_id => current_user.id) end - violation.review.review_type=(false_positive ? Review::TYPE_FALSE_POSITIVE : Review::TYPE_VIOLATION) + violation.review.false_positive=false_positive violation.review.assignee=nil violation.review.save! violation.review.comments.create(:review_text => params[:comment], :user_id => current_user.id) @@ -285,7 +285,7 @@ class ReviewsController < ApplicationController end def search_reviews - options = {'review_type' => 'VIOLATION'} + options = { 'false_positives' => 'without' } unless @statuses == [''] options['statuses']=@statuses.join(',') end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb index 7fecb7d342a..3951dc0edaf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb @@ -27,14 +27,10 @@ class Review < ActiveRecord::Base belongs_to :rule_failure, :foreign_key => 'rule_failure_permanent_id', :primary_key => 'permanent_id' validates_presence_of :user, :message => "can't be empty" - validates_presence_of :review_type, :message => "can't be empty" validates_presence_of :status, :message => "can't be empty" before_save :assign_project - TYPE_VIOLATION = 'VIOLATION' - TYPE_FALSE_POSITIVE = 'FALSE_POSITIVE' - STATUS_OPEN = 'OPEN' STATUS_CLOSED = 'CLOSED' @@ -90,11 +86,27 @@ class Review < ActiveRecord::Base def self.search(options={}) conditions=[] values={} + + # --- 'review_type' is deprecated since 2.9 --- + # Following code just for backward compatibility + review_type = options['review_type'] + if review_type + conditions << 'false_positive=:false_positive' + if review_type == 'FALSE_POSITIVE' + values[:false_positive]=true + else + values[:false_positive]=false + end + end + # --- End of code for backward compatibility code --- - review_type = options['review_type'].split(',') if options['review_type'] - if review_type && review_type.size>0 && !review_type[0].blank? - conditions << 'review_type in (:review_type)' - values[:review_type]=review_type + false_positives = options['false_positives'] + if false_positives == "only" + conditions << 'false_positive=:false_positive' + values[:false_positive]=true + elsif false_positives == "without" + conditions << 'false_positive=:false_positive' + values[:false_positive]=false end ids=options['ids'].split(',') if options['ids'] @@ -202,7 +214,7 @@ class Review < ActiveRecord::Base xml.author(user.login) xml.assignee(assignee.login) if assignee xml.title(title) - xml.type(review_type) + xml.falsePositive(false_positive) xml.status(status) xml.severity(severity) xml.resource(resource.kee) if resource @@ -235,7 +247,7 @@ class Review < ActiveRecord::Base json['author'] = user.login json['assignee'] = assignee.login if assignee json['title'] = title if title - json['type'] = review_type + json['falsePositive'] = false_positive json['status'] = status json['severity'] = severity json['resource'] = resource.kee if resource diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb index eda6220717f..0ce59a962d9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb @@ -102,8 +102,7 @@ class RuleFailure < ActiveRecord::Base def build_review(options={}) if review.nil? self.review=Review.new( - {:review_type => Review::TYPE_VIOLATION, - :status => Review::STATUS_OPEN, + {:status => Review::STATUS_OPEN, :severity => Sonar::RulePriority.to_s(failure_level), :resource_line => line, :resource => snapshot.resource, diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/201_change_false_positive_on_reviews.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/201_change_false_positive_on_reviews.rb new file mode 100644 index 00000000000..d2c2312cf7b --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/201_change_false_positive_on_reviews.rb @@ -0,0 +1,39 @@ +# +# Sonar, entreprise quality control 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 +# + +# +# Sonar 2.9 +# +class ChangeFalsePositiveOnReviews < ActiveRecord::Migration + + def self.up + add_column 'reviews', 'false_positive', :boolean, :null => true, :default => false + Review.reset_column_information + + Review.find(:all).each do |review| + review.false_positive= (review.review_type == 'FALSE_POSITIVE') + review.save! + end + + remove_column 'reviews', 'review_type' + Review.reset_column_information + end + +end diff --git a/sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl b/sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl index d7e6a848481..2391427880f 100644 --- a/sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl +++ b/sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl @@ -489,13 +489,13 @@ CREATE TABLE REVIEWS ( USER_ID INTEGER, ASSIGNEE_ID INTEGER, TITLE VARCHAR(500), - REVIEW_TYPE VARCHAR(10), STATUS VARCHAR(10), SEVERITY VARCHAR(10), RULE_FAILURE_PERMANENT_ID INTEGER, PROJECT_ID INTEGER, RESOURCE_ID INTEGER, RESOURCE_LINE INTEGER, + FALSE_POSITIVE SMALLINT, primary key (id) ); 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 |