]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7330 RuleActivator is now using ActiveRuleIndexer
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 24 Feb 2016 19:28:45 +0000 (20:28 +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/qualityprofile/RuleActivator.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java

index 8a0841b4c4907955b978277a59c709ed53813a99..f73164f415eea44914c14fba2d3c5905f6d1483b 100644 (file)
@@ -21,6 +21,8 @@ package org.sonar.server.qualityprofile;
 
 import com.google.common.base.Splitter;
 import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -41,6 +43,7 @@ import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.server.activity.ActivityService;
 import org.sonar.server.exceptions.BadRequestException;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
 import org.sonar.server.rule.index.RuleIndex2;
 import org.sonar.server.rule.index.RuleQuery;
 import org.sonar.server.util.TypeValidations;
@@ -58,16 +61,18 @@ public class RuleActivator {
   private final TypeValidations typeValidations;
   private final RuleActivatorContextFactory contextFactory;
   private final RuleIndex2 ruleIndex;
+  private final ActiveRuleIndexer activeRuleIndexer;
   private final ActivityService activityService;
 
   public RuleActivator(System2 system2, DbClient db, RuleIndex2 ruleIndex,
     RuleActivatorContextFactory contextFactory, TypeValidations typeValidations,
-    ActivityService activityService) {
+    ActiveRuleIndexer activeRuleIndexer, ActivityService activityService) {
     this.system2 = system2;
     this.db = db;
     this.ruleIndex = ruleIndex;
     this.contextFactory = contextFactory;
     this.typeValidations = typeValidations;
+    this.activeRuleIndexer = activeRuleIndexer;
     this.activityService = activityService;
   }
 
@@ -311,6 +316,7 @@ public class RuleActivator {
     try {
       List<ActiveRuleChange> changes = deactivate(dbSession, key);
       dbSession.commit();
+      activeRuleIndexer.index(changes);
       return changes;
     } finally {
       dbSession.close();
@@ -388,8 +394,8 @@ public class RuleActivator {
   }
 
   BulkChangeResult bulkActivate(RuleQuery ruleQuery, String profileKey, @Nullable String severity) {
-    BulkChangeResult result = new BulkChangeResult();
     DbSession dbSession = db.openSession(false);
+    BulkChangeResult result = new BulkChangeResult();
     try {
       Iterator<RuleKey> rules = ruleIndex.searchAll(ruleQuery);
       while (rules.hasNext()) {
@@ -410,6 +416,7 @@ public class RuleActivator {
         }
       }
       dbSession.commit();
+      activeRuleIndexer.index(result.getChanges());
     } finally {
       dbSession.close();
     }
@@ -418,8 +425,8 @@ public class RuleActivator {
 
   BulkChangeResult bulkDeactivate(RuleQuery ruleQuery, String profile) {
     DbSession dbSession = db.openSession(false);
+    BulkChangeResult result = new BulkChangeResult();
     try {
-      BulkChangeResult result = new BulkChangeResult();
       Iterator<RuleKey> rules = ruleIndex.searchAll(ruleQuery);
       while (rules.hasNext()) {
         try {
@@ -437,6 +444,7 @@ public class RuleActivator {
         }
       }
       dbSession.commit();
+      activeRuleIndexer.index(result.getChanges());
       return result;
     } finally {
       dbSession.close();
@@ -446,26 +454,28 @@ public class RuleActivator {
   public void setParent(String key, @Nullable String parentKey) {
     DbSession dbSession = db.openSession(false);
     try {
-      setParent(dbSession, key, parentKey);
+      List<ActiveRuleChange> changes = setParent(dbSession, key, parentKey);
       dbSession.commit();
+      activeRuleIndexer.index(changes);
 
     } finally {
       dbSession.close();
     }
   }
 
-  void setParent(DbSession dbSession, String profileKey, @Nullable String parentKey) {
+  List<ActiveRuleChange> setParent(DbSession dbSession, String profileKey, @Nullable String parentKey) {
     QualityProfileDto profile = db.qualityProfileDao().selectOrFailByKey(dbSession, profileKey);
+    List<ActiveRuleChange> changes = new ArrayList<>();
     if (parentKey == null) {
       // unset if parent is defined, else nothing to do
-      removeParent(dbSession, profile);
+      changes.addAll(removeParent(dbSession, profile));
 
     } else if (profile.getParentKee() == null || !parentKey.equals(profile.getParentKee())) {
       QualityProfileDto parentProfile = db.qualityProfileDao().selectOrFailByKey(dbSession, parentKey);
       if (isDescendant(dbSession, profile, parentProfile)) {
         throw new BadRequestException(String.format("Descendant profile '%s' can not be selected as parent of '%s'", parentKey, profileKey));
       }
-      removeParent(dbSession, profile);
+      changes.addAll(removeParent(dbSession, profile));
 
       // set new parent
       profile.setParentKee(parentKey);
@@ -473,32 +483,37 @@ public class RuleActivator {
       for (ActiveRuleDto parentActiveRule : db.activeRuleDao().selectByProfileKey(dbSession, parentKey)) {
         try {
           RuleActivation activation = new RuleActivation(parentActiveRule.getKey().ruleKey());
-          activate(dbSession, activation, profileKey);
+          changes.addAll(activate(dbSession, activation, profileKey));
         } catch (BadRequestException e) {
           // for example because rule status is REMOVED
           // TODO return errors
         }
       }
     }
+    return changes;
   }
 
   /**
    * Does not commit
    */
-  private void removeParent(DbSession dbSession, QualityProfileDto profileDto) {
+  private List<ActiveRuleChange> removeParent(DbSession dbSession, QualityProfileDto profileDto) {
     if (profileDto.getParentKee() != null) {
+      List<ActiveRuleChange> changes = new ArrayList<>();
       profileDto.setParentKee(null);
       db.qualityProfileDao().update(dbSession, profileDto);
       for (ActiveRuleDto activeRule : db.activeRuleDao().selectByProfileKey(dbSession, profileDto.getKey())) {
         if (ActiveRuleDto.INHERITED.equals(activeRule.getInheritance())) {
-          deactivate(dbSession, activeRule.getKey(), true);
+          changes.addAll(deactivate(dbSession, activeRule.getKey(), true));
         } else if (ActiveRuleDto.OVERRIDES.equals(activeRule.getInheritance())) {
           activeRule.setInheritance(null);
           activeRule.setUpdatedAtInMs(system2.now());
           db.activeRuleDao().update(dbSession, activeRule);
+          changes.add(ActiveRuleChange.createFor(ActiveRuleChange.Type.UPDATED, activeRule.getKey()).setInheritance(null));
         }
       }
+      return changes;
     }
+    return Collections.emptyList();
   }
 
   boolean isDescendant(DbSession dbSession, QualityProfileDto childProfile, @Nullable QualityProfileDto parentProfile) {
index 8bda831464f5e965068ca4ab4bf52f9dc85ae994..28724162f817995812ff193cec5e9e1bec92a2a0 100644 (file)
@@ -33,8 +33,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
-import org.sonar.api.rule.Severity;
 import org.sonar.api.server.rule.RuleParamType;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
@@ -42,12 +42,14 @@ import org.sonar.db.qualityprofile.ActiveRuleParamDto;
 import org.sonar.db.qualityprofile.QualityProfileDto;
 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.exceptions.BadRequestException;
 import org.sonar.server.exceptions.Message;
-import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-import org.sonar.server.rule.index.RuleIndex;
+import org.sonar.server.qualityprofile.index.ActiveRuleDoc;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndex2;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
+import org.sonar.server.rule.index.RuleIndex2;
+import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.rule.index.RuleQuery;
 import org.sonar.server.search.QueryContext;
 import org.sonar.server.tester.ServerTester;
@@ -55,10 +57,25 @@ import org.sonar.server.tester.UserSessionRule;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
+import static org.sonar.api.rule.Severity.BLOCKER;
+import static org.sonar.api.rule.Severity.CRITICAL;
+import static org.sonar.api.rule.Severity.INFO;
+import static org.sonar.api.rule.Severity.MAJOR;
+import static org.sonar.api.rule.Severity.MINOR;
+import static org.sonar.db.qualityprofile.ActiveRuleDto.INHERITED;
+import static org.sonar.db.qualityprofile.ActiveRuleDto.OVERRIDES;
+import static org.sonar.db.rule.RuleTesting.XOO_X1;
+import static org.sonar.db.rule.RuleTesting.XOO_X2;
+import static org.sonar.db.rule.RuleTesting.newCustomRule;
+import static org.sonar.db.rule.RuleTesting.newDto;
+import static org.sonar.db.rule.RuleTesting.newTemplateRule;
+import static org.sonar.db.rule.RuleTesting.newXooX1;
+import static org.sonar.db.rule.RuleTesting.newXooX2;
 import static org.sonar.server.qualityprofile.QProfileTesting.XOO_P1_KEY;
 import static org.sonar.server.qualityprofile.QProfileTesting.XOO_P2_KEY;
 import static org.sonar.server.qualityprofile.QProfileTesting.XOO_P3_KEY;
 
+// TODO Replace ServerTester by EsTester and DbTester
 public class RuleActivatorMediumTest {
 
   static final RuleKey MANUAL_RULE_KEY = RuleKey.of(RuleKey.MANUAL_REPOSITORY_KEY, "m1");
@@ -66,14 +83,20 @@ public class RuleActivatorMediumTest {
   static final RuleKey CUSTOM_RULE_KEY = RuleKey.of("xoo", "custom1");
 
   @ClassRule
-  public static ServerTester tester = new ServerTester();
+  public static ServerTester tester = new ServerTester().withEsIndexes();
+
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
 
   DbClient db;
   DbSession dbSession;
+
   RuleActivator ruleActivator;
-  ActiveRuleIndex index;
+
+  RuleIndexer ruleIndexer;
+
+  ActiveRuleIndex2 activeRuleIndex;
+  ActiveRuleIndexer activeRuleIndexer;
 
   QualityProfileDto profileDto;
 
@@ -83,28 +106,36 @@ public class RuleActivatorMediumTest {
     db = tester.get(DbClient.class);
     dbSession = db.openSession(false);
     ruleActivator = tester.get(RuleActivator.class);
-    index = tester.get(ActiveRuleIndex.class);
+    activeRuleIndex = tester.get(ActiveRuleIndex2.class);
+    activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
+    activeRuleIndexer.setEnabled(true);
+    ruleIndexer = tester.get(RuleIndexer.class);
+    ruleIndexer.setEnabled(true);
 
     // create pre-defined rules
-    RuleDto javaRule = RuleTesting.newDto(RuleKey.of("squid", "j1"))
+    RuleDto javaRule = newDto(RuleKey.of("squid", "j1"))
       .setSeverity("MAJOR").setLanguage("java");
-    RuleDto xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR");
-    RuleDto xooRule2 = RuleTesting.newXooX2().setSeverity("INFO");
-    RuleDto xooTemplateRule1 = RuleTesting.newTemplateRule(TEMPLATE_RULE_KEY)
+    RuleDto xooRule1 = newXooX1().setSeverity("MINOR");
+    RuleDto xooRule2 = newXooX2().setSeverity("INFO");
+    RuleDto xooTemplateRule1 = newTemplateRule(TEMPLATE_RULE_KEY)
       .setSeverity("MINOR").setLanguage("xoo");
-    RuleDto manualRule = RuleTesting.newDto(MANUAL_RULE_KEY);
-    db.deprecatedRuleDao().insert(dbSession, javaRule, xooRule1, xooRule2, xooTemplateRule1, manualRule);
-    db.deprecatedRuleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1)
+    RuleDto manualRule = newDto(MANUAL_RULE_KEY);
+    db.ruleDao().insert(dbSession, javaRule);
+    db.ruleDao().insert(dbSession, xooRule1);
+    db.ruleDao().insert(dbSession, xooRule2);
+    db.ruleDao().insert(dbSession, xooTemplateRule1);
+    db.ruleDao().insert(dbSession, manualRule);
+    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1)
       .setName("max").setDefaultValue("10").setType(RuleParamType.INTEGER.type()));
-    db.deprecatedRuleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1)
+    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1)
       .setName("min").setType(RuleParamType.INTEGER.type()));
-    db.deprecatedRuleDao().insertRuleParam(dbSession, xooTemplateRule1, RuleParamDto.createFor(xooTemplateRule1)
+    db.ruleDao().insertRuleParam(dbSession, xooTemplateRule1, RuleParamDto.createFor(xooTemplateRule1)
       .setName("format").setType(RuleParamType.STRING.type()));
 
-    RuleDto xooCustomRule1 = RuleTesting.newCustomRule(xooTemplateRule1).setRuleKey(CUSTOM_RULE_KEY.rule())
+    RuleDto xooCustomRule1 = newCustomRule(xooTemplateRule1).setRuleKey(CUSTOM_RULE_KEY.rule())
       .setSeverity("MINOR").setLanguage("xoo");
-    db.deprecatedRuleDao().insert(dbSession, xooCustomRule1);
-    db.deprecatedRuleDao().insertRuleParam(dbSession, xooCustomRule1, RuleParamDto.createFor(xooTemplateRule1)
+    db.ruleDao().insert(dbSession, xooCustomRule1);
+    db.ruleDao().insertRuleParam(dbSession, xooCustomRule1, RuleParamDto.createFor(xooTemplateRule1)
       .setName("format").setDefaultValue("txt").setType(RuleParamType.STRING.type()));
 
     // create pre-defined profile P1
@@ -112,6 +143,7 @@ public class RuleActivatorMediumTest {
     db.qualityProfileDao().insert(dbSession, profileDto);
     dbSession.commit();
     dbSession.clearCache();
+    ruleIndexer.index();
   }
 
   @After
@@ -121,8 +153,8 @@ public class RuleActivatorMediumTest {
 
   @Test
   public void activate() {
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activation.setParameter("min", "3");
     List<ActiveRuleChange> changes = ruleActivator.activate(dbSession, activation, XOO_P1_KEY);
@@ -130,7 +162,7 @@ public class RuleActivatorMediumTest {
     dbSession.clearCache();
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.BLOCKER, null,
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), BLOCKER, null,
       ImmutableMap.of("max", "7", "min", "3"));
     assertThat(changes).hasSize(1);
     assertThat(changes.get(0).getType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED);
@@ -138,8 +170,8 @@ public class RuleActivatorMediumTest {
 
   @Test
   public void activate_with_profile_dto() {
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activation.setParameter("min", "3");
     List<ActiveRuleChange> changes = ruleActivator.activate(dbSession, activation, profileDto);
@@ -147,7 +179,7 @@ public class RuleActivatorMediumTest {
     dbSession.clearCache();
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.BLOCKER, null,
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), BLOCKER, null,
       ImmutableMap.of("max", "7", "min", "3"));
     assertThat(changes).hasSize(1);
     assertThat(changes.get(0).getType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED);
@@ -155,10 +187,10 @@ public class RuleActivatorMediumTest {
 
   @Test
   public void activate_with_default_severity_and_parameter() {
-    activate(new RuleActivation(RuleTesting.XOO_X1), XOO_P1_KEY);
+    activate(new RuleActivation(XOO_X1), XOO_P1_KEY);
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MINOR, null,
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), MINOR, null,
       ImmutableMap.of("max", "10"));
   }
 
@@ -167,12 +199,12 @@ public class RuleActivatorMediumTest {
    */
   @Test
   public void activate_with_empty_parameter_having_no_default_value() {
-    activate(new RuleActivation(RuleTesting.XOO_X1)
+    activate(new RuleActivation(XOO_X1)
       .setParameter("min", ""),
       XOO_P1_KEY);
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MINOR, null,
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), MINOR, null,
       // Max should be set to default value, min has not value it should be ignored
       ImmutableMap.of("max", "10"));
   }
@@ -182,13 +214,13 @@ public class RuleActivatorMediumTest {
    */
   @Test
   public void activate_with_empty_parameters() {
-    activate(new RuleActivation(RuleTesting.XOO_X1)
+    activate(new RuleActivation(XOO_X1)
       .setParameters(ImmutableMap.of("max", "", "min", "")),
       XOO_P1_KEY);
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
     // Max should be set to default value, min has not value it should be ignored
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MINOR, null,
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), MINOR, null,
       ImmutableMap.of("max", "10"));
   }
 
@@ -197,41 +229,41 @@ public class RuleActivatorMediumTest {
    */
   @Test
   public void activate_rule_with_negative_integer_value_on_parameter_having_no_default_value() {
-    activate(new RuleActivation(RuleTesting.XOO_X1)
+    activate(new RuleActivation(XOO_X1)
       .setParameter("min", "-10"),
       XOO_P1_KEY);
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
     // Max should be set to default value, min should be set to -10
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MINOR, null,
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), MINOR, null,
       ImmutableMap.of("max", "10", "min", "-10"));
   }
 
   @Test
   public void activation_ignores_unsupported_parameters() {
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
+    RuleActivation activation = new RuleActivation(XOO_X1);
     activation.setParameter("xxx", "yyy");
     activate(activation, XOO_P1_KEY);
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MINOR, null, ImmutableMap.of("max", "10"));
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), MINOR, null, ImmutableMap.of("max", "10"));
   }
 
   @Test
   public void update_activation_severity_and_parameters() {
     // initial activation
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activate(activation, XOO_P1_KEY);
 
     // update
-    RuleActivation update = new RuleActivation(RuleTesting.XOO_X1);
-    update.setSeverity(Severity.CRITICAL);
+    RuleActivation update = new RuleActivation(XOO_X1);
+    update.setSeverity(CRITICAL);
     update.setParameter("max", "42");
     List<ActiveRuleChange> changes = activate(update, XOO_P1_KEY);
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.CRITICAL, null, ImmutableMap.of("max", "42"));
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), CRITICAL, null, ImmutableMap.of("max", "42"));
     assertThat(changes).hasSize(1);
     assertThat(changes.get(0).getType()).isEqualTo(ActiveRuleChange.Type.UPDATED);
   }
@@ -239,18 +271,18 @@ public class RuleActivatorMediumTest {
   @Test
   public void update_activation_with_parameter_without_default_value() {
     // initial activation -> param "max" has a default value
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activate(activation, XOO_P1_KEY);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.BLOCKER, null,
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), BLOCKER, null,
       ImmutableMap.of("max", "10"));
 
     // update param "min", which has no default value
-    RuleActivation update = new RuleActivation(RuleTesting.XOO_X1);
+    RuleActivation update = new RuleActivation(XOO_X1);
     update.setParameter("min", "3");
     List<ActiveRuleChange> changes = activate(update, XOO_P1_KEY);
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.BLOCKER, null,
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), BLOCKER, null,
       ImmutableMap.of("min", "3", "max", "10"));
     assertThat(changes).hasSize(1);
     assertThat(changes.get(0).getType()).isEqualTo(ActiveRuleChange.Type.UPDATED);
@@ -259,38 +291,38 @@ public class RuleActivatorMediumTest {
   @Test
   public void update_activation_but_new_parameter() {
     // initial activation
-    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1);
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, XOO_X1);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activate(activation, XOO_P1_KEY);
 
-    assertThat(db.deprecatedActiveRuleDao().selectParamByKeyAndName(activeRuleKey, "max", dbSession)).isNotNull();
-    db.deprecatedActiveRuleDao().deleteParamByKeyAndName(dbSession, activeRuleKey, "max");
+    assertThat(db.activeRuleDao().selectParamByKeyAndName(activeRuleKey, "max", dbSession)).isNotNull();
+    db.activeRuleDao().deleteParamByKeyAndName(dbSession, activeRuleKey, "max");
     dbSession.commit();
-    assertThat(db.deprecatedActiveRuleDao().selectParamByKeyAndName(activeRuleKey, "max", dbSession)).isNull();
+    assertThat(db.activeRuleDao().selectParamByKeyAndName(activeRuleKey, "max", dbSession)).isNull();
     dbSession.clearCache();
 
     // update
-    RuleActivation update = new RuleActivation(RuleTesting.XOO_X1);
-    update.setSeverity(Severity.CRITICAL);
+    RuleActivation update = new RuleActivation(XOO_X1);
+    update.setSeverity(CRITICAL);
     update.setParameter("max", "42");
     // contrary to activerule, the param 'max' is supposed to be inserted but not updated
     activate(update, XOO_P1_KEY);
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(activeRuleKey, Severity.CRITICAL, null, ImmutableMap.of("max", "42"));
+    verifyHasActiveRuleInDb(activeRuleKey, CRITICAL, null, ImmutableMap.of("max", "42"));
   }
 
   @Test
   public void ignore_activation_without_changes() {
     // initial activation
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activate(activation, XOO_P1_KEY);
 
     // update with exactly the same severity and params
-    RuleActivation update = new RuleActivation(RuleTesting.XOO_X1);
-    update.setSeverity(Severity.BLOCKER);
+    RuleActivation update = new RuleActivation(XOO_X1);
+    update.setSeverity(BLOCKER);
     List<ActiveRuleChange> changes = activate(update, XOO_P1_KEY);
     assertThat(changes).isEmpty();
   }
@@ -298,35 +330,35 @@ public class RuleActivatorMediumTest {
   @Test
   public void do_not_change_severity_and_params_if_unset_and_already_activated() {
     // initial activation
-    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1);
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, XOO_X1);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
 
     // update without any severity or params => keep
-    RuleActivation update = new RuleActivation(RuleTesting.XOO_X1);
+    RuleActivation update = new RuleActivation(XOO_X1);
     activate(update, XOO_P1_KEY);
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(activeRuleKey, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyHasActiveRuleInDb(activeRuleKey, BLOCKER, null, ImmutableMap.of("max", "7"));
   }
 
   @Test
   public void revert_activation_to_default_severity_and_parameters() {
     // initial activation
-    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1);
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, XOO_X1);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activation.setParameter("min", "3");
     activate(activation, XOO_P1_KEY);
 
     // update without any severity or params = reset
-    RuleActivation update = new RuleActivation(RuleTesting.XOO_X1).setReset(true);
+    RuleActivation update = new RuleActivation(XOO_X1).setReset(true);
     activate(update, XOO_P1_KEY);
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(activeRuleKey, Severity.MINOR, null,
+    verifyHasActiveRuleInDb(activeRuleKey, MINOR, null,
       // only default values
       ImmutableMap.of("max", "10"));
   }
@@ -344,7 +376,7 @@ public class RuleActivatorMediumTest {
     activate(update, XOO_P1_KEY);
 
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
-    verifyHasActiveRule(activeRuleKey, Severity.MINOR, null, ImmutableMap.of("format", "txt"));
+    verifyHasActiveRuleInDb(activeRuleKey, MINOR, null, ImmutableMap.of("format", "txt"));
   }
 
   @Test
@@ -390,13 +422,13 @@ public class RuleActivatorMediumTest {
 
   @Test
   public void fail_to_activate_if_rule_with_removed_status() {
-    RuleDto ruleDto = db.deprecatedRuleDao().getByKey(dbSession, RuleTesting.XOO_X1);
+    RuleDto ruleDto = db.ruleDao().selectOrFailByKey(dbSession, XOO_X1);
     ruleDto.setStatus(RuleStatus.REMOVED);
-    db.deprecatedRuleDao().update(dbSession, ruleDto);
+    db.ruleDao().update(dbSession, ruleDto);
     dbSession.commit();
     dbSession.clearCache();
 
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
+    RuleActivation activation = new RuleActivation(XOO_X1);
 
     try {
       activate(activation, XOO_P1_KEY);
@@ -423,7 +455,7 @@ public class RuleActivatorMediumTest {
   @Test
   public void fail_to_activate_if_unknown_profile() {
     try {
-      activate(new RuleActivation(RuleTesting.XOO_X1), "unknown");
+      activate(new RuleActivation(XOO_X1), "unknown");
       fail();
     } catch (BadRequestException e) {
       assertThat(e).hasMessage("Quality profile not found: unknown");
@@ -432,7 +464,7 @@ public class RuleActivatorMediumTest {
 
   @Test
   public void fail_to_activate_if_invalid_parameter() {
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
+    RuleActivation activation = new RuleActivation(XOO_X1);
     activation.setParameter("max", "foo");
 
     try {
@@ -448,13 +480,13 @@ public class RuleActivatorMediumTest {
   @Test
   public void deactivate() {
     // activation
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
 
     // deactivation
-    ruleActivator.deactivate(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1));
+    ruleActivator.deactivate(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1));
 
     verifyZeroActiveRules(XOO_P1_KEY);
   }
@@ -462,7 +494,7 @@ public class RuleActivatorMediumTest {
   @Test
   public void ignore_deactivation_if_rule_not_activated() {
     // deactivation
-    ActiveRuleKey key = ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1);
+    ActiveRuleKey key = ActiveRuleKey.of(XOO_P1_KEY, XOO_X1);
     ruleActivator.deactivate(key);
 
     verifyZeroActiveRules(XOO_P1_KEY);
@@ -482,7 +514,7 @@ public class RuleActivatorMediumTest {
 
   @Test
   public void deactivation_fails_if_profile_not_found() {
-    ActiveRuleKey key = ActiveRuleKey.of("unknown", RuleTesting.XOO_X1);
+    ActiveRuleKey key = ActiveRuleKey.of("unknown", XOO_X1);
     try {
       ruleActivator.deactivate(key);
       fail();
@@ -494,18 +526,18 @@ public class RuleActivatorMediumTest {
   @Test
   public void allow_to_deactivate_removed_rule() {
     // activation
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
+    RuleActivation activation = new RuleActivation(XOO_X1);
     activate(activation, XOO_P1_KEY);
 
     // set rule as removed
-    RuleDto rule = db.deprecatedRuleDao().getByKey(dbSession, RuleTesting.XOO_X1);
+    RuleDto rule = db.ruleDao().selectOrFailByKey(dbSession, XOO_X1);
     rule.setStatus(RuleStatus.REMOVED);
-    db.deprecatedRuleDao().update(dbSession, rule);
+    db.ruleDao().update(dbSession, rule);
     dbSession.commit();
     dbSession.clearCache();
 
     // deactivation
-    ruleActivator.deactivate(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1));
+    ruleActivator.deactivate(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1));
 
     verifyZeroActiveRules(XOO_P1_KEY);
   }
@@ -516,24 +548,24 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on child profile, but not on root
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activate(activation, XOO_P2_KEY);
 
     verifyZeroActiveRules(XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
 
     // update severity on child
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.MINOR);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(MINOR);
     activation.setParameter("max", "77");
     activate(activation, XOO_P2_KEY);
 
     verifyZeroActiveRules(XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.MINOR, null, ImmutableMap.of("max", "77"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.MINOR, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "77"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, MINOR, null, ImmutableMap.of("max", "77"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, MINOR, INHERITED, ImmutableMap.of("max", "77"));
   }
 
   @Test
@@ -541,15 +573,15 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on root profile
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     List<ActiveRuleChange> changes = activate(activation, XOO_P1_KEY);
 
     assertThat(changes).hasSize(3);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
   }
 
   @Test
@@ -557,43 +589,43 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on root profile
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
 
     // update on parent
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.INFO);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(INFO);
     activation.setParameter("max", "8");
     activate(activation, XOO_P1_KEY);
 
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.INFO, null, ImmutableMap.of("max", "8"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, INFO, null, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "8"));
 
     // update on child -> propagate on grand child only
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.MINOR);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(MINOR);
     activation.setParameter("max", "9");
     activate(activation, XOO_P2_KEY);
 
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.INFO, null, ImmutableMap.of("max", "8"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.MINOR, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "9"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.MINOR, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "9"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, INFO, null, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, MINOR, OVERRIDES, ImmutableMap.of("max", "9"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, MINOR, INHERITED, ImmutableMap.of("max", "9"));
 
     // update on grand child
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "10");
     activate(activation, XOO_P3_KEY);
 
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.INFO, null, ImmutableMap.of("max", "8"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.MINOR, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "9"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "10"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, INFO, null, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, MINOR, OVERRIDES, ImmutableMap.of("max", "9"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, OVERRIDES, ImmutableMap.of("max", "10"));
   }
 
   @Test
@@ -601,39 +633,39 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on root profile P1
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.INFO);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(INFO);
     activation.setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.INFO, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, INFO, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "7"));
 
     // override on child P2
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "8");
     activate(activation, XOO_P2_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.INFO, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "8"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, INFO, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, OVERRIDES, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "8"));
 
     // change on parent -> do not propagate on children because they're overriding values
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.CRITICAL);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(CRITICAL);
     activation.setParameter("max", "9");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.CRITICAL, null, ImmutableMap.of("max", "9"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "8"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, CRITICAL, null, ImmutableMap.of("max", "9"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, OVERRIDES, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "8"));
 
     // reset on parent (use default severity and params) -> do not propagate on children because they're overriding values
-    activation = new RuleActivation(RuleTesting.XOO_X1).setReset(true);
+    activation = new RuleActivation(XOO_X1).setReset(true);
     activate(activation, XOO_P1_KEY);
 
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.MINOR, null, ImmutableMap.of("max", "10"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "8"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, MINOR, null, ImmutableMap.of("max", "10"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, OVERRIDES, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "8"));
   }
 
   @Test
@@ -641,22 +673,22 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on child profile
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.INFO);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(INFO);
     activation.setParameter("max", "7");
     activate(activation, XOO_P2_KEY);
     verifyZeroActiveRules(XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.INFO, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, INFO, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "7"));
 
     // active the same rule on root profile -> mark the child profile as OVERRIDES
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.MAJOR);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(MAJOR);
     activation.setParameter("max", "8");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.MAJOR, null, ImmutableMap.of("max", "8"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, MAJOR, null, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, INFO, OVERRIDES, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "7"));
   }
 
   @Test
@@ -664,20 +696,20 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on root profile
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.INFO);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(INFO);
     activation.setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.INFO, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, INFO, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "7"));
 
     // override on child P2 with same severity and params -> do nothing (still INHERITED but not OVERRIDDEN)
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.INFO);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(INFO);
     activation.setParameter("max", "7");
     activate(activation, XOO_P2_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.INFO, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, INFO, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "7"));
   }
 
   @Test
@@ -685,16 +717,16 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on root profile
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
 
     // deactivate on root
-    ruleActivator.deactivate(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1));
+    ruleActivator.deactivate(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1));
 
     verifyZeroActiveRules(XOO_P1_KEY);
     verifyZeroActiveRules(XOO_P2_KEY);
@@ -706,25 +738,25 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on root profile
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.INFO);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(INFO);
     activation.setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.INFO, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, INFO, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "7"));
 
     // override on child
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "8");
     activate(activation, XOO_P2_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.INFO, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "8"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, INFO, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, OVERRIDES, ImmutableMap.of("max", "8"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "8"));
 
     // deactivate on parent -> do not propagate on children because they're overriding values
-    ruleActivator.deactivate(ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1));
+    ruleActivator.deactivate(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1));
     dbSession.clearCache();
     verifyZeroActiveRules(XOO_P1_KEY);
     verifyZeroActiveRules(XOO_P2_KEY);
@@ -736,17 +768,17 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on root profile
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
 
     // try to deactivate on child
     try {
-      ruleActivator.deactivate(ActiveRuleKey.of(XOO_P2_KEY, RuleTesting.XOO_X1));
+      ruleActivator.deactivate(ActiveRuleKey.of(XOO_P2_KEY, XOO_X1));
       fail();
     } catch (BadRequestException e) {
       assertThat(e).hasMessage("Cannot deactivate inherited rule 'xoo:x1'");
@@ -758,29 +790,29 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on root profile
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
 
     // override
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.INFO);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(INFO);
     activation.setParameter("max", "10");
     activate(activation, XOO_P2_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "10"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "10"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, INFO, OVERRIDES, ImmutableMap.of("max", "10"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "10"));
 
     // reset -> remove overridden values
-    activation = new RuleActivation(RuleTesting.XOO_X1).setReset(true);
+    activation = new RuleActivation(XOO_X1).setReset(true);
     activate(activation, XOO_P2_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
   }
 
   @Test
@@ -788,44 +820,44 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate on root profile
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.BLOCKER);
+    RuleActivation activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(BLOCKER);
     activation.setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
 
     // override on child
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.INFO);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(INFO);
     activation.setParameter("max", "10");
     activate(activation, XOO_P2_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "10"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "10"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, INFO, OVERRIDES, ImmutableMap.of("max", "10"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, INFO, INHERITED, ImmutableMap.of("max", "10"));
 
     // override on grand child
-    activation = new RuleActivation(RuleTesting.XOO_X1);
-    activation.setSeverity(Severity.MINOR);
+    activation = new RuleActivation(XOO_X1);
+    activation.setSeverity(MINOR);
     activation.setParameter("max", "20");
     activate(activation, XOO_P3_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.INFO, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "10"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.MINOR, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "20"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, INFO, OVERRIDES, ImmutableMap.of("max", "10"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, MINOR, OVERRIDES, ImmutableMap.of("max", "20"));
 
     // reset child P2 -> keep the overridden grand-child P3
-    activation = new RuleActivation(RuleTesting.XOO_X1).setReset(true);
+    activation = new RuleActivation(XOO_X1).setReset(true);
     activate(activation, XOO_P2_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyOneActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.MINOR, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "20"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
+    verifyOneActiveRuleInDb(XOO_P3_KEY, XOO_X1, MINOR, OVERRIDES, ImmutableMap.of("max", "20"));
   }
 
   @Test
   public void ignore_reset_if_not_activated() {
     createChildProfiles();
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1).setReset(true);
+    RuleActivation activation = new RuleActivation(XOO_X1).setReset(true);
     activate(activation, XOO_P1_KEY);
 
     verifyZeroActiveRules(XOO_P1_KEY);
@@ -837,14 +869,15 @@ public class RuleActivatorMediumTest {
     // Generate more rules than the search's max limit
     int bulkSize = QueryContext.MAX_LIMIT + 10;
     for (int i = 0; i < bulkSize; i++) {
-      db.deprecatedRuleDao().insert(dbSession, RuleTesting.newDto(RuleKey.of("bulk", "r_" + i)).setLanguage("xoo"));
+      db.ruleDao().insert(dbSession, newDto(RuleKey.of("bulk", "r_" + i)).setLanguage("xoo"));
     }
     dbSession.commit();
+    ruleIndexer.index();
 
     // 0. No active rules so far (base case) and plenty rules available
     verifyZeroActiveRules(XOO_P1_KEY);
-    assertThat(tester.get(RuleIndex.class)
-      .search(new RuleQuery().setRepositories(Arrays.asList("bulk")), new QueryContext(userSessionRule)).getTotal())
+    assertThat(tester.get(RuleIndex2.class)
+      .search(new RuleQuery().setRepositories(Arrays.asList("bulk")), new SearchOptions()).getTotal())
       .isEqualTo(bulkSize);
 
     // 1. bulk activate all the rules
@@ -853,8 +886,8 @@ public class RuleActivatorMediumTest {
 
     // 2. assert that all activation has been commit to DB and ES
     dbSession.clearCache();
-    assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(bulkSize);
-    assertThat(index.findByProfile(XOO_P1_KEY)).hasSize(bulkSize);
+    assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(bulkSize);
+    assertThat(activeRuleIndex.findByProfile(XOO_P1_KEY)).hasSize(bulkSize);
     assertThat(result.countSucceeded()).isEqualTo(bulkSize);
     assertThat(result.countFailed()).isEqualTo(0);
   }
@@ -867,24 +900,23 @@ public class RuleActivatorMediumTest {
     // 2. assert that all activations have been commit to DB and ES
     // -> xoo rules x1, x2 and custom1
     dbSession.clearCache();
-    assertThat(db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(3);
-    assertThat(index.findByProfile(XOO_P1_KEY)).hasSize(3);
+    assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(3);
+    assertThat(activeRuleIndex.findByProfile(XOO_P1_KEY)).hasSize(3);
     assertThat(result.countSucceeded()).isEqualTo(3);
     assertThat(result.countFailed()).isGreaterThan(0);
-
   }
 
   @Test
   public void set_and_unset_parent_profile() {
     // x1 is activated on the "future parent" P1
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
+    RuleActivation activation = new RuleActivation(XOO_X1);
     activation.setSeverity("MAJOR");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.MAJOR, null, ImmutableMap.of("max", "10"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, MAJOR, null, ImmutableMap.of("max", "10"));
 
     // create profile P2 with x2
     db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2());
-    activation = new RuleActivation(RuleTesting.XOO_X2);
+    activation = new RuleActivation(XOO_X2);
     activation.setSeverity("MAJOR");
     activate(activation, XOO_P2_KEY);
 
@@ -892,15 +924,16 @@ public class RuleActivatorMediumTest {
     ruleActivator.setParent(XOO_P2_KEY, XOO_P1_KEY);
     dbSession.clearCache();
     assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P2_KEY).getParentKee()).isEqualTo(XOO_P1_KEY);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P2_KEY, RuleTesting.XOO_X1), Severity.MAJOR, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "10"));
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P2_KEY, RuleTesting.XOO_X2), Severity.MAJOR, null, Collections.<String, String>emptyMap());
+
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P2_KEY, XOO_X1), MAJOR, INHERITED, ImmutableMap.of("max", "10"));
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P2_KEY, XOO_X2), MAJOR, null, Collections.<String, String>emptyMap());
 
     // unset parent
     dbSession.clearCache();
     ruleActivator.setParent(XOO_P2_KEY, null);
     assertThat(countActiveRules(XOO_P2_KEY)).isEqualTo(1);
     assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P2_KEY).getParentKee()).isNull();
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P2_KEY, RuleTesting.XOO_X2), Severity.MAJOR, null, Collections.<String, String>emptyMap());
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P2_KEY, XOO_X2), MAJOR, null, Collections.<String, String>emptyMap());
   }
 
   @Test
@@ -925,10 +958,10 @@ public class RuleActivatorMediumTest {
   @Test
   public void keep_overridden_rules_when_unsetting_parent() {
     // x1 is activated on the "future parent"
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
+    RuleActivation activation = new RuleActivation(XOO_X1);
     activation.setSeverity("MAJOR");
     activate(activation, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.MAJOR, null, ImmutableMap.of("max", "10"));
+    verifyOneActiveRuleInDb(XOO_P1_KEY, XOO_X1, MAJOR, null, ImmutableMap.of("max", "10"));
 
     // create empty profile P2
     db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2());
@@ -937,36 +970,36 @@ public class RuleActivatorMediumTest {
 
     // set parent -> child profile inherits rule x1
     ruleActivator.setParent(XOO_P2_KEY, XOO_P1_KEY);
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.MAJOR, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "10"));
+    verifyOneActiveRuleInDbAndIndex(XOO_P2_KEY, XOO_X1, MAJOR, INHERITED, ImmutableMap.of("max", "10"));
 
     // override x1
-    activation = new RuleActivation(RuleTesting.XOO_X1);
+    activation = new RuleActivation(XOO_X1);
     activation.setSeverity("BLOCKER").setParameter("max", "333");
     activate(activation, XOO_P2_KEY);
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "333"));
+    verifyOneActiveRuleInDb(XOO_P2_KEY, XOO_X1, BLOCKER, OVERRIDES, ImmutableMap.of("max", "333"));
 
     // unset parent -> keep x1
     ruleActivator.setParent(XOO_P2_KEY, null);
     dbSession.clearCache();
     assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P2_KEY).getParentKee()).isNull();
-    verifyOneActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "333"));
+    verifyOneActiveRuleInDbAndIndex(XOO_P2_KEY, XOO_X1, BLOCKER, null, ImmutableMap.of("max", "333"));
   }
 
   @Test
   public void ignore_activation_errors_when_setting_parent() {
     // x1 and x2 are activated on the "future parent" P1
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1).setSeverity("MAJOR");
+    RuleActivation activation = new RuleActivation(XOO_X1).setSeverity("MAJOR");
     activate(activation, XOO_P1_KEY);
-    activation = new RuleActivation(RuleTesting.XOO_X2).setSeverity("MAJOR");
+    activation = new RuleActivation(XOO_X2).setSeverity("MAJOR");
     activate(activation, XOO_P1_KEY);
 
     // create profile P2
     db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2());
 
     // mark rule x1 as REMOVED
-    RuleDto rule = db.deprecatedRuleDao().getByKey(dbSession, RuleTesting.XOO_X1);
+    RuleDto rule = db.ruleDao().selectOrFailByKey(dbSession, XOO_X1);
     rule.setStatus(RuleStatus.REMOVED);
-    db.deprecatedRuleDao().update(dbSession, rule);
+    db.ruleDao().update(dbSession, rule);
     dbSession.commit();
     dbSession.clearCache();
 
@@ -976,13 +1009,13 @@ public class RuleActivatorMediumTest {
 
     assertThat(db.qualityProfileDao().selectByKey(dbSession, XOO_P2_KEY).getParentKee()).isEqualTo(XOO_P1_KEY);
     assertThat(countActiveRules(XOO_P2_KEY)).isEqualTo(1);
-    verifyHasActiveRule(ActiveRuleKey.of(XOO_P2_KEY, RuleTesting.XOO_X2), Severity.MAJOR, ActiveRuleDto.INHERITED, Collections.<String, String>emptyMap());
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P2_KEY, XOO_X2), MAJOR, INHERITED, Collections.<String, String>emptyMap());
   }
 
   @Test
   public void bulk_deactivate() {
-    activate(new RuleActivation(RuleTesting.XOO_X1), XOO_P1_KEY);
-    activate(new RuleActivation(RuleTesting.XOO_X2), XOO_P1_KEY);
+    activate(new RuleActivation(XOO_X1), XOO_P1_KEY);
+    activate(new RuleActivation(XOO_X2), XOO_P1_KEY);
     assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(2);
 
     BulkChangeResult result = ruleActivator.bulkDeactivate(new RuleQuery().setActivation(true).setQProfileKey(XOO_P1_KEY), XOO_P1_KEY);
@@ -998,7 +1031,7 @@ public class RuleActivatorMediumTest {
   public void bulk_deactivation_ignores_errors() {
     // activate on parent profile P1
     createChildProfiles();
-    activate(new RuleActivation(RuleTesting.XOO_X1), XOO_P1_KEY);
+    activate(new RuleActivation(XOO_X1), XOO_P1_KEY);
     assertThat(countActiveRules(XOO_P2_KEY)).isEqualTo(1);
 
     // bulk deactivate on child profile P2 -> not possible
@@ -1016,9 +1049,9 @@ public class RuleActivatorMediumTest {
     createChildProfiles();
 
     // activate two rules on root profile P1 (propagated to P2 and P3)
-    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1).setSeverity(Severity.INFO).setParameter("max", "7");
+    RuleActivation activation = new RuleActivation(XOO_X1).setSeverity(INFO).setParameter("max", "7");
     activate(activation, XOO_P1_KEY);
-    activation = new RuleActivation(RuleTesting.XOO_X2).setSeverity(Severity.INFO);
+    activation = new RuleActivation(XOO_X2).setSeverity(INFO);
     activate(activation, XOO_P1_KEY);
 
     // bulk change severity to BLOCKER. Parameters are not set.
@@ -1026,81 +1059,83 @@ public class RuleActivatorMediumTest {
     BulkChangeResult result = ruleActivator.bulkActivate(query, XOO_P1_KEY, "BLOCKER");
     assertThat(result.countSucceeded()).isEqualTo(2);
 
-    verifyHasActiveRule(XOO_P1_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, null, ImmutableMap.of("max", "7"));
-    verifyHasActiveRule(XOO_P1_KEY, RuleTesting.XOO_X2, Severity.BLOCKER, null, Collections.<String, String>emptyMap());
-    verifyHasActiveRule(XOO_P2_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyHasActiveRule(XOO_P2_KEY, RuleTesting.XOO_X2, Severity.BLOCKER, ActiveRuleDto.INHERITED, Collections.<String, String>emptyMap());
-    verifyHasActiveRule(XOO_P3_KEY, RuleTesting.XOO_X1, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
-    verifyHasActiveRule(XOO_P3_KEY, RuleTesting.XOO_X2, Severity.BLOCKER, ActiveRuleDto.INHERITED, Collections.<String, String>emptyMap());
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P1_KEY, XOO_X1), BLOCKER, null, ImmutableMap.of("max", "7"));
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P1_KEY, XOO_X2), BLOCKER, null, Collections.<String, String>emptyMap());
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P2_KEY, XOO_X1), BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P2_KEY, XOO_X2), BLOCKER, INHERITED, Collections.<String, String>emptyMap());
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P3_KEY, XOO_X1), BLOCKER, INHERITED, ImmutableMap.of("max", "7"));
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(XOO_P3_KEY, XOO_X2), BLOCKER, INHERITED, Collections.<String, String>emptyMap());
   }
 
   private int countActiveRules(String profileKey) {
-    List<ActiveRuleDto> activeRuleDtos = db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, profileKey);
-    List<ActiveRule> activeRules = Lists.newArrayList(index.findByProfile(profileKey));
-    assertThat(activeRuleDtos.size()).as("Not same active rules between db and index").isEqualTo(activeRules.size());
+    List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().selectByProfileKey(dbSession, profileKey);
     return activeRuleDtos.size();
   }
 
-  private void verifyOneActiveRule(String profileKey, RuleKey ruleKey, String expectedSeverity,
+  private void verifyOneActiveRuleInDb(String profileKey, RuleKey ruleKey, String expectedSeverity,
     @Nullable String expectedInheritance, Map<String, String> expectedParams) {
     assertThat(countActiveRules(profileKey)).isEqualTo(1);
-    verifyHasActiveRule(profileKey, ruleKey, expectedSeverity, expectedInheritance, expectedParams);
+    verifyHasActiveRuleInDb(ActiveRuleKey.of(profileKey, ruleKey), expectedSeverity, expectedInheritance, expectedParams);
   }
 
-  private void verifyHasActiveRule(String profileKey, RuleKey ruleKey, String expectedSeverity,
+  private void verifyOneActiveRuleInDbAndIndex(String profileKey, RuleKey ruleKey, String expectedSeverity,
     @Nullable String expectedInheritance, Map<String, String> expectedParams) {
-    verifyHasActiveRule(ActiveRuleKey.of(profileKey, ruleKey), expectedSeverity, expectedInheritance, expectedParams);
+    assertThat(countActiveRules(profileKey)).isEqualTo(1);
+    verifyHasActiveRuleInDbAndIndex(ActiveRuleKey.of(profileKey, ruleKey), expectedSeverity, expectedInheritance, expectedParams);
   }
 
-  private void verifyHasActiveRule(ActiveRuleKey activeRuleKey, String expectedSeverity,
+  private void verifyHasActiveRuleInDb(ActiveRuleKey activeRuleKey, String expectedSeverity,
     @Nullable String expectedInheritance, Map<String, String> expectedParams) {
     // verify db
     boolean found = false;
-    List<ActiveRuleDto> activeRuleDtos = db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, activeRuleKey.qProfile());
+    List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().selectByProfileKey(dbSession, activeRuleKey.qProfile());
     for (ActiveRuleDto activeRuleDto : activeRuleDtos) {
       if (activeRuleDto.getKey().equals(activeRuleKey)) {
         found = true;
         assertThat(activeRuleDto.getSeverityString()).isEqualTo(expectedSeverity);
         assertThat(activeRuleDto.getInheritance()).isEqualTo(expectedInheritance);
         // Dates should be set
-        assertThat(activeRuleDto.getCreatedAt()).isNotNull();
-        assertThat(activeRuleDto.getUpdatedAt()).isNotNull();
+        assertThat(activeRuleDto.getCreatedAtInMs()).isNotNull();
+        assertThat(activeRuleDto.getUpdatedAtInMs()).isNotNull();
 
-        List<ActiveRuleParamDto> paramDtos = db.deprecatedActiveRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey());
+        List<ActiveRuleParamDto> paramDtos = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey());
         assertThat(paramDtos).hasSize(expectedParams.size());
         for (Map.Entry<String, String> entry : expectedParams.entrySet()) {
-          ActiveRuleParamDto paramDto = db.deprecatedActiveRuleDao().selectParamByKeyAndName(activeRuleDto.getKey(), entry.getKey(), dbSession);
+          ActiveRuleParamDto paramDto = db.activeRuleDao().selectParamByKeyAndName(activeRuleDto.getKey(), entry.getKey(), dbSession);
           assertThat(paramDto).isNotNull();
           assertThat(paramDto.getValue()).isEqualTo(entry.getValue());
         }
       }
     }
     assertThat(found).as("Rule is not activated in db").isTrue();
+  }
 
+  private void verifyHasActiveRuleInIndex(ActiveRuleKey activeRuleKey, String expectedSeverity,
+    @Nullable String expectedInheritance) {
     // verify es
-    List<ActiveRule> activeRules = Lists.newArrayList(index.findByProfile(activeRuleKey.qProfile()));
-    found = false;
-    for (ActiveRule activeRule : activeRules) {
+    List<ActiveRuleDoc> activeRules = Lists.newArrayList(activeRuleIndex.findByProfile(activeRuleKey.qProfile()));
+    boolean found = false;
+    for (ActiveRuleDoc activeRule : activeRules) {
       if (activeRule.key().equals(activeRuleKey)) {
         found = true;
         assertThat(activeRule.severity()).isEqualTo(expectedSeverity);
-        assertThat(activeRule.inheritance()).isEqualTo(expectedInheritance == null ? ActiveRule.Inheritance.NONE : ActiveRule.Inheritance.valueOf(expectedInheritance));
+        assertThat(activeRule.inheritance()).isEqualTo(expectedInheritance == null ? ActiveRule.Inheritance.NONE :
+          ActiveRule.Inheritance.valueOf(expectedInheritance));
 
         // Dates should be set
-        assertThat(activeRule.createdAt()).isNotNull();
-        assertThat(activeRule.updatedAt()).isNotNull();
-
-        // verify parameters in es
-        assertThat(activeRule.params()).hasSize(expectedParams.size());
-        for (Map.Entry<String, String> entry : expectedParams.entrySet()) {
-          String value = activeRule.params().get(entry.getKey());
-          assertThat(value).isEqualTo(entry.getValue());
-        }
+        assertThat(activeRule.createdAtAsLong()).isNotNull();
+        assertThat(activeRule.updatedAtAsLong()).isNotNull();
       }
     }
     assertThat(found).as("Rule is not activated in index").isTrue();
   }
 
+  private void verifyHasActiveRuleInDbAndIndex(ActiveRuleKey activeRuleKey, String expectedSeverity,
+    @Nullable String expectedInheritance, Map<String, String> expectedParams) {
+    verifyHasActiveRuleInDb(activeRuleKey, expectedSeverity, expectedInheritance, expectedParams);
+    verifyHasActiveRuleInIndex(activeRuleKey, expectedSeverity, expectedInheritance);
+  }
+
   private void createChildProfiles() {
     db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP2().setParentKee(XOO_P1_KEY));
     db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP3().setParentKee(XOO_P2_KEY));
@@ -1111,17 +1146,18 @@ public class RuleActivatorMediumTest {
     List<ActiveRuleChange> changes = ruleActivator.activate(dbSession, activation, profileKey);
     dbSession.commit();
     dbSession.clearCache();
+    activeRuleIndexer.index(changes);
     return changes;
   }
 
   private void verifyZeroActiveRules(String key) {
     // verify db
     dbSession.clearCache();
-    List<ActiveRuleDto> activeRuleDtos = db.deprecatedActiveRuleDao().selectByProfileKey(dbSession, key);
+    List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().selectByProfileKey(dbSession, key);
     assertThat(activeRuleDtos).isEmpty();
 
     // verify es
-    List<ActiveRule> activeRules = Lists.newArrayList(index.findByProfile(key));
+    List<ActiveRuleDoc> activeRules = Lists.newArrayList(activeRuleIndex.findByProfile(key));
     assertThat(activeRules).isEmpty();
   }
 }