diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-04-28 08:50:54 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-04-28 15:15:49 +0200 |
commit | c3fabd05ae340704746d2b3be87b584bdd0da475 (patch) | |
tree | dab8469d0b567c7b34cd8a87498cbf974b173ad5 /sonar-ws-client/src/test | |
parent | 50a43f7b9dab293b61fabe742252dca659f2e4ca (diff) | |
download | sonarqube-c3fabd05ae340704746d2b3be87b584bdd0da475.tar.gz sonarqube-c3fabd05ae340704746d2b3be87b584bdd0da475.zip |
SONAR-2382 Create a new "reviews" web service API
Diffstat (limited to 'sonar-ws-client/src/test')
3 files changed, 123 insertions, 0 deletions
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 new file mode 100644 index 00000000000..340a27d3900 --- /dev/null +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java @@ -0,0 +1,56 @@ +/* + * Sonar, open source software quality management 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 + */ +package org.sonar.wsclient.services; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Test; + +public class ReviewQueryTest extends QueryTestCase { + + @Test + public void testSimpleQueryForResource() { + Resource resource = mock(Resource.class); + when(resource.getId()).thenReturn(69); + ReviewQuery query = ReviewQuery.createForResource(resource); + assertThat(query.getUrl(), is("/api/reviews?id=69&")); + assertThat(query.getModelClass().getName(), is(Review.class.getName())); + } + + @Test + public void resourceTreeViolations() { + ReviewQuery query = new ReviewQuery(); + query.setIds(10L, 11L); + query.setReviewType("FALSE_POSITIVE"); + query.setStatuses("OPEN"); + query.setSeverities("MINOR", "INFO"); + query.setProjects(1L); + query.setResources(2L, 3L); + query.setAuthors(20L); + query.setAssignees(21L); + query.setHtml(Boolean.TRUE); + assertThat( + query.getUrl(), + is("/api/reviews?ids=10,11&review_type=FALSE_POSITIVE&statuses=OPEN&severities=MINOR,INFO&projects=1&resources=2,3&authors=20&assignees=21&html=true&")); + } +} 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 new file mode 100644 index 00000000000..22a6ae0ad48 --- /dev/null +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ReviewUnmarshallerTest.java @@ -0,0 +1,66 @@ +/* + * Sonar, open source software quality management 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 + */ +package org.sonar.wsclient.unmarshallers; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +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.Review.Comment; + +public class ReviewUnmarshallerTest extends UnmarshallerTestCase { + + @Test + public void testToModels() { + Review review = new ReviewUnmarshaller().toModel("[]"); + assertThat(review, nullValue()); + + List<Review> reviews = new ReviewUnmarshaller().toModels(loadFile("/reviews/reviews.json")); + assertThat(reviews.size(), is(2)); + + review = reviews.get(0); + assertThat(review.getAssigneeLogin(), nullValue()); + + review = reviews.get(1); + 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.getType(), is("VIOLATION")); + 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>")); + } + +} diff --git a/sonar-ws-client/src/test/resources/reviews/reviews.json b/sonar-ws-client/src/test/resources/reviews/reviews.json new file mode 100644 index 00000000000..83a90bb5f74 --- /dev/null +++ b/sonar-ws-client/src/test/resources/reviews/reviews.json @@ -0,0 +1 @@ +[{"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","type":"VIOLATION","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"}]},{"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.<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"}]}]
\ No newline at end of file |