aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-02-09 16:36:23 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-02-09 16:36:23 +0100
commit916f7021154eae9c7c88f0f219884d972573209c (patch)
tree521298ebafdd7db56d34ab908ea7f3b2822c10f0 /server/sonar-server
parent8f8e96192f36aa13496ebfe7bbaf333de8a92e35 (diff)
parent72f64c95fdef18ec950d341c1a9093f30087e1c1 (diff)
downloadsonarqube-916f7021154eae9c7c88f0f219884d972573209c.tar.gz
sonarqube-916f7021154eae9c7c88f0f219884d972573209c.zip
Merge branch 'branch-6.7'
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/CachingRuleFinder.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java34
4 files changed, 39 insertions, 2 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/CachingRuleFinder.java b/server/sonar-server/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
index bed8c761474..da5e850067e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
@@ -174,7 +174,8 @@ public class CachingRuleFinder implements RuleFinder {
.setRepositoryKey(ruleDefinition.getRepositoryKey())
.setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
.setStatus(ruleDefinition.getStatus().name())
- .setTags(ruleDefinition.getSystemTags().toArray(new String[ruleDefinition.getSystemTags().size()]))
+ .setSystemTags(ruleDefinition.getSystemTags().toArray(new String[ruleDefinition.getSystemTags().size()]))
+ .setTags(new String[0])
.setId(ruleDefinition.getId());
if (description != null && descriptionFormat != null) {
if (RuleDto.Format.HTML.equals(descriptionFormat)) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java b/server/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
index 3ebd0f28178..765bf9a158b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
@@ -145,6 +145,7 @@ public class DefaultRuleFinder implements RuleFinder {
.setRepositoryKey(rule.getRepositoryKey())
.setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
.setStatus(rule.getStatus().name())
+ .setSystemTags(rule.getSystemTags().toArray(new String[rule.getSystemTags().size()]))
.setTags(rule.getTags().toArray(new String[rule.getTags().size()]))
.setId(rule.getId());
if (description != null && descriptionFormat != null) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
index 7bc6af5db42..ee0287a318a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
@@ -408,7 +408,8 @@ public class CachingRuleFinderTest {
assertThat(rule.getUpdatedAt().getTime()).isEqualTo(ruleDefinition.getUpdatedAt());
assertThat(rule.getRepositoryKey()).isEqualTo(ruleDefinition.getRepositoryKey());
assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString());
- assertThat(rule.getTags()).isEqualTo(ruleDefinition.getSystemTags().stream().toArray(String[]::new));
+ assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().stream().toArray(String[]::new));
+ assertThat(rule.getTags()).isEmpty();
assertThat(rule.getId()).isEqualTo(ruleDefinition.getId());
assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDescription());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java
index 3727eea253e..a8e8f668d82 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.rule;
+import com.google.common.collect.ImmutableSet;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.rule.RuleStatus;
@@ -28,11 +29,14 @@ import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleDto.Scope;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
public class DefaultRuleFinderTest {
@@ -138,4 +142,34 @@ public class DefaultRuleFinderTest {
assertThat(underTest.findAll(RuleQuery.create())).extracting("id").containsOnly(rule1.getId(), rule3.getId(), rule4.getId());
}
+ @Test
+ public void findById_populates_system_tags_but_not_tags() {
+ RuleDefinitionDto ruleDefinition = dbTester.rules()
+ .insert(t -> t.setSystemTags(ImmutableSet.of(randomAlphanumeric(5), randomAlphanumeric(6))));
+ OrganizationDto organization = dbTester.organizations().insert();
+ dbTester.rules().insertRule(organization);
+
+ Rule rule = underTest.findById(ruleDefinition.getId());
+ assertThat(rule.getSystemTags())
+ .containsOnlyElementsOf(ruleDefinition.getSystemTags());
+ assertThat(rule.getTags()).isEmpty();
+ }
+
+ @Test
+ public void findByKey_populates_system_tags_but_not_tags() {
+ RuleDefinitionDto ruleDefinition = dbTester.rules()
+ .insert(t -> t.setSystemTags(ImmutableSet.of(randomAlphanumeric(5), randomAlphanumeric(6))));
+ OrganizationDto organization = dbTester.organizations().insert();
+ dbTester.rules().insertRule(organization);
+
+ Rule rule = underTest.findByKey(ruleDefinition.getKey());
+ assertThat(rule.getSystemTags())
+ .containsOnlyElementsOf(ruleDefinition.getSystemTags());
+ assertThat(rule.getTags()).isEmpty();
+
+ rule = underTest.findByKey(ruleDefinition.getRepositoryKey(), ruleDefinition.getRuleKey());
+ assertThat(rule.getSystemTags())
+ .containsOnlyElementsOf(ruleDefinition.getSystemTags());
+ assertThat(rule.getTags()).isEmpty();
+ }
}