aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2022-06-21 16:44:20 +0200
committersonartech <sonartech@sonarsource.com>2022-06-22 16:09:14 +0000
commit308e3b537734beb775c9dff31f67b7cbadba8b08 (patch)
tree7be8ae205b9ea353274534a22fda7db11bc90aa6 /server
parent5d2cc92609ee308d456c914705869536b209fc2b (diff)
downloadsonarqube-308e3b537734beb775c9dff31f67b7cbadba8b08.tar.gz
sonarqube-308e3b537734beb775c9dff31f67b7cbadba8b08.zip
SONAR-16542 fixed an issue where rule repo key was not returned
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java12
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/PullActionProtobufObjectGenerator.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java6
3 files changed, 16 insertions, 4 deletions
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
index e57b9166489..fca2debffd2 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
@@ -126,9 +126,19 @@ public class IssueDbTester {
@SafeVarargs
public final IssueDto insertIssue(Consumer<IssueDto>... populators) {
RuleDto rule = db.rules().insertIssueRule();
+ return insertIssue(rule, populators);
+ }
+
+ /**
+ * Inserts an issue.
+ *
+ * @throws AssertionError if rule is not Security Hotspot
+ */
+ @SafeVarargs
+ public final IssueDto insertIssue(RuleDto ruleDto, Consumer<IssueDto>... populators) {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- IssueDto issue = newIssue(rule, project, file)
+ IssueDto issue = newIssue(ruleDto, project, file)
.setType(RULE_TYPES_EXCEPT_HOTSPOTS[new Random().nextInt(RULE_TYPES_EXCEPT_HOTSPOTS.length)]);
stream(populators).forEach(p -> p.accept(issue));
return insertIssue(issue);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/PullActionProtobufObjectGenerator.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/PullActionProtobufObjectGenerator.java
index 6d3e6a85ec7..d4f066c6249 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/PullActionProtobufObjectGenerator.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/PullActionProtobufObjectGenerator.java
@@ -54,7 +54,7 @@ public class PullActionProtobufObjectGenerator {
issueBuilder.setKey(issueDto.getKey());
issueBuilder.setCreationDate(issueDto.getCreatedAt());
issueBuilder.setResolved(issueDto.getStatus().equals(org.sonar.api.issue.Issue.STATUS_RESOLVED));
- issueBuilder.setRuleKey(issueDto.getRuleKey().rule());
+ issueBuilder.setRuleKey(issueDto.getRuleKey().toString());
if (issueDto.isManualSeverity() && issueDto.getSeverity() != null) {
issueBuilder.setUserSeverity(issueDto.getSeverity());
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java
index 1e0d1cc2f0f..f9da48c1680 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java
@@ -141,7 +141,9 @@ public class PullActionTest {
.setChecksum("hash")
.setTextRange(textRange);
- IssueDto issueDto = issueDbTester.insertIssue(p -> p.setSeverity("MINOR")
+
+ RuleDto rule = db.rules().insertIssueRule(r -> r.setRepositoryKey("java").setRuleKey("S1000"));
+ IssueDto issueDto = issueDbTester.insertIssue(rule, p -> p.setSeverity("MINOR")
.setManualSeverity(true)
.setMessage("message")
.setCreatedAt(NOW)
@@ -164,7 +166,7 @@ public class PullActionTest {
assertThat(issueLite.getUserSeverity()).isEqualTo("MINOR");
assertThat(issueLite.getCreationDate()).isEqualTo(NOW);
assertThat(issueLite.getResolved()).isTrue();
- assertThat(issueLite.getRuleKey()).isEqualTo(issueDto.getRuleKey().rule());
+ assertThat(issueLite.getRuleKey()).isEqualTo("java:S1000");
assertThat(issueLite.getType()).isEqualTo(Common.RuleType.forNumber(issueDto.getType()).name());
Issues.Location location = issueLite.getMainLocation();