aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2019-12-05 15:12:52 +0100
committerSonarTech <sonartech@sonarsource.com>2020-01-13 20:46:27 +0100
commit20800515eafd42ebe95017409df4430c7dc16e60 (patch)
tree7ef803bcaf9fe8b7263ff1c766cb0514326e2b02
parent29a5dec5cff33ddb418d09a743b8f95999e0a867 (diff)
downloadsonarqube-20800515eafd42ebe95017409df4430c7dc16e60.tar.gz
sonarqube-20800515eafd42ebe95017409df4430c7dc16e60.zip
SONAR-12719 add resolution to response of api/hotspots/show
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java35
-rw-r--r--sonar-ws/src/main/protobuf/ws-hotspots.proto3
3 files changed, 36 insertions, 5 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java
index 862f73f53ac..5aa202080ae 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ShowAction.java
@@ -103,8 +103,7 @@ public class ShowAction implements HotspotsWsAction {
private void formatHotspot(ShowWsResponse.Builder builder, IssueDto hotspot) {
builder.setKey(hotspot.getKey());
ofNullable(hotspot.getStatus()).ifPresent(builder::setStatus);
- // FIXME resolution field will be added later
- // ofNullable(hotspot.getResolution()).ifPresent(builder::setResolution);
+ ofNullable(hotspot.getResolution()).ifPresent(builder::setResolution);
ofNullable(hotspot.getLine()).ifPresent(builder::setLine);
builder.setMessage(nullToEmpty(hotspot.getMessage()));
ofNullable(hotspot.getAssigneeUuid()).ifPresent(builder::setAssignee);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java
index 9f394b96e9e..61bcb3c5bec 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ShowActionTest.java
@@ -30,9 +30,11 @@ import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.sonar.api.issue.Issue;
import org.sonar.api.rules.RuleType;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
@@ -175,6 +177,37 @@ public class ShowActionTest {
}
@Test
+ @UseDataProvider("statusAndResolutionCombinations")
+ public void returns_status_and_resolution(String status, @Nullable String resolution) {
+ ComponentDto project = dbTester.components().insertPrivateProject();
+ userSessionRule.registerComponents(project);
+ userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
+ ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
+ RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
+ IssueDto hotspot = dbTester.issues().insertIssue(newHotspot(project, file, rule).setStatus(status).setResolution(resolution));
+
+ Hotspots.ShowWsResponse response = newRequest(hotspot)
+ .executeProtobuf(Hotspots.ShowWsResponse.class);
+
+ assertThat(response.getStatus()).isEqualTo(status);
+ if (resolution == null) {
+ assertThat(response.hasResolution()).isFalse();
+ } else {
+ assertThat(response.getResolution()).isEqualTo(resolution);
+ }
+ }
+
+ @DataProvider
+ public static Object[][] statusAndResolutionCombinations() {
+ return new Object[][] {
+ {Issue.STATUS_TO_REVIEW, null},
+ {Issue.STATUS_REVIEWED, Issue.RESOLUTION_FIXED},
+ {Issue.STATUS_REVIEWED, Issue.RESOLUTION_SAFE},
+ {Issue.STATUS_CLOSED, Issue.RESOLUTION_REMOVED}
+ };
+ }
+
+ @Test
public void returns_hotspot_component_and_rule() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
@@ -193,7 +226,7 @@ public class ShowActionTest {
}
@Test
- public void returns_no_textrange_when_locations_have_none() {
+ public void returns_no_textRange_when_locations_have_none() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
diff --git a/sonar-ws/src/main/protobuf/ws-hotspots.proto b/sonar-ws/src/main/protobuf/ws-hotspots.proto
index cef59629a8e..e851afb7adb 100644
--- a/sonar-ws/src/main/protobuf/ws-hotspots.proto
+++ b/sonar-ws/src/main/protobuf/ws-hotspots.proto
@@ -57,8 +57,7 @@ message ShowWsResponse {
optional Component project = 3;
optional Rule rule = 4;
optional string status = 5;
-// FIXME resolution field will be added later
-// optional string resolution = 6;
+ optional string resolution = 6;
optional int32 line = 7;
optional string message = 8;
optional string assignee = 9;