]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 fix update of param activation when no default value
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 7 Jul 2014 08:43:12 +0000 (10:43 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 7 Jul 2014 08:43:12 +0000 (10:43 +0200)
sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java

index 81c470690bad126d27df3f5dd486e780fabab640..e779be0091145f6a1fe54acbfd81a15b208868c0 100644 (file)
@@ -214,7 +214,10 @@ class RuleActivatorContext {
     }
     for (Map.Entry<String, String> changeParam : change.getParameters().entrySet()) {
       ActiveRuleParamDto param = activeRuleParams.get(changeParam.getKey());
-      if (param != null && !StringUtils.equals(changeParam.getValue(), param.getValue())) {
+      if (changeParam.getValue()==null && param != null && param.getValue()!=null) {
+        return false;
+      }
+      if (changeParam.getValue()!=null && (param == null || !StringUtils.equals(changeParam.getValue(), param.getValue()))) {
         return false;
       }
     }
index 3e1f5ae6c507c9ad85ef359ddc0f70a41ea3fee4..5d55a161de7ed817ab464dee4af5339564ecf333 100644 (file)
@@ -112,12 +112,14 @@ public class RuleActivatorMediumTest {
     RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
     activation.setSeverity(Severity.BLOCKER);
     activation.setParameter("max", "7");
+    activation.setParameter("min", "3");
     List<ActiveRuleChange> changes = ruleActivator.activate(dbSession, activation, XOO_P1_KEY);
     dbSession.commit();
     dbSession.clearCache();
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.BLOCKER, null,
+      ImmutableMap.of("max", "7", "min", "3"));
     assertThat(changes).hasSize(1);
     assertThat(changes.get(0).getType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED);
   }
@@ -127,7 +129,8 @@ public class RuleActivatorMediumTest {
     activate(new RuleActivation(RuleTesting.XOO_X1), XOO_P1_KEY);
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MINOR, null, ImmutableMap.of("max", "10"));
+    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MINOR, null,
+      ImmutableMap.of("max", "10"));
   }
 
   @Test
@@ -160,21 +163,21 @@ public class RuleActivatorMediumTest {
   }
 
   @Test
-  @Ignore
   public void update_activation_with_parameter_without_default_value() throws Exception {
-    // initial activation
+    // initial activation -> param "max" has a default value
     RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
     activation.setSeverity(Severity.BLOCKER);
     activate(activation, XOO_P1_KEY);
+    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.BLOCKER, null,
+      ImmutableMap.of("max", "10"));
 
-    // update
+    // update param "min", which has no default value
     RuleActivation update = new RuleActivation(RuleTesting.XOO_X1);
-    // parameter min has no default value
-    update.setParameter("min", "42");
+    update.setParameter("min", "3");
     List<ActiveRuleChange> changes = activate(update, XOO_P1_KEY);
-
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.BLOCKER, null, ImmutableMap.of("min", "42"));
+    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.BLOCKER, null,
+      ImmutableMap.of("min", "3", "max", "10"));
     assertThat(changes).hasSize(1);
     assertThat(changes.get(0).getType()).isEqualTo(ActiveRuleChange.Type.UPDATED);
   }