aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-06-27 23:59:18 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-06-27 23:59:18 +0200
commite8c8a5436ce4839305a06804354b135c2d9b9ffc (patch)
treeb482566ffb832e4ecade0bcb88709acff354b503
parenta0a6f86dd90abe06ce847eb095ad91bd4612fb04 (diff)
downloadsonarqube-e8c8a5436ce4839305a06804354b135c2d9b9ffc.tar.gz
sonarqube-e8c8a5436ce4839305a06804354b135c2d9b9ffc.zip
SONAR-5007 - Fixed user-tag deletion when becomes systemTag
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java9
2 files changed, 9 insertions, 4 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
index 351a30f4766..8c0a2fc6181 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
@@ -23,6 +23,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.picocontainer.Startable;
@@ -340,7 +341,8 @@ public class RegisterRules implements Startable {
if (RuleStatus.REMOVED == ruleDef.status()) {
dto.setSystemTags(Collections.<String>emptySet());
changed = true;
- } else if (!dto.getSystemTags().containsAll(ruleDef.tags())) {
+ } else if (!dto.getSystemTags().containsAll(ruleDef.tags())
+ || !Sets.intersection(dto.getTags(), ruleDef.tags()).isEmpty()) {
dto.setSystemTags(ruleDef.tags());
// remove end-user tags that are now declared as system
RuleTagHelper.applyTags(dto, ImmutableSet.copyOf(dto.getTags()));
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
index 404e78f8e7d..416606b49cd 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
@@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableMap;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
-import org.junit.Ignore;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
@@ -271,7 +270,6 @@ public class RegisterRulesMediumTest {
}
@Test
- @Ignore("To be fixed")
public void remove_end_user_tags_that_are_declared_as_system() {
verifyRulesInDb();
@@ -297,9 +295,14 @@ public class RegisterRulesMediumTest {
dbSession.clearCache();
// User tag should become a system tag
+ RuleDto ruleDtoReloaded = db.ruleDao().getByKey(dbSession, RuleTesting.XOO_X1);
+ assertThat(ruleDtoReloaded.getSystemTags()).contains("tag1", "tag2", "user-tag");
+ assertThat(ruleDtoReloaded.getTags()).isEmpty();
+
+ // User tag should become a system tag
Rule ruleReloaded = index.getByKey(RuleTesting.XOO_X1);
assertThat(ruleReloaded.systemTags()).contains("tag1", "tag2", "user-tag");
- assertThat(ruleUpdated.tags()).isEmpty();
+ assertThat(ruleReloaded.tags()).isEmpty();
}
@Test