]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7330 RuleUpdater is now using RuleIndexer
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 22 Feb 2016 10:47:26 +0000 (11:47 +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/RuleUpdater.java
server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java

index 98a95b97eca7ee72104e11e2deaeca43c27b9907..0acc2497660cf87361f988db123a5293754ab0b5 100644 (file)
@@ -19,6 +19,9 @@
  */
 package org.sonar.server.rule;
 
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Multimap;
@@ -39,6 +42,7 @@ import org.sonar.db.qualityprofile.ActiveRuleParamDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.server.db.DbClient;
+import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.user.UserSession;
 
 import static com.google.common.collect.Lists.newArrayList;
@@ -47,10 +51,12 @@ import static com.google.common.collect.Lists.newArrayList;
 public class RuleUpdater {
 
   private final DbClient dbClient;
+  private final RuleIndexer ruleIndexer;
   private final System2 system;
 
-  public RuleUpdater(DbClient dbClient, System2 system) {
+  public RuleUpdater(DbClient dbClient, RuleIndexer ruleIndexer, System2 system) {
     this.dbClient = dbClient;
+    this.ruleIndexer = ruleIndexer;
     this.system = system;
   }
 
@@ -81,12 +87,23 @@ public class RuleUpdater {
     Context context = newContext(update);
     // validate only the changes, not all the rule fields
     apply(update, context, userSession);
-    dbClient.deprecatedRuleDao().update(dbSession, context.rule);
+    update(dbSession, context.rule);
     updateParameters(dbSession, update, context);
     dbSession.commit();
+    ruleIndexer.setEnabled(true).index();
     return true;
   }
 
+  @VisibleForTesting
+  boolean update(RuleUpdate update, UserSession userSession) {
+    DbSession dbSession = dbClient.openSession(false);
+    try {
+      return update(dbSession, update, userSession);
+    } finally {
+      dbClient.closeSession(dbSession);
+    }
+  }
+
   /**
    * Load all the DTOs required for validating changes and updating rule
    */
@@ -94,7 +111,7 @@ public class RuleUpdater {
     DbSession dbSession = dbClient.openSession(false);
     try {
       Context context = new Context();
-      context.rule = dbClient.deprecatedRuleDao().getByKey(dbSession, change.getRuleKey());
+      context.rule = dbClient.ruleDao().selectOrFailByKey(dbSession, change.getRuleKey());
       if (RuleStatus.REMOVED == context.rule.getStatus()) {
         throw new IllegalArgumentException("Rule with REMOVED status cannot be updated: " + change.getRuleKey());
       }
@@ -145,6 +162,7 @@ public class RuleUpdater {
       throw new IllegalArgumentException("The description is missing");
     } else {
       context.rule.setDescription(description);
+      context.rule.setDescriptionFormat(RuleDto.Format.MARKDOWN);
     }
   }
 
@@ -221,8 +239,10 @@ public class RuleUpdater {
   private void updateParameters(DbSession dbSession, RuleUpdate update, Context context) {
     if (update.isChangeParameters() && update.isCustomRule()) {
       RuleDto customRule = context.rule;
-      RuleDto templateRule = dbClient.deprecatedRuleDao().selectTemplate(customRule, dbSession);
-      if (templateRule == null) {
+      Integer templateId = customRule.getTemplateId();
+      Preconditions.checkNotNull(templateId, "Rule '%s' has no persisted template!", customRule);
+      Optional<RuleDto> templateRule = dbClient.ruleDao().selectById(templateId, dbSession);
+      if (!templateRule.isPresent()) {
         throw new IllegalStateException(String.format("Template %s of rule %s does not exist",
           customRule.getTemplateId(), customRule.getKey()));
       }
@@ -245,13 +265,13 @@ public class RuleUpdater {
 
   private void deleteOrUpdateParameters(DbSession dbSession, RuleUpdate update, RuleDto customRule, List<String> paramKeys,
     Multimap<RuleDto, ActiveRuleDto> activeRules, Multimap<ActiveRuleDto, ActiveRuleParamDto> activeRuleParams) {
-    for (RuleParamDto ruleParamDto : dbClient.deprecatedRuleDao().selectRuleParamsByRuleKey(dbSession, update.getRuleKey())) {
+    for (RuleParamDto ruleParamDto : dbClient.ruleDao().selectRuleParamsByRuleKey(dbSession, update.getRuleKey())) {
       String key = ruleParamDto.getName();
       String value = Strings.emptyToNull(update.parameter(key));
 
       // Update rule param
       ruleParamDto.setDefaultValue(value);
-      dbClient.deprecatedRuleDao().updateRuleParam(dbSession, customRule, ruleParamDto);
+      dbClient.ruleDao().updateRuleParam(dbSession, customRule, ruleParamDto);
 
       if (value != null) {
         // Update linked active rule params or create new one
@@ -285,4 +305,10 @@ public class RuleUpdater {
     private RuleDto rule;
   }
 
+  private void update(DbSession session, RuleDto rule) {
+    rule.setUpdatedAtInMs(system.now());
+    rule.setUpdatedAt(new Date(system.now()));
+    dbClient.ruleDao().update(session, rule);
+  }
+
 }
index 61b11d32750745af8a50a41a561e78dcfee3a6b7..38a70f70934bd014eef908a588bba7e6de831d26 100644 (file)
@@ -143,7 +143,7 @@ public class UpdateAction implements RulesWsAction {
     DbSession dbSession = dbClient.openSession(false);
     try {
       RuleUpdate update = readRequest(dbSession, request);
-      ruleUpdater.update(dbSession, update, userSession);
+      ruleUpdater.update(update, userSession);
       UpdateResponse updateResponse = buildResponse(dbSession, update.getRuleKey());
 
       writeProtobuf(updateResponse, request, response);
index eeb89016853807d3be2b2e424d62a4a9384ba300..ebb4f2980adc0215a6f7fc6f04f106085ff5eea9 100644 (file)
  */
 package org.sonar.server.rule;
 
+import com.google.common.base.Function;
+import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
+import java.util.List;
+import java.util.Map;
 import java.util.Set;
+import javax.annotation.Nonnull;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -32,46 +37,49 @@ import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.server.debt.DebtRemediationFunction;
 import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.db.qualityprofile.QualityProfileDto;
+import org.sonar.db.rule.RuleDao;
 import org.sonar.db.rule.RuleDto;
 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.qualityprofile.ActiveRule;
 import org.sonar.server.qualityprofile.QProfileTesting;
 import org.sonar.server.qualityprofile.RuleActivation;
 import org.sonar.server.qualityprofile.RuleActivator;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-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 org.sonar.server.tester.UserSessionRule;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
 
+// TODO remove ServerTester usage when ActiveRule Daov2 is removed
 public class RuleUpdaterMediumTest {
 
-  private static final RuleKey RULE_KEY = RuleKey.of("squid", "S001");
+  static final RuleKey RULE_KEY = RuleKey.of("squid", "S001");
 
   @ClassRule
   public static ServerTester tester = new ServerTester();
+
   @org.junit.Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
   DbClient db = tester.get(DbClient.class);
   RuleDao ruleDao = tester.get(RuleDao.class);
-  DbSession dbSession;
-  BaseIndex<Rule, RuleDto, RuleKey> ruleIndex = tester.get(RuleIndex.class);
-  RuleUpdater updater = tester.get(RuleUpdater.class);
+  DbSession dbSession = db.openSession(false);
+  RuleIndex2 ruleIndex = tester.get(RuleIndex2.class);
+
+  RuleUpdater underTest = tester.get(RuleUpdater.class);
 
   @Before
   public void before() {
     tester.clearDbAndIndexes();
-    dbSession = db.openSession(false);
   }
 
   @After
@@ -86,7 +94,7 @@ public class RuleUpdaterMediumTest {
 
     RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setTags(Sets.newHashSet("java9"));
     try {
-      updater.update(dbSession, update, userSessionRule);
+      underTest.update(update, userSessionRule);
       fail();
     } catch (IllegalArgumentException e) {
       assertThat(e).hasMessage("Rule with REMOVED status cannot be updated: squid:S001");
@@ -107,10 +115,10 @@ public class RuleUpdaterMediumTest {
 
     RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY);
     assertThat(update.isEmpty()).isTrue();
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
 
     dbSession.clearCache();
-    RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY);
+    RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
     assertThat(rule.getNoteData()).isEqualTo("my *note*");
     assertThat(rule.getNoteUserLogin()).isEqualTo("me");
     assertThat(rule.getTags()).containsOnly("tag1");
@@ -136,10 +144,10 @@ public class RuleUpdaterMediumTest {
 
     RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY);
     update.setMarkdownNote("my *note*");
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
 
     dbSession.clearCache();
-    RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY);
+    RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
     assertThat(rule.getNoteData()).isEqualTo("my *note*");
     assertThat(rule.getNoteUserLogin()).isEqualTo("me");
     assertThat(rule.getNoteCreatedAt()).isNotNull();
@@ -159,10 +167,10 @@ public class RuleUpdaterMediumTest {
     dbSession.commit();
 
     RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setMarkdownNote(null);
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
 
     dbSession.clearCache();
-    RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY);
+    RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
     assertThat(rule.getNoteData()).isNull();
     assertThat(rule.getNoteUserLogin()).isNull();
     assertThat(rule.getNoteCreatedAt()).isNull();
@@ -179,10 +187,10 @@ public class RuleUpdaterMediumTest {
 
     // java8 is a system tag -> ignore
     RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setTags(Sets.newHashSet("bug", "java8"));
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
 
     dbSession.clearCache();
-    RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY);
+    RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
     assertThat(rule.getTags()).containsOnly("bug");
     assertThat(rule.getSystemTags()).containsOnly("java8", "javadoc");
 
@@ -199,10 +207,10 @@ public class RuleUpdaterMediumTest {
     dbSession.commit();
 
     RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setTags(null);
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
 
     dbSession.clearCache();
-    RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY);
+    RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
     assertThat(rule.getTags()).isEmpty();
     assertThat(rule.getSystemTags()).containsOnly("java8", "javadoc");
 
@@ -225,19 +233,18 @@ public class RuleUpdaterMediumTest {
     DefaultDebtRemediationFunction fn = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "1min");
     RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY)
       .setDebtRemediationFunction(fn);
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
     dbSession.clearCache();
 
     // verify debt is overridden
-    Rule indexedRule = tester.get(RuleIndex.class).getByKey(RULE_KEY);
-    assertThat(indexedRule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
-    assertThat(indexedRule.debtRemediationFunction().coefficient()).isNull();
-    assertThat(indexedRule.debtRemediationFunction().offset()).isEqualTo("1min");
-
-    assertThat(indexedRule.debtOverloaded()).isTrue();
-    assertThat(indexedRule.defaultDebtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
-    assertThat(indexedRule.defaultDebtRemediationFunction().coefficient()).isEqualTo("1d");
-    assertThat(indexedRule.defaultDebtRemediationFunction().offset()).isEqualTo("5min");
+    RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
+    assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE.name());
+    assertThat(rule.getRemediationCoefficient()).isNull();
+    assertThat(rule.getRemediationOffset()).isEqualTo("1min");
+
+    assertThat(rule.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET.name());
+    assertThat(rule.getDefaultRemediationCoefficient()).isEqualTo("1d");
+    assertThat(rule.getDefaultRemediationOffset()).isEqualTo("5min");
   }
 
   @Test
@@ -253,19 +260,18 @@ public class RuleUpdaterMediumTest {
 
     RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY)
       .setDebtRemediationFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "2d", null));
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
     dbSession.clearCache();
 
     // verify debt is overridden
-    Rule indexedRule = tester.get(RuleIndex.class).getByKey(RULE_KEY);
-    assertThat(indexedRule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
-    assertThat(indexedRule.debtRemediationFunction().coefficient()).isEqualTo("2d");
-    assertThat(indexedRule.debtRemediationFunction().offset()).isNull();
-
-    assertThat(indexedRule.debtOverloaded()).isTrue();
-    assertThat(indexedRule.defaultDebtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
-    assertThat(indexedRule.defaultDebtRemediationFunction().coefficient()).isEqualTo("1d");
-    assertThat(indexedRule.defaultDebtRemediationFunction().offset()).isNull();
+    RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
+    assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
+    assertThat(rule.getRemediationCoefficient()).isEqualTo("2d");
+    assertThat(rule.getRemediationOffset()).isNull();
+
+    assertThat(rule.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
+    assertThat(rule.getDefaultRemediationCoefficient()).isEqualTo("1d");
+    assertThat(rule.getDefaultRemediationOffset()).isNull();
   }
 
   @Test
@@ -281,19 +287,18 @@ public class RuleUpdaterMediumTest {
 
     RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY)
       .setDebtRemediationFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "10min"));
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
     dbSession.clearCache();
 
     // verify debt is overridden
-    Rule indexedRule = tester.get(RuleIndex.class).getByKey(RULE_KEY);
-    assertThat(indexedRule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
-    assertThat(indexedRule.debtRemediationFunction().coefficient()).isNull();
-    assertThat(indexedRule.debtRemediationFunction().offset()).isEqualTo("10min");
-
-    assertThat(indexedRule.debtOverloaded()).isTrue();
-    assertThat(indexedRule.defaultDebtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
-    assertThat(indexedRule.defaultDebtRemediationFunction().coefficient()).isEqualTo("1d");
-    assertThat(indexedRule.defaultDebtRemediationFunction().offset()).isEqualTo("5min");
+    RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
+    assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE.name());
+    assertThat(rule.getRemediationCoefficient()).isNull();
+    assertThat(rule.getRemediationOffset()).isEqualTo("10min");
+
+    assertThat(rule.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET.name());
+    assertThat(rule.getDefaultRemediationCoefficient()).isEqualTo("1d");
+    assertThat(rule.getDefaultRemediationOffset()).isEqualTo("5min");
   }
 
   @Test
@@ -308,19 +313,18 @@ public class RuleUpdaterMediumTest {
     dbSession.commit();
 
     RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setDebtRemediationFunction(null);
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
     dbSession.clearCache();
 
     // verify debt is coming from default values
-    Rule indexedRule = tester.get(RuleIndex.class).getByKey(RULE_KEY);
-    assertThat(indexedRule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
-    assertThat(indexedRule.debtRemediationFunction().coefficient()).isEqualTo("1d");
-    assertThat(indexedRule.debtRemediationFunction().offset()).isEqualTo("5min");
-
-    assertThat(indexedRule.debtOverloaded()).isFalse();
-    assertThat(indexedRule.defaultDebtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
-    assertThat(indexedRule.defaultDebtRemediationFunction().coefficient()).isEqualTo("1d");
-    assertThat(indexedRule.defaultDebtRemediationFunction().offset()).isEqualTo("5min");
+    RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
+    assertThat(rule.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
+    assertThat(rule.getDefaultRemediationCoefficient()).isEqualTo("1d");
+    assertThat(rule.getDefaultRemediationOffset()).isEqualTo("5min");
+
+    assertThat(rule.getRemediationFunction()).isNull();
+    assertThat(rule.getRemediationCoefficient()).isNull();
+    assertThat(rule.getRemediationOffset()).isNull();
   }
 
   @Test
@@ -352,21 +356,29 @@ public class RuleUpdaterMediumTest {
       .setSeverity("MAJOR")
       .setStatus(RuleStatus.READY)
       .setParameters(ImmutableMap.of("regex", "b.*"));
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
 
     dbSession.clearCache();
 
     // Verify custom rule is updated
-    Rule customRuleReloaded = ruleIndex.getByKey(customRule.getKey());
+    RuleDto customRuleReloaded = ruleDao.selectOrFailByKey(dbSession, customRule.getKey());
     assertThat(customRuleReloaded).isNotNull();
-    assertThat(customRuleReloaded.name()).isEqualTo("New name");
-    assertThat(customRuleReloaded.htmlDescription()).isEqualTo("New description");
-    assertThat(customRuleReloaded.severity()).isEqualTo("MAJOR");
-    assertThat(customRuleReloaded.status()).isEqualTo(RuleStatus.READY);
-    assertThat(customRuleReloaded.params()).hasSize(2);
-
-    assertThat(customRuleReloaded.params().get(0).defaultValue()).isEqualTo("b.*");
-    assertThat(customRuleReloaded.params().get(1).defaultValue()).isNull();
+    assertThat(customRuleReloaded.getName()).isEqualTo("New name");
+    assertThat(customRuleReloaded.getDescription()).isEqualTo("New description");
+    assertThat(customRuleReloaded.getSeverityString()).isEqualTo("MAJOR");
+    assertThat(customRuleReloaded.getStatus()).isEqualTo(RuleStatus.READY);
+
+    List<RuleParamDto> params = ruleDao.selectRuleParamsByRuleKey(dbSession, customRuleReloaded.getKey());
+    assertThat(params).hasSize(2);
+    assertThat(params.get(0).getDefaultValue()).isEqualTo("b.*");
+    assertThat(params.get(1).getDefaultValue()).isNull();
+
+    // Verify in index
+    assertThat(ruleIndex.search(new RuleQuery().setQueryText("New name"), new SearchOptions()).getIds()).containsOnly(customRule.getKey());
+    assertThat(ruleIndex.search(new RuleQuery().setQueryText("New description"), new SearchOptions()).getIds()).containsOnly(customRule.getKey());
+
+    assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old name"), new SearchOptions()).getTotal()).isZero();
+    assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old description"), new SearchOptions()).getTotal()).isZero();
   }
 
   @Test
@@ -394,14 +406,13 @@ public class RuleUpdaterMediumTest {
       .setMarkdownDescription("New description")
       .setSeverity("MAJOR")
       .setStatus(RuleStatus.READY);
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
 
     dbSession.clearCache();
 
     // Verify custom rule is updated
-    Rule customRuleReloaded = ruleIndex.getByKey(customRule.getKey());
-    RuleParam param = customRuleReloaded.params().get(0);
-    assertThat(param.defaultValue()).isNull();
+    List<RuleParamDto> params = ruleDao.selectRuleParamsByRuleKey(dbSession, customRule.getKey());
+    assertThat(params.get(0).getDefaultValue()).isNull();
   }
 
   @Test
@@ -437,22 +448,21 @@ public class RuleUpdaterMediumTest {
     // Update custom rule parameter 'regex', add 'message' and remove 'format'
     RuleUpdate update = RuleUpdate.createForCustomRule(customRule.getKey())
       .setParameters(ImmutableMap.of("regex", "b.*", "message", "a message"));
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
 
     dbSession.clearCache();
 
     // Verify custom rule parameters has been updated
-    Rule customRuleReloaded = ruleIndex.getByKey(customRule.getKey());
-    assertThat(customRuleReloaded.params()).hasSize(3);
-    assertThat(customRuleReloaded.param("regex")).isNotNull();
-    assertThat(customRuleReloaded.param("regex").defaultValue()).isEqualTo("b.*");
-    assertThat(customRuleReloaded.param("message")).isNotNull();
-    assertThat(customRuleReloaded.param("message").defaultValue()).isEqualTo("a message");
-    assertThat(customRuleReloaded.param("format")).isNotNull();
-    assertThat(customRuleReloaded.param("format").defaultValue()).isNull();
-
-    RuleParam param = customRuleReloaded.params().get(0);
-    assertThat(param.defaultValue()).isEqualTo("b.*");
+    List<RuleParamDto> params = ruleDao.selectRuleParamsByRuleKey(dbSession, customRule.getKey());
+    assertThat(params).hasSize(3);
+
+    Map<String, RuleParamDto> paramsByKey = paramsByKey(params);
+    assertThat(paramsByKey.get("regex")).isNotNull();
+    assertThat(paramsByKey.get("regex").getDefaultValue()).isEqualTo("b.*");
+    assertThat(paramsByKey.get("message")).isNotNull();
+    assertThat(paramsByKey.get("message").getDefaultValue()).isEqualTo("a message");
+    assertThat(paramsByKey.get("format")).isNotNull();
+    assertThat(paramsByKey.get("format").getDefaultValue()).isNull();
 
     // Verify active rule parameters has been updated
     ActiveRule activeRule = tester.get(ActiveRuleIndex.class).getByKey(ActiveRuleKey.of(profileDto.getKey(), customRule.getKey()));
@@ -482,7 +492,7 @@ public class RuleUpdaterMediumTest {
       .setName("")
       .setMarkdownDescription("New desc");
     try {
-      updater.update(dbSession, update, userSessionRule);
+      underTest.update(update, userSessionRule);
       fail();
     } catch (Exception e) {
       assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("The name is missing");
@@ -506,7 +516,7 @@ public class RuleUpdaterMediumTest {
       .setName("New name")
       .setMarkdownDescription("");
     try {
-      updater.update(dbSession, update, userSessionRule);
+      underTest.update(update, userSessionRule);
       fail();
     } catch (Exception e) {
       assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("The description is missing");
@@ -529,16 +539,23 @@ public class RuleUpdaterMediumTest {
       .setName("New name")
       .setMarkdownDescription("New description")
       .setSeverity(Severity.CRITICAL);
-    updater.update(dbSession, update, userSessionRule);
+    underTest.update(update, userSessionRule);
 
     dbSession.clearCache();
 
     // Verify manual rule is updated
-    Rule manualRuleReloaded = ruleIndex.getByKey(manualRule.getKey());
+    RuleDto manualRuleReloaded = ruleDao.selectOrFailByKey(dbSession, manualRule.getKey());
     assertThat(manualRuleReloaded).isNotNull();
-    assertThat(manualRuleReloaded.name()).isEqualTo("New name");
-    assertThat(manualRuleReloaded.htmlDescription()).isEqualTo("New description");
-    assertThat(manualRuleReloaded.severity()).isEqualTo(Severity.CRITICAL);
+    assertThat(manualRuleReloaded.getName()).isEqualTo("New name");
+    assertThat(manualRuleReloaded.getDescription()).isEqualTo("New description");
+    assertThat(manualRuleReloaded.getSeverityString()).isEqualTo(Severity.CRITICAL);
+
+    // Verify in index
+    assertThat(ruleIndex.search(new RuleQuery().setQueryText("New name"), new SearchOptions()).getIds()).containsOnly(manualRule.getKey());
+    assertThat(ruleIndex.search(new RuleQuery().setQueryText("New description"), new SearchOptions()).getIds()).containsOnly(manualRule.getKey());
+
+    assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old name"), new SearchOptions()).getTotal()).isZero();
+    assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old description"), new SearchOptions()).getTotal()).isZero();
   }
 
   @Test
@@ -631,4 +648,17 @@ public class RuleUpdaterMediumTest {
       assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom or a manual rule");
     }
   }
+
+  private static Map<String, RuleParamDto> paramsByKey(List<RuleParamDto> params) {
+    return FluentIterable.from(params).uniqueIndex(RuleParamToKey.INSTANCE);
+  }
+
+  private enum RuleParamToKey implements Function<RuleParamDto, String> {
+    INSTANCE;
+
+    @Override
+    public String apply(@Nonnull RuleParamDto input) {
+      return input.getName();
+    }
+  }
 }