]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 - Fixed user-tag deletion when becomes systemTag
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 27 Jun 2014 21:59:18 +0000 (23:59 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 27 Jun 2014 21:59:18 +0000 (23:59 +0200)
sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java

index 351a30f4766d791bfbab11864bd7e6df5109fada..8c0a2fc6181904aca82435ca3fc94e627b5018a7 100644 (file)
@@ -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()));
index 404e78f8e7dfdf8371d92e2f4c8b4e5e46e0479e..416606b49cdd60da8b1e0bb70d98605456720ee7 100644 (file)
@@ -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();
 
@@ -296,10 +294,15 @@ public class RegisterRulesMediumTest {
     tester.get(Platform.class).executeStartupTasks();
     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