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;
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()));
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;
}
@Test
- @Ignore("To be fixed")
public void remove_end_user_tags_that_are_declared_as_system() {
verifyRulesInDb();
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