diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-03-20 18:57:40 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-03-20 18:57:40 +0100 |
commit | d93268cebc05e32cf5fee908538350d44859962b (patch) | |
tree | 93856a6dbcfcf0724a1a7dc3fb61650f1bb9e6aa /sonar-batch | |
parent | dd1478fd1c40ceca4382eda011c3f093ba75dfe5 (diff) | |
download | sonarqube-d93268cebc05e32cf5fee908538350d44859962b.tar.gz sonarqube-d93268cebc05e32cf5fee908538350d44859962b.zip |
SONAR-5056 Fix issue when removing characteristic and rules linked with default characteristic linked on it was updated
Diffstat (limited to 'sonar-batch')
3 files changed, 22 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java index 75afe603f4f..701a5b9f81e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java @@ -81,7 +81,7 @@ public class RulesProvider extends ProviderAdapter { if (ruleDto.hasCharacteristic()) { newRule.setDebtCharacteristic(effectiveCharacteristic(ruleDto, ruleKey, debtModel).key()); - newRule.setDebtRemediationFunction(effectiveFunction(ruleDto, ruleKey, newRule, durations)); + newRule.setDebtRemediationFunction(effectiveFunction(ruleDto, ruleKey, durations)); } for (RuleParamDto ruleParamDto : paramDtosByRuleId.get(ruleDto.getId())) { @@ -103,7 +103,7 @@ public class RulesProvider extends ProviderAdapter { return characteristic; } - private DebtRemediationFunction effectiveFunction(RuleDto ruleDto, RuleKey ruleKey, NewRule newRule, Durations durations) { + private DebtRemediationFunction effectiveFunction(RuleDto ruleDto, RuleKey ruleKey, Durations durations) { String function = ruleDto.getRemediationFunction(); String defaultFunction = ruleDto.getDefaultRemediationFunction(); if (function != null) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java index d87e6b3189b..08106710bfe 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java @@ -174,6 +174,17 @@ public class RulesProviderTest extends AbstractDaoTestCase { } @Test + public void build_rules_with_default_characteristic_and_disable_characteristic() throws Exception { + setupData("build_rules_with_default_characteristic_and_disable_characteristic"); + + Rules rules = provider.provide(ruleDao, debtModel, durations); + + Rule rule = rules.find(RuleKey.of("checkstyle", "AvoidNull")); + assertThat(rule.debtCharacteristic()).isNull(); + assertThat(rule.debtRemediationFunction()).isNull(); + } + + @Test public void fail_if_characteristic_not_found() throws Exception { setupData("fail_if_characteristic_not_found"); diff --git a/sonar-batch/src/test/resources/org/sonar/batch/rule/RulesProviderTest/build_rules_with_default_characteristic_and_disable_characteristic.xml b/sonar-batch/src/test/resources/org/sonar/batch/rule/RulesProviderTest/build_rules_with_default_characteristic_and_disable_characteristic.xml new file mode 100644 index 00000000000..695d1dfcb4e --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/rule/RulesProviderTest/build_rules_with_default_characteristic_and_disable_characteristic.xml @@ -0,0 +1,9 @@ +<dataset> + + <rules id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle" name="Avoid Null" description="Should avoid NULL" status="READY" priority="1" + characteristic_id="-1" default_characteristic_id="103" + remediation_function="[null]" default_remediation_function="LINEAR" + remediation_factor="[null]" default_remediation_factor="2h" + remediation_offset="[null]" default_remediation_offset="[null]"/> + +</dataset> |