ruleRow.setCoefficient(convertDuration(enabledRequirement.getCoefficientValue(), enabledRequirement.getCoefficientUnit()));
ruleRow.setOffset(convertDuration(enabledRequirement.getOffsetValue(), enabledRequirement.getOffsetUnit()));
+ // Constant/issue with coefficient is replaced by Constant/issue with offset (with no coefficient)
+ if (DebtRemediationFunction.Type.CONSTANT_ISSUE.name().equals(ruleRow.getFunction())
+ && ruleRow.getCoefficient() != null) {
+ ruleRow.setOffset(ruleRow.getCoefficient());
+ ruleRow.setCoefficient(null);
+ }
+
// If the coefficient of a linear or linear with offset function is null, it should be replaced by 0
if ((DebtRemediationFunction.Type.LINEAR.name().equals(ruleRow.getFunction()) ||
DebtRemediationFunction.Type.LINEAR_OFFSET.name().equals(ruleRow.getFunction()))
verify(ruleRegistry).reindex();
}
+ /**
+ * SONAR-5335
+ */
+ @Test
+ public void convert_constant_issue_with_coeff_to_constant_issue_with_offset() throws Exception {
+ setupData("convert_constant_issue_with_coeff_to_constant_issue_with_offset_requirements");
+ db.prepareDbUnit(getClass(), "convert_constant_issue_with_coeff_to_constant_issue_with_offset.xml");
+
+ when(status.isUpgraded()).thenReturn(true);
+ when(status.getInitialDbVersion()).thenReturn(498);
+
+ service.start();
+
+ db.assertDbUnit(getClass(), "convert_constant_issue_with_coeff_to_constant_issue_with_offset_result.xml", "rules");
+ }
+
@Test
public void convert_duration() throws Exception {
assertThat(CopyRequirementsFromCharacteristicsToRules.convertDuration(1.0, "h")).isEqualTo("1h");
--- /dev/null
+<dataset>
+
+ <!-- Constant/issue with coefficient -> Update rule to Constant/issue with offset -->
+ <rules id="1" plugin_rule_key="RightCurlyBraceStartLineCheck" plugin_name="squid" name="RightCurlyBraceStartLineCheck" description="Right curly braces should be located at the beginning of lines of code" status="READY"
+ characteristic_id="[null]" default_characteristic_id="10"
+ remediation_function="[null]" default_remediation_function="LINEAR"
+ remediation_coeff="[null]" default_remediation_coeff="5d"
+ remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"/>
+
+ <!-- Constant/issue with coefficient and offset -> Update rule to Constant/issue with only offset -->
+ <rules id="2" plugin_rule_key="HiddenFieldCheck" plugin_name="squid" name="HiddenFieldCheck" description="HiddenFieldCheck" status="READY"
+ characteristic_id="[null]" default_characteristic_id="10"
+ remediation_function="[null]" default_remediation_function="LINEAR"
+ remediation_coeff="[null]" default_remediation_coeff="5d"
+ remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"/>
+
+ <!-- Constant/issue with coefficient but having same value as default -> No update -->
+ <rules id="3" plugin_rule_key="ForLoopCounterChangedCheck" plugin_name="squid" name="ForLoopCounterChangedCheck" description="ForLoopCounterChangedCheck" status="READY"
+ characteristic_id="[null]" default_characteristic_id="10"
+ remediation_function="[null]" default_remediation_function="CONSTANT_ISSUE"
+ remediation_coeff="[null]" default_remediation_coeff="[null]"
+ remediation_offset="[null]" default_remediation_offset="5min" updated_at="2014-02-19"/>
+
+</dataset>
--- /dev/null
+
+<dataset>
+
+ <!-- Requirements of rule 1 -->
+ <characteristics id="1" parent_id="10" rule_id="1"
+ function_key="constant_issue" factor_value="20.0" factor_unit="mn" offset_value="0.0" offset_unit="h" enabled="[true]"
+ created_at="2013-11-20" updated_at="[null]"/>
+
+ <!-- Requirements of rule 2 -->
+ <characteristics id="2" parent_id="10" rule_id="2"
+ function_key="constant_issue" factor_value="30.0" factor_unit="mn" offset_value="20.0" offset_unit="h" enabled="[true]"
+ created_at="2013-11-20" updated_at="[null]"/>
+
+ <!-- Requirements of rule 3 -->
+ <characteristics id="3" parent_id="10" rule_id="3"
+ function_key="constant_issue" factor_value="5.0" factor_unit="mn" offset_value="0.0" offset_unit="h" enabled="[true]"
+ created_at="2013-11-20" updated_at="[null]"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- Constant/issue with coefficient -> Update rule to Constant/issue with offset -->
+ <rules id="1" plugin_rule_key="RightCurlyBraceStartLineCheck" plugin_name="squid" name="RightCurlyBraceStartLineCheck" description="Right curly braces should be located at the beginning of lines of code" status="READY"
+ characteristic_id="10" default_characteristic_id="10"
+ remediation_function="CONSTANT_ISSUE" default_remediation_function="LINEAR"
+ remediation_coeff="[null]" default_remediation_coeff="5d"
+ remediation_offset="20min" default_remediation_offset="[null]" updated_at="2014-03-13 19:10:03.0"/>
+
+ <!-- Constant/issue with coefficient and offset -> Update rule to Constant/issue with only offset -->
+ <rules id="2" plugin_rule_key="HiddenFieldCheck" plugin_name="squid" name="HiddenFieldCheck" description="HiddenFieldCheck" status="READY"
+ characteristic_id="10" default_characteristic_id="10"
+ remediation_function="CONSTANT_ISSUE" default_remediation_function="LINEAR"
+ remediation_coeff="[null]" default_remediation_coeff="5d"
+ remediation_offset="30min" default_remediation_offset="[null]" updated_at="2014-03-13 19:10:03.0"/>
+
+ <!-- Constant/issue with coefficient but having same value as default -> No update -->
+ <rules id="3" plugin_rule_key="ForLoopCounterChangedCheck" plugin_name="squid" name="ForLoopCounterChangedCheck" description="ForLoopCounterChangedCheck" status="READY"
+ characteristic_id="[null]" default_characteristic_id="10"
+ remediation_function="[null]" default_remediation_function="CONSTANT_ISSUE"
+ remediation_coeff="[null]" default_remediation_coeff="[null]"
+ remediation_offset="[null]" default_remediation_offset="5min" updated_at="2014-02-19"/>
+
+</dataset>
remediation_coeff="[null]" default_remediation_coeff="5d"
remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"/>
- <!-- Rule linked to one enable requirement on Linear function (with a coeeficient of 0min -> to be replaced by null), with different value of debt -> Update rule -->
+ <!-- Rule linked to one enable requirement on Linear function (with a coefficient of 0min -> to be replaced by null), with different value of debt -> Update rule -->
<rules id="7" plugin_rule_key="ForLoopCounterChangedCheck" plugin_name="squid" name="ForLoopCounterChangedCheck" description="ForLoopCounterChangedCheck" status="READY"
characteristic_id="[null]" default_characteristic_id="20"
remediation_function="[null]" default_remediation_function="LINEAR"
characteristic_id="[null]" default_characteristic_id="20"
remediation_function="[null]" default_remediation_function="LINEAR"
remediation_coeff="[null]" default_remediation_coeff="5d"
- remediation_offset="[null]" default_remediation_offset="[null" updated_at="2014-02-19"/>
+ remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"/>
<!-- Rule linked to one enable requirement on Linear function (with a coefficient of 0d -> should keep 0d), with different value of debt -> Update rule -->
<rules id="9" plugin_rule_key="SwitchLastCaseIsDefaultCheck" plugin_name="squid" name="SwitchLastCaseIsDefaultCheck" description="SwitchLastCaseIsDefaultCheck" status="READY"
remediation_coeff="[null]" default_remediation_coeff="5d"
remediation_offset="15min" default_remediation_offset="[null]" updated_at="2014-03-13 19:10:03.0"/>
- <!-- Rule linked to one enable requirement on Linear function (with a coeeficient of 0min -> to be replaced by null), with different value of debt -> Update rule -->
+ <!-- Rule linked to one enable requirement on Linear function (with a coefficient of 0min -> to be replaced by null), with different value of debt -> Update rule -->
<rules id="7" plugin_rule_key="ForLoopCounterChangedCheck" plugin_name="squid" name="ForLoopCounterChangedCheck" description="ForLoopCounterChangedCheck" status="READY"
characteristic_id="10" default_characteristic_id="20"
remediation_function="LINEAR" default_remediation_function="LINEAR"
characteristic_id="10" default_characteristic_id="20"
remediation_function="LINEAR_OFFSET" default_remediation_function="LINEAR"
remediation_coeff="5d" default_remediation_coeff="5d"
- remediation_offset="0h" default_remediation_offset="[null" updated_at="2014-03-13 19:10:03.0"/>
+ remediation_offset="0h" default_remediation_offset="[null]" updated_at="2014-03-13 19:10:03.0"/>
<!-- Rule linked to one enable requirement on Linear function (with a coefficient of 0d -> should keep 0d), with different value of debt -> Update rule -->
<rules id="9" plugin_rule_key="SwitchLastCaseIsDefaultCheck" plugin_name="squid" name="SwitchLastCaseIsDefaultCheck" description="SwitchLastCaseIsDefaultCheck" status="READY"