From 308e3b537734beb775c9dff31f67b7cbadba8b08 Mon Sep 17 00:00:00 2001 From: Lukasz Jarocki Date: Tue, 21 Jun 2022 16:44:20 +0200 Subject: [PATCH] SONAR-16542 fixed an issue where rule repo key was not returned --- .../java/org/sonar/db/issue/IssueDbTester.java | 12 +++++++++++- .../ws/pull/PullActionProtobufObjectGenerator.java | 2 +- .../org/sonar/server/issue/ws/PullActionTest.java | 6 ++++-- 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... 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... 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(); -- 2.39.5