]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5056 When creating a custom rule, copy debt definitions from parent
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 3 Apr 2014 07:08:52 +0000 (09:08 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 3 Apr 2014 08:44:32 +0000 (10:44 +0200)
sonar-server/src/main/java/org/sonar/server/rule/RuleOperations.java
sonar-server/src/test/java/org/sonar/server/rule/RuleOperationsTest.java

index afd53b9be2455ee10e98d88ebd646e73a0bb120c..5708ef4a757cdc574e02dea56b4ffecc04c349bd 100644 (file)
@@ -145,6 +145,10 @@ public class RuleOperations implements ServerComponent {
         .setCardinality(Cardinality.SINGLE)
         .setStatus(Rule.STATUS_READY)
         .setLanguage(templateRule.getLanguage())
+        .setDefaultSubCharacteristicId(templateRule.getDefaultSubCharacteristicId())
+        .setDefaultRemediationFunction(templateRule.getDefaultRemediationFunction())
+        .setDefaultRemediationCoefficient(templateRule.getDefaultRemediationCoefficient())
+        .setDefaultRemediationOffset(templateRule.getDefaultRemediationOffset())
         .setCreatedAt(new Date(system.now()))
         .setUpdatedAt(new Date(system.now()));
       ruleDao.insert(rule, session);
@@ -272,12 +276,14 @@ public class RuleOperations implements ServerComponent {
         }
 
         // New sub characteristic is not equals to existing one -> update it
+        // TODO check characteristic is not equals to default one, if so do nothing
         if (!subCharacteristic.getId().equals(ruleDto.getSubCharacteristicId())) {
           ruleDto.setSubCharacteristicId(subCharacteristic.getId());
           updated = true;
         }
 
         // New remediation function is not equals to existing one -> update it
+        // TODO check remediaiton function is not equals to default one, if so do nothing
         if (!isSameRemediationFunction(ruleChange.debtRemediationFunction(), ruleChange.debtRemediationCoefficient(), ruleChange.debtRemediationOffset(), ruleDto)) {
           DefaultDebtRemediationFunction debtRemediationFunction = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.valueOf(ruleChange.debtRemediationFunction()),
             ruleChange.debtRemediationCoefficient(), ruleChange.debtRemediationOffset());
index 5ccf3b58082e26fef13b84bf76f1d2afe69e443f..85b660c989ec49fc450baaeb8b18c8f0a69ff5b2 100644 (file)
@@ -216,7 +216,8 @@ public class RuleOperationsTest {
 
   @Test
   public void create_custom_rule() throws Exception {
-    RuleDto templateRule = new RuleDto().setId(10).setRepositoryKey("squid").setRuleKey("AvoidCycle").setConfigKey("Xpath");
+    RuleDto templateRule = new RuleDto().setId(10).setRepositoryKey("squid").setRuleKey("AvoidCycle").setConfigKey("Xpath")
+      .setDefaultSubCharacteristicId(20).setDefaultRemediationFunction("LINEAR_OFFSET").setDefaultRemediationCoefficient("2h").setDefaultRemediationOffset("15min");
     when(ruleDao.selectParametersByRuleId(eq(10), eq(session))).thenReturn(newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10")));
     when(ruleDao.selectTagsByRuleIds(eq(10), eq(session))).thenReturn(newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM)));
 
@@ -235,6 +236,10 @@ public class RuleOperationsTest {
     assertThat(ruleArgument.getValue().getRuleKey()).startsWith("AvoidCycle");
     assertThat(ruleArgument.getValue().getStatus()).isEqualTo("READY");
     assertThat(ruleArgument.getValue().getCardinality()).isEqualTo(Cardinality.SINGLE);
+    assertThat(ruleArgument.getValue().getDefaultSubCharacteristicId()).isEqualTo(20);
+    assertThat(ruleArgument.getValue().getDefaultRemediationFunction()).isEqualTo("LINEAR_OFFSET");
+    assertThat(ruleArgument.getValue().getDefaultRemediationCoefficient()).isEqualTo("2h");
+    assertThat(ruleArgument.getValue().getDefaultRemediationOffset()).isEqualTo("15min");
 
     ArgumentCaptor<RuleParamDto> ruleParamArgument = ArgumentCaptor.forClass(RuleParamDto.class);
     verify(ruleDao).insert(ruleParamArgument.capture(), eq(session));