diff options
author | Jacek Poreda <jacek.poreda@sonarsource.com> | 2023-06-02 14:05:00 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-06-02 20:02:46 +0000 |
commit | f2ba697894b609580067e51346dfff9588ca9a18 (patch) | |
tree | 62d71feaf9de3079b87f025e6617e7a87b8c6116 | |
parent | c2f97c9acd95a7f426534a6d78583279e7f0f71b (diff) | |
download | sonarqube-f2ba697894b609580067e51346dfff9588ca9a18.tar.gz sonarqube-f2ba697894b609580067e51346dfff9588ca9a18.zip |
SONAR-19339 Fix propagation of 'resolution' field for api/hotspots/pull
-rw-r--r-- | server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java | 26 | ||||
-rw-r--r-- | server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml | 1 |
2 files changed, 20 insertions, 7 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java index f9832c2a662..332bb74f04e 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Set; import java.util.stream.IntStream; import java.util.stream.Stream; +import javax.annotation.Nullable; import org.junit.Rule; import org.junit.Test; import org.sonar.api.rule.RuleKey; @@ -227,21 +228,24 @@ public class IssueDaoIT { List<String> statusesA = List.of(STATUS_OPEN, STATUS_REVIEWED, STATUS_CLOSED, STATUS_RESOLVED); IntStream.range(0, statusesA.size()).forEach(i -> insertBranchIssue(branchA, fileA, rule, "A" + i, statusesA.get(i), updatedAt)); + insertBranchIssue(branchA, fileA, rule, "WithResolution", STATUS_RESOLVED, RESOLUTION_FIXED, updatedAt); + ComponentDto branchB = db.components().insertProjectBranch(project, b -> b.setKey("branchB")); ComponentDto fileB = db.components().insertComponent(newFileDto(branchB)); List<String> statusesB = List.of(STATUS_OPEN, STATUS_RESOLVED); IntStream.range(0, statusesB.size()).forEach(i -> insertBranchIssue(branchB, fileB, rule, "B" + i, statusesB.get(i), updatedAt)); - List<IssueDto> branchAIssuesA1 = underTest.selectByBranch(db.getSession(), Set.of("issueA0", "issueA1", "issueA3"), + List<IssueDto> branchAIssuesA1 = underTest.selectByBranch(db.getSession(), Set.of("issueA0", "issueA1", "issueA3", "issueWithResolution"), buildSelectByBranchQuery(branchA, "java", false, changedSince)); assertThat(branchAIssuesA1) - .extracting(IssueDto::getKey, IssueDto::getStatus) + .extracting(IssueDto::getKey, IssueDto::getStatus, IssueDto::getResolution) .containsExactlyInAnyOrder( - tuple("issueA0", STATUS_OPEN), - tuple("issueA1", STATUS_REVIEWED), - tuple("issueA3", STATUS_RESOLVED)); + tuple("issueA0", STATUS_OPEN, null), + tuple("issueA1", STATUS_REVIEWED, null), + tuple("issueA3", STATUS_RESOLVED, null), + tuple("issueWithResolution", STATUS_RESOLVED, RESOLUTION_FIXED)); assertThat(branchAIssuesA1.get(0)) .extracting(IssueDto::getMessage, IssueDto::parseMessageFormattings) @@ -622,12 +626,20 @@ public class IssueDaoIT { return RULE_TYPES_EXCEPT_HOTSPOT[nextInt(RULE_TYPES_EXCEPT_HOTSPOT.length)]; } - private void insertBranchIssue(ComponentDto branch, ComponentDto file, RuleDto rule, String id, String status, Long updateAt) { - db.issues().insert(rule, branch, file, i -> i.setKee("issue" + id).setStatus(status).setUpdatedAt(updateAt).setType(randomRuleTypeExceptHotspot()) + private void insertBranchIssue(ComponentDto branch, ComponentDto file, RuleDto rule, String id, String status, @Nullable String resolution, Long updateAt) { + db.issues().insert(rule, branch, file, i -> i.setKee("issue" + id) + .setStatus(status) + .setResolution(resolution) + .setUpdatedAt(updateAt) + .setType(randomRuleTypeExceptHotspot()) .setMessage("message") .setMessageFormattings(MESSAGE_FORMATTING)); } + private void insertBranchIssue(ComponentDto branch, ComponentDto file, RuleDto rule, String id, String status, Long updateAt) { + insertBranchIssue(branch, file, rule, id, status, null, updateAt); + } + private static IssueQueryParams buildSelectByBranchQuery(ComponentDto branch, String language, boolean resolvedOnly, Long changedSince) { return new IssueQueryParams(branch.uuid(), List.of(language), List.of(), List.of(), resolvedOnly, changedSince); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml index 956359ff38c..d1d0849563e 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml @@ -654,6 +654,7 @@ i.rule_uuid as ruleUuid, i.created_at as createdAt, i.status as status, + i.resolution as resolution, r.rule_type as ruleType, r.plugin_name as ruleRepo, r.plugin_rule_key as ruleKey, |