]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6238 Updating only the name of a rule is not taking in account when synchronizi... 129/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 3 Mar 2015 12:06:50 +0000 (13:06 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 3 Mar 2015 12:06:50 +0000 (13:06 +0100)
server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java

index e2ea5e4ff9812c0e855c58a7966958306840b71c..674e9cade109469341443e78cfc1d5956623db85 100644 (file)
@@ -51,12 +51,8 @@ import org.sonar.server.startup.RegisterDebtModel;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+
+import java.util.*;
 
 import static com.google.common.collect.Lists.newArrayList;
 
@@ -228,7 +224,9 @@ public class RegisterRules implements Startable {
       dto.setName(def.name());
       changed = true;
     }
-    changed = mergeDescription(def, dto);
+    if (mergeDescription(def, dto)) {
+      changed= true;
+    }
     if (!dto.getSystemTags().containsAll(def.tags())) {
       dto.setSystemTags(def.tags());
       changed = true;
index 292b0e3effb13b2affb43f38b5b05ae0ad4ca4cb..2bc554247f7ef43a952a5358e1f05a2d7b07e8e4 100644 (file)
@@ -252,6 +252,56 @@ public class RegisterRulesMediumTest {
     assertThat(rule.effortToFixDescription()).isEqualTo("Effort2");
   }
 
+  @Test
+  public void update_only_rule_name() {
+    register(new Rules() {
+      @Override
+      public void init(RulesDefinition.NewRepository repository) {
+        repository.createRule("x1")
+          .setName("Name1")
+          .setHtmlDescription("Desc1");
+      }
+    });
+
+    register(new Rules() {
+      @Override
+      public void init(RulesDefinition.NewRepository repository) {
+        repository.createRule(RuleTesting.XOO_X1.rule())
+          .setName("Name2")
+          .setHtmlDescription("Desc1");
+      }
+    });
+
+    Rule rule = ruleIndex.getByKey(RuleTesting.XOO_X1);
+    assertThat(rule.name()).isEqualTo("Name2");
+    assertThat(rule.htmlDescription()).isEqualTo("Desc1");
+  }
+
+  @Test
+  public void update_only_rule_description() {
+    register(new Rules() {
+      @Override
+      public void init(RulesDefinition.NewRepository repository) {
+        repository.createRule("x1")
+          .setName("Name1")
+          .setHtmlDescription("Desc1");
+      }
+    });
+
+    register(new Rules() {
+      @Override
+      public void init(RulesDefinition.NewRepository repository) {
+        repository.createRule(RuleTesting.XOO_X1.rule())
+          .setName("Name1")
+          .setHtmlDescription("Desc2");
+      }
+    });
+
+    Rule rule = ruleIndex.getByKey(RuleTesting.XOO_X1);
+    assertThat(rule.name()).isEqualTo("Name1");
+    assertThat(rule.htmlDescription()).isEqualTo("Desc2");
+  }
+
   @Test
   public void do_not_update_rules_if_no_changes() throws Exception {
     Rules rules = new Rules() {
index 930515c1de7d0f4d37074d401c2b96e618f20977..7c1abbfedc77bf02def3643aa839549662ed562f 100644 (file)
@@ -218,6 +218,8 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
 
     RegisterRules task = new RegisterRules(loader, ruleActivator, dbClient, languages);
     task.start();
+    // Execute a commit to refresh session state as the task is using its own session
+    dbSession.commit();
   }
 
   private RuleParamDto getParam(List<RuleParamDto> params, String key) {