aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-task-projectanalysis
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2020-07-07 10:09:34 +0200
committersonartech <sonartech@sonarsource.com>2020-07-09 20:05:35 +0000
commit191fde8d2cfc1a69b4e981b67e4e0bdbb33bba7c (patch)
treea8ac75655809b537b42672ca7b2c7ecbc92e17d5 /server/sonar-ce-task-projectanalysis
parent3adb1969a53fb22066453c36fe9d0acb6902d343 (diff)
downloadsonarqube-191fde8d2cfc1a69b4e981b67e4e0bdbb33bba7c.tar.gz
sonarqube-191fde8d2cfc1a69b4e981b67e4e0bdbb33bba7c.zip
SONAR-13591 Fix copy of issue tags from rule tags
Diffstat (limited to 'server/sonar-ce-task-projectanalysis')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java46
2 files changed, 47 insertions, 2 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java
index 602981259fc..6b5a9fa6e1b 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/ProtobufIssueDiskCache.java
@@ -19,7 +19,6 @@
*/
package org.sonar.ce.task.projectanalysis.util.cache;
-import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import java.io.BufferedOutputStream;
@@ -116,7 +115,7 @@ public class ProtobufIssueDiskCache implements DiskCache<DefaultIssue> {
defaultIssue.setAttributes(next.getAttributesMap());
defaultIssue.setAuthorLogin(next.hasAuthorLogin() ? next.getAuthorLogin() : null);
next.getCommentsList().forEach(c -> defaultIssue.addComment(toDefaultIssueComment(c)));
- defaultIssue.setTags(ImmutableSet.copyOf(TAGS_SPLITTER.split(next.hasTags() ? "" : next.getTags())));
+ defaultIssue.setTags(ImmutableSet.copyOf(TAGS_SPLITTER.split(next.getTags())));
defaultIssue.setLocations(next.hasLocations() ? next.getLocations() : null);
defaultIssue.setIsFromExternalRuleEngine(next.getIsFromExternalRuleEngine());
defaultIssue.setCreationDate(new Date(next.getCreationDate()));
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java
index bcea933ce76..7779b704c23 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java
@@ -132,6 +132,7 @@ public class PersistIssuesStepTest extends BaseStepTest {
.setProjectKey(project.getKey())
.setSeverity(BLOCKER)
.setStatus(STATUS_OPEN)
+ .setTags(singletonList("test"))
.setNew(false)
.setCopied(true)
.setType(RuleType.BUG)
@@ -164,6 +165,7 @@ public class PersistIssuesStepTest extends BaseStepTest {
assertThat(result.getSeverity()).isEqualTo(BLOCKER);
assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
+ assertThat(result.getTags()).containsExactlyInAnyOrder("test");
List<IssueChangeDto> changes = dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList("ISSUE"));
assertThat(changes).extracting(IssueChangeDto::getChangeType).containsExactly(IssueChangeDto.TYPE_COMMENT, IssueChangeDto.TYPE_FIELD_CHANGE);
@@ -172,6 +174,50 @@ public class PersistIssuesStepTest extends BaseStepTest {
}
@Test
+ public void insert_copied_issue_with_minimal_info() {
+ RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
+ db.rules().insert(rule);
+ OrganizationDto organizationDto = db.organizations().insert();
+ ComponentDto project = db.components().insertPrivateProject(organizationDto);
+ ComponentDto file = db.components().insertComponent(newFileDto(project, null));
+ when(system2.now()).thenReturn(NOW);
+
+ protoIssueCache.newAppender().append(new DefaultIssue()
+ .setKey("ISSUE")
+ .setType(RuleType.CODE_SMELL)
+ .setRuleKey(rule.getKey())
+ .setComponentUuid(file.uuid())
+ .setComponentKey(file.getKey())
+ .setProjectUuid(project.uuid())
+ .setProjectKey(project.getKey())
+ .setSeverity(BLOCKER)
+ .setStatus(STATUS_OPEN)
+ .setNew(false)
+ .setCopied(true)
+ .setType(RuleType.BUG)
+ .setCreationDate(new Date(NOW))
+ .setSelectedAt(NOW))
+ .close();
+
+ TestComputationStepContext context = new TestComputationStepContext();
+ underTest.execute(context);
+
+ IssueDto result = dbClient.issueDao().selectOrFailByKey(session, "ISSUE");
+ assertThat(result.getKey()).isEqualTo("ISSUE");
+ assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
+ assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
+ assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
+ assertThat(result.getSeverity()).isEqualTo(BLOCKER);
+ assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
+ assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
+ assertThat(result.getTags()).isEmpty();
+
+ assertThat(dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList("ISSUE"))).isEmpty();
+ assertThat(context.getStatistics().getAll()).contains(
+ entry("inserts", "1"), entry("updates", "0"), entry("merged", "0"));
+ }
+
+ @Test
public void insert_merged_issue() {
RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
db.rules().insert(rule);