From e8c8a5436ce4839305a06804354b135c2d9b9ffc Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Fri, 27 Jun 2014 23:59:18 +0200 Subject: [PATCH] SONAR-5007 - Fixed user-tag deletion when becomes systemTag --- .../main/java/org/sonar/server/rule/RegisterRules.java | 4 +++- .../org/sonar/server/rule/RegisterRulesMediumTest.java | 9 ++++++--- 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.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(); @@ -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 -- 2.39.5