]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7330 RuleCreator is now using RuleIndexer
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 22 Feb 2016 11:31:36 +0000 (12:31 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Feb 2016 12:26:54 +0000 (13:26 +0100)
server/sonar-server/src/main/java/org/sonar/server/rule/RuleCreator.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleCreatorMediumTest.java

index 11b28a75d1a17c58213021d4b3e107903fae1df3..a7adbd6af2e3f4b7b772e2f0399e7eb79d5f2b91 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.rule;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
 import java.util.List;
@@ -29,15 +30,16 @@ import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.server.rule.RuleParamType;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleDto.Format;
 import org.sonar.db.rule.RuleParamDto;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.Errors;
 import org.sonar.server.exceptions.Message;
 import org.sonar.server.rule.index.RuleDoc;
+import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.util.TypeValidations;
 
 import static com.google.common.collect.Lists.newArrayList;
@@ -45,11 +47,12 @@ import static com.google.common.collect.Lists.newArrayList;
 @ServerSide
 public class RuleCreator {
 
+  private final RuleIndexer ruleIndexer;
   private final DbClient dbClient;
-
   private final TypeValidations typeValidations;
 
-  public RuleCreator(DbClient dbClient, TypeValidations typeValidations) {
+  public RuleCreator(RuleIndexer ruleIndexer, DbClient dbClient, TypeValidations typeValidations) {
+    this.ruleIndexer = ruleIndexer;
     this.dbClient = dbClient;
     this.typeValidations = typeValidations;
   }
@@ -77,7 +80,7 @@ public class RuleCreator {
     if (templateKey == null) {
       throw new IllegalArgumentException("Rule template key should not be null");
     }
-    RuleDto templateRule = dbClient.deprecatedRuleDao().getByKey(dbSession, templateKey);
+    RuleDto templateRule = dbClient.ruleDao().selectOrFailByKey(dbSession, templateKey);
     if (!templateRule.isTemplate()) {
       throw new IllegalArgumentException("This rule is not a template rule: " + templateKey.toString());
     }
@@ -85,14 +88,15 @@ public class RuleCreator {
 
     RuleKey customRuleKey = RuleKey.of(templateRule.getRepositoryKey(), newRule.ruleKey());
 
-    RuleDto existingRule = loadRule(customRuleKey, dbSession);
-    if (existingRule != null) {
-      updateExistingRule(existingRule, newRule, dbSession);
+    Optional<RuleDto> existingRule = loadRule(customRuleKey, dbSession);
+    if (existingRule.isPresent()) {
+      updateExistingRule(existingRule.get(), newRule, dbSession);
     } else {
       createCustomRule(customRuleKey, newRule, templateRule, dbSession);
     }
 
     dbSession.commit();
+    ruleIndexer.setEnabled(true).index();
     return customRuleKey;
   }
 
@@ -100,14 +104,15 @@ public class RuleCreator {
     validateManualRule(newRule);
 
     RuleKey customRuleKey = RuleKey.of(RuleDoc.MANUAL_REPOSITORY, newRule.ruleKey());
-    RuleDto existingRule = loadRule(customRuleKey, dbSession);
-    if (existingRule != null) {
-      updateExistingRule(existingRule, newRule, dbSession);
+    Optional<RuleDto> existingRule = loadRule(customRuleKey, dbSession);
+    if (existingRule.isPresent()) {
+      updateExistingRule(existingRule.get(), newRule, dbSession);
     } else {
       createManualRule(customRuleKey, newRule, dbSession);
     }
 
     dbSession.commit();
+    ruleIndexer.setEnabled(true).index();
     return customRuleKey;
   }
 
@@ -128,7 +133,7 @@ public class RuleCreator {
       errors.add(Message.of("coding_rules.validation.missing_status"));
     }
 
-    for (RuleParamDto ruleParam : dbClient.deprecatedRuleDao().selectRuleParamsByRuleKey(dbSession, templateKey)) {
+    for (RuleParamDto ruleParam : dbClient.ruleDao().selectRuleParamsByRuleKey(dbSession, templateKey)) {
       try {
         validateParam(ruleParam, newRule.parameter(ruleParam.getName()));
       } catch (BadRequestException validationError) {
@@ -187,9 +192,8 @@ public class RuleCreator {
     }
   }
 
-  @CheckForNull
-  private RuleDto loadRule(RuleKey ruleKey, DbSession dbSession) {
-    return dbClient.deprecatedRuleDao().getNullableByKey(dbSession, ruleKey);
+  private Optional<RuleDto> loadRule(RuleKey ruleKey, DbSession dbSession) {
+    return dbClient.ruleDao().selectByKey(dbSession, ruleKey);
   }
 
   private RuleKey createCustomRule(RuleKey ruleKey, NewRule newRule, RuleDto templateRuleDto, DbSession dbSession) {
@@ -208,9 +212,9 @@ public class RuleCreator {
       .setEffortToFixDescription(templateRuleDto.getEffortToFixDescription())
       .setTags(templateRuleDto.getTags())
       .setSystemTags(templateRuleDto.getSystemTags());
-    dbClient.deprecatedRuleDao().insert(dbSession, ruleDto);
+    dbClient.ruleDao().insert(dbSession, ruleDto);
 
-    for (RuleParamDto templateRuleParamDto : dbClient.deprecatedRuleDao().selectRuleParamsByRuleKey(dbSession, templateRuleDto.getKey())) {
+    for (RuleParamDto templateRuleParamDto : dbClient.ruleDao().selectRuleParamsByRuleKey(dbSession, templateRuleDto.getKey())) {
       String customRuleParamValue = Strings.emptyToNull(newRule.parameter(templateRuleParamDto.getName()));
       createCustomRuleParams(customRuleParamValue, ruleDto, templateRuleParamDto, dbSession);
     }
@@ -223,7 +227,7 @@ public class RuleCreator {
       .setType(templateRuleParam.getType())
       .setDescription(templateRuleParam.getDescription())
       .setDefaultValue(paramValue);
-    dbClient.deprecatedRuleDao().insertRuleParam(dbSession, ruleDto, ruleParamDto);
+    dbClient.ruleDao().insertRuleParam(dbSession, ruleDto, ruleParamDto);
   }
 
   private RuleKey createManualRule(RuleKey ruleKey, NewRule newRule, DbSession dbSession) {
@@ -233,7 +237,7 @@ public class RuleCreator {
       .setDescriptionFormat(Format.MARKDOWN)
       .setSeverity(newRule.severity())
       .setStatus(RuleStatus.READY);
-    dbClient.deprecatedRuleDao().insert(dbSession, ruleDto);
+    dbClient.ruleDao().insert(dbSession, ruleDto);
     return ruleKey;
   }
 
@@ -243,7 +247,7 @@ public class RuleCreator {
         throw new ReactivationException(String.format("A removed rule with the key '%s' already exists", ruleDto.getKey().rule()), ruleDto.getKey());
       } else {
         ruleDto.setStatus(RuleStatus.READY);
-        dbClient.deprecatedRuleDao().update(dbSession, ruleDto);
+        dbClient.ruleDao().update(dbSession, ruleDto);
       }
     } else {
       throw new IllegalArgumentException(String.format("A rule with the key '%s' already exists", ruleDto.getKey().rule()));
index 091c3e74d04d7f237e6972334a1433ab223e248e..38c7c984cd73089a412f3f119c24031e890082a9 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.rule;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Sets;
+import java.util.List;
 import org.assertj.core.api.Fail;
 import org.junit.After;
 import org.junit.Before;
@@ -30,24 +31,24 @@ import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.server.debt.DebtRemediationFunction;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
+import org.sonar.db.rule.RuleDao;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleDto.Format;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.db.DbClient;
+import org.sonar.server.es.SearchOptions;
 import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.rule.db.RuleDao;
-import org.sonar.server.rule.index.RuleIndex;
-import org.sonar.server.search.BaseIndex;
+import org.sonar.server.rule.index.RuleIndex2;
+import org.sonar.server.rule.index.RuleQuery;
 import org.sonar.server.tester.ServerTester;
-
-import java.util.List;
 import org.sonar.server.tester.UserSessionRule;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
 
+// TODO replace ServerTester by EsTester / DbTester
 public class RuleCreatorMediumTest {
 
   @ClassRule
@@ -59,7 +60,7 @@ public class RuleCreatorMediumTest {
   DbClient db = tester.get(DbClient.class);
   RuleDao dao = tester.get(RuleDao.class);
   RuleCreator creator = tester.get(RuleCreator.class);
-  BaseIndex<Rule, RuleDto, RuleKey> ruleIndex = tester.get(RuleIndex.class);
+  RuleIndex2 ruleIndex = tester.get(RuleIndex2.class);
 
   @Before
   public void before() {
@@ -88,7 +89,7 @@ public class RuleCreatorMediumTest {
 
     dbSession.clearCache();
 
-    RuleDto rule = db.deprecatedRuleDao().getNullableByKey(dbSession, customRuleKey);
+    RuleDto rule = db.ruleDao().selectOrFailByKey(dbSession, customRuleKey);
     assertThat(rule).isNotNull();
     assertThat(rule.getKey()).isEqualTo(RuleKey.of("java", "CUSTOM_RULE"));
     assertThat(rule.getTemplateId()).isEqualTo(templateRule.getId());
@@ -105,7 +106,7 @@ public class RuleCreatorMediumTest {
     assertThat(rule.getTags()).containsOnly("usertag1", "usertag2");
     assertThat(rule.getSystemTags()).containsOnly("tag1", "tag4");
 
-    List<RuleParamDto> params = db.deprecatedRuleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
+    List<RuleParamDto> params = db.ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
     assertThat(params).hasSize(1);
 
     RuleParamDto param = params.get(0);
@@ -115,6 +116,8 @@ public class RuleCreatorMediumTest {
     assertThat(param.getType()).isEqualTo("STRING");
     // From user
     assertThat(param.getDefaultValue()).isEqualTo("a.*");
+
+    assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(customRuleKey, templateRule.getKey());
   }
 
   @Test
@@ -132,7 +135,7 @@ public class RuleCreatorMediumTest {
     RuleKey customRuleKey = creator.create(newRule);
     dbSession.clearCache();
 
-    List<RuleParamDto> params = db.deprecatedRuleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
+    List<RuleParamDto> params = db.ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
     assertThat(params).hasSize(1);
 
     RuleParamDto param = params.get(0);
@@ -156,7 +159,7 @@ public class RuleCreatorMediumTest {
     RuleKey customRuleKey = creator.create(newRule);
     dbSession.clearCache();
 
-    List<RuleParamDto> params = db.deprecatedRuleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
+    List<RuleParamDto> params = db.ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
     assertThat(params).hasSize(1);
 
     RuleParamDto param = params.get(0);
@@ -181,7 +184,7 @@ public class RuleCreatorMediumTest {
     RuleKey customRuleKey = creator.create(newRule);
     dbSession.clearCache();
 
-    List<RuleParamDto> params = db.deprecatedRuleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
+    List<RuleParamDto> params = db.ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
     assertThat(params).hasSize(1);
 
     RuleParamDto param = params.get(0);
@@ -235,7 +238,6 @@ public class RuleCreatorMediumTest {
     dbSession.clearCache();
   }
 
-
   @Test
   public void reactivate_custom_rule_if_already_exists_in_removed_status() {
     String key = "CUSTOM_RULE";
@@ -244,13 +246,14 @@ public class RuleCreatorMediumTest {
     RuleDto templateRule = createTemplateRule();
 
     // insert a removed rule
-    RuleDto rule = dao.insert(dbSession, RuleTesting.newCustomRule(templateRule)
+    RuleDto rule = RuleTesting.newCustomRule(templateRule)
       .setRuleKey(key)
       .setStatus(RuleStatus.REMOVED)
       .setName("Old name")
       .setDescription("Old description")
       .setDescriptionFormat(Format.MARKDOWN)
-      .setSeverity(Severity.INFO));
+      .setSeverity(Severity.INFO);
+    dao.insert(dbSession, rule);
     dao.insertRuleParam(dbSession, rule, dao.selectRuleParamsByRuleKey(dbSession, templateRule.getKey()).get(0).setDefaultValue("a.*"));
     dbSession.commit();
     dbSession.clearCache();
@@ -266,18 +269,18 @@ public class RuleCreatorMediumTest {
 
     dbSession.clearCache();
 
-    Rule result = ruleIndex.getByKey(customRuleKey);
-    assertThat(result.key()).isEqualTo(RuleKey.of("java", key));
-    assertThat(result.status()).isEqualTo(RuleStatus.READY);
+    RuleDto result = db.ruleDao().selectOrFailByKey(dbSession, customRuleKey);
+    assertThat(result.getKey()).isEqualTo(RuleKey.of("java", key));
+    assertThat(result.getStatus()).isEqualTo(RuleStatus.READY);
 
     // These values should be the same than before
-    assertThat(result.name()).isEqualTo("Old name");
-    assertThat(result.markdownDescription()).isEqualTo("Old description");
-    assertThat(result.severity()).isEqualTo(Severity.INFO);
-    assertThat(result.param("regex").defaultValue()).isEqualTo("a.*");
+    assertThat(result.getName()).isEqualTo("Old name");
+    assertThat(result.getDescription()).isEqualTo("Old description");
+    assertThat(result.getSeverityString()).isEqualTo(Severity.INFO);
 
-    // Check that the id is the same
-    assertThat(db.deprecatedRuleDao().getByKey(dbSession, result.key()).getId()).isEqualTo(rule.getId());
+    List<RuleParamDto> params = db.ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
+    assertThat(params).hasSize(1);
+    assertThat(params.get(0).getDefaultValue()).isEqualTo("a.*");
   }
 
   @Test
@@ -288,12 +291,13 @@ public class RuleCreatorMediumTest {
     RuleDto templateRule = createTemplateRule();
 
     // insert a removed rule
-    RuleDto rule = dao.insert(dbSession, RuleTesting.newCustomRule(templateRule)
+    RuleDto rule = RuleTesting.newCustomRule(templateRule)
       .setRuleKey(key)
       .setStatus(RuleStatus.REMOVED)
       .setName("Old name")
       .setDescription("Old description")
-      .setSeverity(Severity.INFO));
+      .setSeverity(Severity.INFO);
+    dao.insert(dbSession, rule);
     dao.insertRuleParam(dbSession, rule, dao.selectRuleParamsByRuleKey(dbSession, templateRule.getKey()).get(0).setDefaultValue("a.*"));
     dbSession.commit();
     dbSession.clearCache();
@@ -465,8 +469,8 @@ public class RuleCreatorMediumTest {
   @Test
   public void fail_to_create_custom_rule_when_wrong_rule_template() {
     // insert rule
-    RuleDto rule = dao.insert(dbSession,
-      RuleTesting.newDto(RuleKey.of("java", "S001")).setIsTemplate(false));
+    RuleDto rule = RuleTesting.newDto(RuleKey.of("java", "S001")).setIsTemplate(false);
+    dao.insert(dbSession, rule);
     dbSession.commit();
 
     // Create custom rule with unknown template rule
@@ -494,19 +498,22 @@ public class RuleCreatorMediumTest {
 
     dbSession.clearCache();
 
-    Rule rule = ruleIndex.getByKey(ruleKey);
+    RuleDto rule = db.ruleDao().selectOrFailByKey(dbSession, ruleKey);
     assertThat(rule).isNotNull();
-    assertThat(rule.key()).isEqualTo(RuleKey.of("manual", "MANUAL_RULE"));
-    assertThat(rule.name()).isEqualTo("My manual");
-    assertThat(rule.markdownDescription()).isEqualTo("Some description");
-    assertThat(rule.severity()).isNull();
-    assertThat(rule.status()).isEqualTo(RuleStatus.READY);
-    assertThat(rule.language()).isNull();
-    assertThat(rule.internalKey()).isNull();
-    assertThat(rule.debtRemediationFunction()).isNull();
-    assertThat(rule.tags()).isEmpty();
-    assertThat(rule.systemTags()).isEmpty();
-    assertThat(rule.params()).isEmpty();
+    assertThat(rule.getKey()).isEqualTo(RuleKey.of("manual", "MANUAL_RULE"));
+    assertThat(rule.getName()).isEqualTo("My manual");
+    assertThat(rule.getDescription()).isEqualTo("Some description");
+    assertThat(rule.getSeverityString()).isNull();
+    assertThat(rule.getStatus()).isEqualTo(RuleStatus.READY);
+    assertThat(rule.getLanguage()).isNull();
+    assertThat(rule.getConfigKey()).isNull();
+    assertThat(rule.getDefaultRemediationOffset()).isNull();
+    assertThat(rule.getTags()).isEmpty();
+    assertThat(rule.getSystemTags()).isEmpty();
+
+    assertThat(db.ruleDao().selectRuleParamsByRuleKey(dbSession, ruleKey)).isEmpty();
+
+    assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(ruleKey);
   }
 
   @Test
@@ -519,19 +526,20 @@ public class RuleCreatorMediumTest {
 
     dbSession.clearCache();
 
-    Rule rule = ruleIndex.getByKey(ruleKey);
+    RuleDto rule = db.ruleDao().selectOrFailByKey(dbSession, ruleKey);
     assertThat(rule).isNotNull();
-    assertThat(rule.key()).isEqualTo(RuleKey.of("manual", "MANUAL_RULE"));
-    assertThat(rule.name()).isEqualTo("My manual");
-    assertThat(rule.markdownDescription()).isEqualTo("Some description");
-    assertThat(rule.severity()).isEqualTo(Severity.BLOCKER);
-    assertThat(rule.status()).isEqualTo(RuleStatus.READY);
-    assertThat(rule.language()).isNull();
-    assertThat(rule.internalKey()).isNull();
-    assertThat(rule.debtRemediationFunction()).isNull();
-    assertThat(rule.tags()).isEmpty();
-    assertThat(rule.systemTags()).isEmpty();
-    assertThat(rule.params()).isEmpty();
+    assertThat(rule.getKey()).isEqualTo(RuleKey.of("manual", "MANUAL_RULE"));
+    assertThat(rule.getName()).isEqualTo("My manual");
+    assertThat(rule.getDescription()).isEqualTo("Some description");
+    assertThat(rule.getSeverityString()).isEqualTo(Severity.BLOCKER);
+    assertThat(rule.getStatus()).isEqualTo(RuleStatus.READY);
+    assertThat(rule.getLanguage()).isNull();
+    assertThat(rule.getConfigKey()).isNull();
+    assertThat(rule.getDefaultRemediationFunction()).isNull();
+    assertThat(rule.getTags()).isEmpty();
+    assertThat(rule.getSystemTags()).isEmpty();
+
+    assertThat(db.ruleDao().selectRuleParamsByRuleKey(dbSession, ruleKey)).isEmpty();
   }
 
   @Test
@@ -539,11 +547,12 @@ public class RuleCreatorMediumTest {
     String key = "MANUAL_RULE";
 
     // insert a removed rule
-    RuleDto rule = dao.insert(dbSession, RuleTesting.newManualRule(key)
+    RuleDto rule = RuleTesting.newManualRule(key)
       .setStatus(RuleStatus.REMOVED)
       .setName("Old name")
       .setDescription("Old description")
-      .setSeverity(Severity.INFO));
+      .setSeverity(Severity.INFO);
+    dao.insert(dbSession, rule);
     dbSession.commit();
     dbSession.clearCache();
 
@@ -555,17 +564,14 @@ public class RuleCreatorMediumTest {
 
     dbSession.clearCache();
 
-    Rule result = ruleIndex.getByKey(ruleKey);
-    assertThat(result.key()).isEqualTo(RuleKey.of("manual", key));
-    assertThat(result.status()).isEqualTo(RuleStatus.READY);
+    RuleDto result = db.ruleDao().selectOrFailByKey(dbSession, ruleKey);
+    assertThat(result.getKey()).isEqualTo(RuleKey.of("manual", key));
+    assertThat(result.getStatus()).isEqualTo(RuleStatus.READY);
 
     // Name, description and severity should be the same than before
-    assertThat(result.name()).isEqualTo("Old name");
-    assertThat(result.markdownDescription()).isEqualTo("Old description");
-    assertThat(result.severity()).isEqualTo(Severity.INFO);
-
-    // Check that the id is the same
-    assertThat(db.deprecatedRuleDao().getByKey(dbSession, result.key()).getId()).isEqualTo(rule.getId());
+    assertThat(result.getName()).isEqualTo("Old name");
+    assertThat(result.getDescription()).isEqualTo("Old description");
+    assertThat(result.getSeverityString()).isEqualTo(Severity.INFO);
   }
 
   @Test
@@ -666,18 +672,17 @@ public class RuleCreatorMediumTest {
   }
 
   private RuleDto createTemplateRule() {
-    RuleDto templateRule = dao.insert(dbSession,
-      RuleTesting.newDto(RuleKey.of("java", "S001"))
-        .setIsTemplate(true)
-        .setLanguage("java")
-        .setConfigKey("S001")
-        .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
-        .setDefaultRemediationCoefficient("1h")
-        .setDefaultRemediationOffset("5min")
-        .setEffortToFixDescription("desc")
-        .setTags(Sets.newHashSet("usertag1", "usertag2"))
-        .setSystemTags(Sets.newHashSet("tag1", "tag4"))
-      );
+    RuleDto templateRule = RuleTesting.newDto(RuleKey.of("java", "S001"))
+      .setIsTemplate(true)
+      .setLanguage("java")
+      .setConfigKey("S001")
+      .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
+      .setDefaultRemediationCoefficient("1h")
+      .setDefaultRemediationOffset("5min")
+      .setEffortToFixDescription("desc")
+      .setTags(Sets.newHashSet("usertag1", "usertag2"))
+      .setSystemTags(Sets.newHashSet("tag1", "tag4"));
+    dao.insert(dbSession, templateRule);
     RuleParamDto ruleParamDto = RuleParamDto.createFor(templateRule).setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*");
     dao.insertRuleParam(dbSession, templateRule, ruleParamDto);
     dbSession.commit();
@@ -685,16 +690,15 @@ public class RuleCreatorMediumTest {
   }
 
   private RuleDto createTemplateRuleWithIntArrayParam() {
-    RuleDto templateRule = dao.insert(dbSession,
-      RuleTesting.newDto(RuleKey.of("java", "S002"))
-        .setIsTemplate(true)
-        .setLanguage("java")
-        .setConfigKey("S002")
-        .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
-        .setDefaultRemediationCoefficient("1h")
-        .setDefaultRemediationOffset("5min")
-        .setEffortToFixDescription("desc")
-      );
+    RuleDto templateRule = RuleTesting.newDto(RuleKey.of("java", "S002"))
+      .setIsTemplate(true)
+      .setLanguage("java")
+      .setConfigKey("S002")
+      .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
+      .setDefaultRemediationCoefficient("1h")
+      .setDefaultRemediationOffset("5min")
+      .setEffortToFixDescription("desc");
+    dao.insert(dbSession, templateRule);
     RuleParamDto ruleParamDto = RuleParamDto.createFor(templateRule)
       .setName("myIntegers").setType("INTEGER,multiple=true,values=1;2;3").setDescription("My Integers").setDefaultValue("1");
     dao.insertRuleParam(dbSession, templateRule, ruleParamDto);
@@ -703,16 +707,15 @@ public class RuleCreatorMediumTest {
   }
 
   private RuleDto createTemplateRuleWithTwoIntParams() {
-    RuleDto templateRule = dao.insert(dbSession,
-      RuleTesting.newDto(RuleKey.of("java", "S003"))
-        .setIsTemplate(true)
-        .setLanguage("java")
-        .setConfigKey("S003")
-        .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
-        .setDefaultRemediationCoefficient("1h")
-        .setDefaultRemediationOffset("5min")
-        .setEffortToFixDescription("desc")
-      );
+    RuleDto templateRule = RuleTesting.newDto(RuleKey.of("java", "S003"))
+      .setIsTemplate(true)
+      .setLanguage("java")
+      .setConfigKey("S003")
+      .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
+      .setDefaultRemediationCoefficient("1h")
+      .setDefaultRemediationOffset("5min")
+      .setEffortToFixDescription("desc");
+    dao.insert(dbSession, templateRule);
     RuleParamDto ruleParam1Dto = RuleParamDto.createFor(templateRule)
       .setName("first").setType("INTEGER").setDescription("First integer").setDefaultValue("0");
     dao.insertRuleParam(dbSession, templateRule, ruleParam1Dto);