]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10357 add ruleId to RuleActivation
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 30 Jan 2018 16:09:38 +0000 (17:09 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 8 Feb 2018 12:41:00 +0000 (13:41 +0100)
16 files changed:
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImpl.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRulesImpl.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivation.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperImplTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileResetImplTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java

index 04b83baa134cb5a4edcd0e77d6902fcdd59d14b3..9e77286eaab92db5b63e2039c5fd1f319d70051a 100644 (file)
@@ -21,10 +21,10 @@ package org.sonar.server.qualityprofile;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Stream;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
 import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInActiveRule;
@@ -33,8 +33,11 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.RulesProfileDto;
+import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
 
+import static org.sonar.core.util.stream.MoreCollectors.toSet;
+
 public class BuiltInQProfileUpdateImpl implements BuiltInQProfileUpdate {
 
   private final DbClient dbClient;
@@ -54,17 +57,19 @@ public class BuiltInQProfileUpdateImpl implements BuiltInQProfileUpdate {
       .map(ActiveRuleDto::getRuleKey)
       .collect(MoreCollectors.toHashSet());
 
+    Set<RuleKey> ruleKeys = Stream.concat(
+      deactivatedKeys.stream(),
+      builtIn.getActiveRules().stream().map(ar -> RuleKey.of(ar.repoKey(), ar.ruleKey())))
+      .collect(toSet());
+    RuleActivationContext context = ruleActivator.createContextForBuiltInProfile(dbSession, rulesProfile, ruleKeys);
+
     Collection<RuleActivation> activations = new ArrayList<>();
-    Collection<RuleKey> ruleKeys = new HashSet<>(deactivatedKeys);
     for (BuiltInActiveRule ar : builtIn.getActiveRules()) {
-      RuleActivation activation = convert(ar);
+      RuleActivation activation = convert(ar, context);
       activations.add(activation);
-      ruleKeys.add(activation.getRuleKey());
       deactivatedKeys.remove(activation.getRuleKey());
     }
 
-    RuleActivationContext context = ruleActivator.createContextForBuiltInProfile(dbSession, rulesProfile, ruleKeys);
-
     List<ActiveRuleChange> changes = new ArrayList<>();
     for (RuleActivation activation : activations) {
       changes.addAll(ruleActivator.activate(dbSession, activation, context));
@@ -77,10 +82,13 @@ public class BuiltInQProfileUpdateImpl implements BuiltInQProfileUpdate {
     return changes;
   }
 
-  private static RuleActivation convert(BuiltInActiveRule ar) {
+  private static RuleActivation convert(BuiltInActiveRule ar, RuleActivationContext context) {
+    RuleKey ruleKey = RuleKey.of(ar.repoKey(), ar.ruleKey());
+    context.reset(ruleKey);
+    RuleDefinitionDto ruleDefinition = context.getRule().get();
     Map<String, String> params = ar.overriddenParams().stream()
       .collect(MoreCollectors.uniqueIndex(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue));
-    return RuleActivation.create(RuleKey.of(ar.repoKey(), ar.ruleKey()), ar.overriddenSeverity(), params);
+    return RuleActivation.create(ruleDefinition.getId(), ruleKey, ar.overriddenSeverity(), params);
   }
 
 }
index dff9e728e1eca1863fabe334acbcde4840c03c05..14e80f6812dc0dcda7a199603652870e5311acb8 100644 (file)
@@ -30,6 +30,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.function.Function;
 import javax.annotation.Nullable;
@@ -43,6 +44,7 @@ import org.codehaus.staxmate.in.SMInputCursor;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.text.XmlWriter;
+import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.organization.OrganizationDto;
@@ -50,6 +52,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.ActiveRuleParamDto;
 import org.sonar.db.qualityprofile.OrgActiveRuleDto;
 import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.rule.RuleDefinitionDto;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
@@ -140,7 +143,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
     try {
       String profileLang = null;
       String profileName = null;
-      List<RuleActivation> ruleActivations = Lists.newArrayList();
+      List<Rule> rules = Lists.newArrayList();
       SMInputFactory inputFactory = initStax();
       SMHierarchicCursor rootC = inputFactory.rootElementCursor(backup);
       rootC.advance(); // <profile>
@@ -158,12 +161,13 @@ public class QProfileBackuperImpl implements QProfileBackuper {
 
         } else if (StringUtils.equals(ATTRIBUTE_RULES, nodeName)) {
           SMInputCursor rulesCursor = cursor.childElementCursor("rule");
-          ruleActivations = parseRuleActivations(rulesCursor);
+          rules = parseRuleActivations(rulesCursor);
         }
       }
 
       QProfileName targetName = new QProfileName(profileLang, profileName);
       QProfileDto targetProfile = profileLoader.apply(targetName);
+      List<RuleActivation> ruleActivations = toRuleActivations(dbSession, rules);
       BulkChangeResult changes = profileReset.reset(dbSession, targetProfile, ruleActivations);
       return new QProfileRestoreSummary(targetProfile, changes);
     } catch (XMLStreamException e) {
@@ -171,8 +175,40 @@ public class QProfileBackuperImpl implements QProfileBackuper {
     }
   }
 
-  private static List<RuleActivation> parseRuleActivations(SMInputCursor rulesCursor) throws XMLStreamException {
-    List<RuleActivation> activations = new ArrayList<>();
+  private List<RuleActivation> toRuleActivations(DbSession dbSession, List<Rule> rules) {
+    List<RuleKey> ruleKeys = rules.stream()
+      .map(r -> r.ruleKey)
+      .collect(MoreCollectors.toList());
+    Map<RuleKey, RuleDefinitionDto> ruleDefinitionsByKey = db.ruleDao().selectDefinitionByKeys(dbSession, ruleKeys)
+      .stream()
+      .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getKey));
+
+    return rules.stream()
+      .map(r -> {
+        RuleDefinitionDto ruleDefinition = ruleDefinitionsByKey.get(r.ruleKey);
+        if (ruleDefinition == null) {
+          return null;
+        }
+        return RuleActivation.create(ruleDefinition.getId(), ruleDefinition.getKey(), r.severity, r.parameters);
+      })
+      .filter(Objects::nonNull)
+      .collect(MoreCollectors.toList(rules.size()));
+  }
+
+  private static final class Rule {
+    private final RuleKey ruleKey;
+    private final String severity;
+    private final Map<String, String> parameters;
+
+    private Rule(RuleKey ruleKey, String severity, Map<String, String> parameters) {
+      this.ruleKey = ruleKey;
+      this.severity = severity;
+      this.parameters = parameters;
+    }
+  }
+
+  private static List<Rule> parseRuleActivations(SMInputCursor rulesCursor) throws XMLStreamException {
+    List<Rule> activations = new ArrayList<>();
     Set<RuleKey> activatedKeys = new HashSet<>();
     List<RuleKey> duplicatedKeys = new ArrayList<>();
     while (rulesCursor.getNext() != null) {
@@ -202,7 +238,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
         duplicatedKeys.add(ruleKey);
       }
       activatedKeys.add(ruleKey);
-      activations.add(RuleActivation.create(ruleKey, severity, parameters));
+      activations.add(new Rule(ruleKey, severity, parameters));
     }
     if (!duplicatedKeys.isEmpty()) {
       throw new IllegalArgumentException("The quality profile cannot be restored as it contains duplicates for the following rules: " +
index 3cbaa9f121c35b1341656627e91f9f2b891b6266..11ccb29d71f9716358bd3d76a4b3ed36e6a92489 100644 (file)
@@ -30,6 +30,8 @@ import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
+import javax.annotation.CheckForNull;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.profiles.ProfileExporter;
@@ -50,6 +52,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto;
 import org.sonar.db.qualityprofile.ActiveRuleParamDto;
 import org.sonar.db.qualityprofile.OrgActiveRuleDto;
 import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.NotFoundException;
 
@@ -156,9 +159,13 @@ public class QProfileExporters {
   }
 
   private List<ActiveRuleChange> importProfile(QProfileDto profile, RulesProfile definition, DbSession dbSession) {
+    Map<RuleKey, RuleDefinitionDto> rulesByRuleKey = dbClient.ruleDao().selectAllDefinitions(dbSession)
+      .stream()
+      .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getKey));
     List<ActiveRule> activeRules = definition.getActiveRules();
     List<RuleActivation> activations = activeRules.stream()
-      .map(QProfileExporters::toRuleActivation)
+      .map(activeRule -> toRuleActivation(activeRule, rulesByRuleKey))
+      .filter(Objects::nonNull)
       .collect(MoreCollectors.toArrayList(activeRules.size()));
     return qProfileRules.activateAndCommit(dbSession, profile, activations);
   }
@@ -178,12 +185,17 @@ public class QProfileExporters {
     result.addInfos(messages.getInfos());
   }
 
-  private static RuleActivation toRuleActivation(ActiveRule activeRule) {
+  @CheckForNull
+  private static RuleActivation toRuleActivation(ActiveRule activeRule, Map<RuleKey, RuleDefinitionDto> rulesByRuleKey) {
     RuleKey ruleKey = activeRule.getRule().ruleKey();
+    RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey);
+    if (ruleDefinition == null) {
+      return null;
+    }
     String severity = activeRule.getSeverity().name();
     Map<String, String> params = activeRule.getActiveRuleParams().stream()
       .collect(MoreCollectors.uniqueIndex(ActiveRuleParam::getKey, ActiveRuleParam::getValue));
-    return RuleActivation.create(ruleKey, severity, params);
+    return RuleActivation.create(ruleDefinition.getId(), ruleKey, severity, params);
   }
 
 }
index 554db53075da4105c0c55dc15dd8dc6d9100baf2..b082c30d1bccd61271d38f507acdc3c002f85547 100644 (file)
@@ -71,8 +71,8 @@ public class QProfileRulesImpl implements QProfileRules {
   @Override
   public BulkChangeResult bulkActivateAndCommit(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery, @Nullable String severity) {
     verifyNotBuiltIn(profile);
-    return doBulk(dbSession, profile, ruleQuery, (context, ruleKey) -> {
-      RuleActivation activation = RuleActivation.create(ruleKey, severity, null);
+    return doBulk(dbSession, profile, ruleQuery, (context, ruleDefinition) -> {
+      RuleActivation activation = RuleActivation.create(ruleDefinition.getId(), ruleDefinition.getKey(), severity, null);
       return ruleActivator.activate(dbSession, activation, context);
     });
   }
@@ -93,7 +93,7 @@ public class QProfileRulesImpl implements QProfileRules {
   @Override
   public BulkChangeResult bulkDeactivateAndCommit(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery) {
     verifyNotBuiltIn(profile);
-    return doBulk(dbSession, profile, ruleQuery, (context, ruleKey) -> ruleActivator.deactivate(dbSession, context, ruleKey, false));
+    return doBulk(dbSession, profile, ruleQuery, (context, ruleDefinition) -> ruleActivator.deactivate(dbSession, context, ruleDefinition.getKey(), false));
   }
 
   @Override
@@ -115,14 +115,16 @@ public class QProfileRulesImpl implements QProfileRules {
     checkArgument(!profile.isBuiltIn(), "The built-in profile %s is read-only and can't be updated", profile.getName());
   }
 
-  private BulkChangeResult doBulk(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery, BiFunction<RuleActivationContext, RuleKey, List<ActiveRuleChange>> fn) {
+  private BulkChangeResult doBulk(DbSession dbSession, QProfileDto profile, RuleQuery ruleQuery, BiFunction<RuleActivationContext, RuleDefinitionDto, List<ActiveRuleChange>> fn) {
     BulkChangeResult result = new BulkChangeResult();
     Collection<RuleKey> ruleKeys = Sets.newHashSet(ruleIndex.searchAll(ruleQuery));
     RuleActivationContext context = ruleActivator.createContextForUserProfile(dbSession, profile, ruleKeys);
 
     for (RuleKey ruleKey : ruleKeys) {
       try {
-        List<ActiveRuleChange> changes = fn.apply(context, ruleKey);
+        context.reset(ruleKey);
+        RuleDefinitionDto ruleDefinition = context.getRule().get();
+        List<ActiveRuleChange> changes = fn.apply(context, ruleDefinition);
         result.addChanges(changes);
         if (!changes.isEmpty()) {
           result.incrementSucceeded();
index 09f346c03b87031baac58a0e1d264825909e3aa3..1549b74e83401b9387fd1bc81e65324e92324e2e 100644 (file)
@@ -86,7 +86,7 @@ public class QProfileTreeImpl implements QProfileTree {
 
     for (ActiveRuleDto parentActiveRule : parentActiveRules) {
       try {
-        RuleActivation activation = RuleActivation.create(parentActiveRule.getRuleKey(), null, null);
+        RuleActivation activation = RuleActivation.create(parentActiveRule.getRuleId(), parentActiveRule.getRuleKey(), null, null);
         changes.addAll(ruleActivator.activate(dbSession, activation, context));
       } catch (BadRequestException e) {
         // for example because rule status is REMOVED
index bede1be50bd0e3fa08e884469d0d66402d50ac0a..fba67f21db7dc57da9d8b8fa3ee827d0d2ff5d9f 100644 (file)
@@ -35,11 +35,13 @@ import org.sonar.api.rule.Severity;
 public class RuleActivation {
 
   private final RuleKey ruleKey;
+  private final int ruleId;
   private final boolean reset;
   private final String severity;
   private final Map<String, String> parameters = new HashMap<>();
 
-  private RuleActivation(RuleKey ruleKey, boolean reset, @Nullable String severity, @Nullable Map<String, String> parameters) {
+  private RuleActivation(int ruleId, RuleKey ruleKey, boolean reset, @Nullable String severity, @Nullable Map<String, String> parameters) {
+    this.ruleId = ruleId;
     this.ruleKey = ruleKey;
     this.reset = reset;
     this.severity = severity;
@@ -53,16 +55,16 @@ public class RuleActivation {
     }
   }
 
-  public static RuleActivation createReset(RuleKey ruleKey) {
-    return new RuleActivation(ruleKey, true, null, null);
+  public static RuleActivation createReset(int ruleId, RuleKey ruleKey) {
+    return new RuleActivation(ruleId, ruleKey, true, null, null);
   }
 
-  public static RuleActivation create(RuleKey ruleKey, @Nullable String severity, @Nullable Map<String, String> parameters) {
-    return new RuleActivation(ruleKey, false, severity, parameters);
+  public static RuleActivation create(int ruleId, RuleKey ruleKey, @Nullable String severity, @Nullable Map<String, String> parameters) {
+    return new RuleActivation(ruleId, ruleKey, false, severity, parameters);
   }
 
-  public static RuleActivation create(RuleKey ruleKey) {
-    return create(ruleKey, null, null);
+  public static RuleActivation create(int ruleId, RuleKey ruleKey) {
+    return create(ruleId, ruleKey, null, null);
   }
 
   /**
@@ -73,6 +75,10 @@ public class RuleActivation {
     return severity;
   }
 
+  public int getRuleId() {
+    return ruleId;
+  }
+
   public RuleKey getRuleKey() {
     return ruleKey;
   }
index 1f620be292c26d819c0aba12201fc900fcd456a8..85028f242ef33d44d865b3ab237780d44f4064f3 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.server.qualityprofile.QProfileRules;
 import org.sonar.server.qualityprofile.RuleActivation;
 import org.sonar.server.user.UserSession;
@@ -104,18 +105,20 @@ public class ActivateRuleAction implements QProfileWsAction {
       QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
       OrganizationDto organization = wsSupport.getOrganization(dbSession, profile);
       wsSupport.checkCanEdit(dbSession, organization, profile);
-      RuleActivation activation = readActivation(request);
+      RuleActivation activation = readActivation(dbSession, request);
       ruleActivator.activateAndCommit(dbSession, profile, singletonList(activation));
     }
 
     response.noContent();
   }
 
-  private static RuleActivation readActivation(Request request) {
+  private RuleActivation readActivation(DbSession dbSession, Request request) {
     RuleKey ruleKey = RuleKey.parse(request.mandatoryParam(PARAM_RULE));
+    RuleDefinitionDto ruleDefinition = dbClient.ruleDao().selectDefinitionByKey(dbSession, ruleKey)
+      .orElseThrow(() -> new IllegalArgumentException(format("Rule '%s' not found", ruleKey)));
     boolean reset = Boolean.TRUE.equals(request.paramAsBoolean(PARAM_RESET));
     if (reset) {
-      return RuleActivation.createReset(ruleKey);
+      return RuleActivation.createReset(ruleDefinition.getId(), ruleKey);
     }
     String severity = request.param(PARAM_SEVERITY);
     Map<String, String> params = null;
@@ -123,7 +126,7 @@ public class ActivateRuleAction implements QProfileWsAction {
     if (paramsAsString != null) {
       params = KeyValueFormat.parse(paramsAsString);
     }
-    return RuleActivation.create(ruleKey, severity, params);
+    return RuleActivation.create(ruleDefinition.getId(), ruleKey, severity, params);
   }
 
 }
index 7da0368869d4d9e7ce075a5d1e3660257e83b0a7..3e51539b2f716b23e2da9b505873465c6866d462 100644 (file)
@@ -156,6 +156,7 @@ public class QProfileBackuperImplTest {
 
   @Test
   public void restore_resets_the_activated_rules() {
+    db.rules().insert(RuleKey.of("sonarjs", "s001"));
     OrganizationDto organization = db.organizations().insert();
     Reader backup = new StringReader("<?xml version='1.0' encoding='UTF-8'?>" +
       "<profile><name>foo</name>" +
index dbcb29e488be0c4f221fb7de12a23b545e9b0743..764962d5d9c65a94c3d21c4af0a0d17426686c24 100644 (file)
@@ -115,7 +115,7 @@ public class QProfileComparisonTest {
 
   @Test
   public void compare_same() {
-    RuleActivation commonActivation = RuleActivation.create(xooRule1.getKey(), Severity.CRITICAL,
+    RuleActivation commonActivation = RuleActivation.create(xooRule1.getId(), xooRule1.getKey(), Severity.CRITICAL,
       ImmutableMap.of("min", "7", "max", "42"));
     qProfileRules.activateAndCommit(dbSession, left, singleton(commonActivation));
     qProfileRules.activateAndCommit(dbSession, right, singleton(commonActivation));
@@ -132,7 +132,7 @@ public class QProfileComparisonTest {
 
   @Test
   public void compare_only_left() {
-    RuleActivation activation = RuleActivation.create(xooRule1.getKey());
+    RuleActivation activation = RuleActivation.create(xooRule1.getId(), xooRule1.getKey());
     qProfileRules.activateAndCommit(dbSession, left, singleton(activation));
 
     QProfileComparisonResult result = comparison.compare(dbSession, left, right);
@@ -147,7 +147,7 @@ public class QProfileComparisonTest {
 
   @Test
   public void compare_only_right() {
-    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getKey())));
+    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getId(), xooRule1.getKey())));
 
     QProfileComparisonResult result = comparison.compare(dbSession, left, right);
     assertThat(result.left().getKee()).isEqualTo(left.getKee());
@@ -161,8 +161,8 @@ public class QProfileComparisonTest {
 
   @Test
   public void compare_disjoint() {
-    qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getKey())));
-    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule2.getKey())));
+    qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getId(), xooRule1.getKey())));
+    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule2.getId(), xooRule2.getKey())));
 
     QProfileComparisonResult result = comparison.compare(dbSession, left, right);
     assertThat(result.left().getKee()).isEqualTo(left.getKee());
@@ -176,8 +176,8 @@ public class QProfileComparisonTest {
 
   @Test
   public void compare_modified_severity() {
-    qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getKey(), Severity.CRITICAL, null)));
-    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getKey(), Severity.BLOCKER, null)));
+    qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getId(), xooRule1.getKey(), Severity.CRITICAL, null)));
+    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule2.getId(), xooRule1.getKey(), Severity.BLOCKER, null)));
 
     QProfileComparisonResult result = comparison.compare(dbSession, left, right);
     assertThat(result.left().getKee()).isEqualTo(left.getKee());
@@ -196,8 +196,8 @@ public class QProfileComparisonTest {
 
   @Test
   public void compare_modified_param() {
-    qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getKey(), null, ImmutableMap.of("max", "20"))));
-    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getKey(), null, ImmutableMap.of("max", "30"))));
+    qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getId(), xooRule1.getKey(), null, ImmutableMap.of("max", "20"))));
+    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getId(), xooRule1.getKey(), null, ImmutableMap.of("max", "30"))));
 
     QProfileComparisonResult result = comparison.compare(dbSession, left, right);
     assertThat(result.left().getKee()).isEqualTo(left.getKee());
@@ -219,8 +219,8 @@ public class QProfileComparisonTest {
 
   @Test
   public void compare_different_params() {
-    qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getKey(), null, ImmutableMap.of("max", "20"))));
-    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getKey(), null, ImmutableMap.of("min", "5"))));
+    qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getId(), xooRule1.getKey(), null, ImmutableMap.of("max", "20"))));
+    qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getId(), xooRule1.getKey(), null, ImmutableMap.of("min", "5"))));
 
     QProfileComparisonResult result = comparison.compare(dbSession, left, right);
     assertThat(result.left().getKee()).isEqualTo(left.getKee());
index 130fecf02018417374c198e04b54f9d68974a495..677c7e7c921f01e2303614f349a7c3407bd140b4 100644 (file)
@@ -67,10 +67,10 @@ public class QProfileResetImplTest {
   public void reset() {
     QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE));
     RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
-    qProfileRules.activateAndCommit(db.getSession(), profile, singleton(RuleActivation.create(existingRule.getKey())));
+    qProfileRules.activateAndCommit(db.getSession(), profile, singleton(RuleActivation.create(existingRule.getId(), existingRule.getKey())));
     RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
 
-    BulkChangeResult result = underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(newRule.getKey())));
+    BulkChangeResult result = underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(newRule.getId(), newRule.getKey())));
 
     assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile))
       .extracting(OrgActiveRuleDto::getRuleKey)
@@ -87,11 +87,11 @@ public class QProfileResetImplTest {
     QProfileDto childProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE));
     qProfileTree.setParentAndCommit(db.getSession(), childProfile, parentProfile);
     RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
-    qProfileRules.activateAndCommit(db.getSession(), parentProfile, singleton(RuleActivation.create(existingRule.getKey())));
-    qProfileRules.activateAndCommit(db.getSession(), childProfile, singleton(RuleActivation.create(existingRule.getKey())));
+    qProfileRules.activateAndCommit(db.getSession(), parentProfile, singleton(RuleActivation.create(existingRule.getId(), existingRule.getKey())));
+    qProfileRules.activateAndCommit(db.getSession(), childProfile, singleton(RuleActivation.create(existingRule.getId(), existingRule.getKey())));
     RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
 
-    underTest.reset(db.getSession(), childProfile, singletonList(RuleActivation.create(newRule.getKey())));
+    underTest.reset(db.getSession(), childProfile, singletonList(RuleActivation.create(newRule.getId(), newRule.getKey())));
 
     assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), childProfile))
       .extracting(OrgActiveRuleDto::getRuleKey)
@@ -106,7 +106,7 @@ public class QProfileResetImplTest {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage(String.format("Operation forbidden for built-in Quality Profile '%s'", profile.getKee()));
 
-    underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getKey())));
+    underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getId(), defaultRule.getKey())));
   }
 
   @Test
@@ -117,6 +117,6 @@ public class QProfileResetImplTest {
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("Quality profile must be persisted");
 
-    underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getKey())));
+    underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getId(), defaultRule.getKey())));
   }
 }
index cd562543f93bd2e20148ed691dc091b5ff258da9..e331bc6e4f20a7214f7177258a78f3fe13eb31ce 100644 (file)
@@ -95,7 +95,7 @@ public class QProfileRuleImplTest {
   public void system_activates_rule_without_parameters() {
     RuleDefinitionDto rule = createRule();
     QProfileDto profile = createProfile(rule);
-    RuleActivation activation = RuleActivation.create(rule.getKey(), BLOCKER, null);
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), BLOCKER, null);
     List<ActiveRuleChange> changes = activate(profile, activation);
 
     assertThatRuleIsActivated(profile, rule, changes, BLOCKER, null, emptyMap());
@@ -107,7 +107,7 @@ public class QProfileRuleImplTest {
     userSession.logIn();
     RuleDefinitionDto rule = createRule();
     QProfileDto profile = createProfile(rule);
-    RuleActivation activation = RuleActivation.create(rule.getKey(), BLOCKER, null);
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), BLOCKER, null);
     List<ActiveRuleChange> changes = activate(profile, activation);
 
     assertThatRuleIsActivated(profile, rule, changes, BLOCKER, null, emptyMap());
@@ -120,7 +120,7 @@ public class QProfileRuleImplTest {
     RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10"));
     QProfileDto profile = createProfile(rule);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     List<ActiveRuleChange> changes = activate(profile, activation);
 
     assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, of("min", "10"));
@@ -133,7 +133,7 @@ public class QProfileRuleImplTest {
     RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10"));
     QProfileDto profile = createProfile(rule);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey(), null, of(ruleParam.getName(), "15"));
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), null, of(ruleParam.getName(), "15"));
     List<ActiveRuleChange> changes = activate(profile, activation);
 
     assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, of("min", "15"));
@@ -145,7 +145,7 @@ public class QProfileRuleImplTest {
     RuleDefinitionDto rule = createRule();
     QProfileDto profile = createProfile(rule);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     List<ActiveRuleChange> changes = activate(profile, activation);
 
     assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, emptyMap());
@@ -161,7 +161,7 @@ public class QProfileRuleImplTest {
     RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10"));
     QProfileDto profile = createProfile(rule);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey(), null, of("min", ""));
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), null, of("min", ""));
     List<ActiveRuleChange> changes = activate(profile, activation);
 
     assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, of("min", "10"));
@@ -178,7 +178,7 @@ public class QProfileRuleImplTest {
     RuleParamDto paramWithDefault = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10"));
     QProfileDto profile = createProfile(rule);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey(), null, of(paramWithoutDefault.getName(), "-10"));
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), null, of(paramWithoutDefault.getName(), "-10"));
     List<ActiveRuleChange> changes = activate(profile, activation);
 
     assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null,
@@ -192,7 +192,7 @@ public class QProfileRuleImplTest {
     RuleParamDto param = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10"));
     QProfileDto profile = createProfile(rule);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey(), null, of("xxx", "yyy"));
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), null, of("xxx", "yyy"));
     List<ActiveRuleChange> changes = activate(profile, activation);
 
     assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, of(param.getName(), param.getDefaultValue()));
@@ -206,11 +206,11 @@ public class QProfileRuleImplTest {
     QProfileDto profile = createProfile(rule);
 
     // initial activation
-    RuleActivation activation = RuleActivation.create(rule.getKey(), MAJOR, null);
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), MAJOR, null);
     activate(profile, activation);
 
     // update
-    RuleActivation updateActivation = RuleActivation.create(rule.getKey(), CRITICAL, of(param.getName(), "20"));
+    RuleActivation updateActivation = RuleActivation.create(rule.getId(), rule.getKey(), CRITICAL, of(param.getName(), "20"));
     List<ActiveRuleChange> changes = activate(profile, updateActivation);
 
     assertThatRuleIsUpdated(profile, rule, CRITICAL, null, of(param.getName(), "20"));
@@ -225,11 +225,11 @@ public class QProfileRuleImplTest {
     QProfileDto profile = createProfile(rule);
 
     // initial activation -> param "max" has a default value
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     activate(profile, activation);
 
     // update param "min", which has no default value
-    RuleActivation updateActivation = RuleActivation.create(rule.getKey(), MAJOR, of(paramWithoutDefault.getName(), "3"));
+    RuleActivation updateActivation = RuleActivation.create(rule.getId(), rule.getKey(), MAJOR, of(paramWithoutDefault.getName(), "3"));
     List<ActiveRuleChange> changes = activate(profile, updateActivation);
 
     assertThatRuleIsUpdated(profile, rule, MAJOR, null, of(paramWithDefault.getName(), "10", paramWithoutDefault.getName(), "3"));
@@ -243,11 +243,11 @@ public class QProfileRuleImplTest {
     QProfileDto profile = createProfile(rule);
 
     // initial activation -> param "max" has a default value
-    RuleActivation activation = RuleActivation.create(rule.getKey(), null, of(paramWithDefault.getName(), "20"));
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), null, of(paramWithDefault.getName(), "20"));
     activate(profile, activation);
 
     // reset to default_value
-    RuleActivation updateActivation = RuleActivation.create(rule.getKey(), null, of(paramWithDefault.getName(), ""));
+    RuleActivation updateActivation = RuleActivation.create(rule.getId(), rule.getKey(), null, of(paramWithDefault.getName(), ""));
     List<ActiveRuleChange> changes = activate(profile, updateActivation);
 
     assertThatRuleIsUpdated(profile, rule, rule.getSeverityString(), null, of(paramWithDefault.getName(), "10"));
@@ -262,11 +262,11 @@ public class QProfileRuleImplTest {
     QProfileDto profile = createProfile(rule);
 
     // initial activation -> param "max" has a default value
-    RuleActivation activation = RuleActivation.create(rule.getKey(), null, of(paramWithoutDefault.getName(), "20"));
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), null, of(paramWithoutDefault.getName(), "20"));
     activate(profile, activation);
 
     // remove parameter
-    RuleActivation updateActivation = RuleActivation.create(rule.getKey(), null, of(paramWithoutDefault.getName(), ""));
+    RuleActivation updateActivation = RuleActivation.create(rule.getId(), rule.getKey(), null, of(paramWithoutDefault.getName(), ""));
     List<ActiveRuleChange> changes = activate(profile, updateActivation);
 
     assertThatRuleIsUpdated(profile, rule, rule.getSeverityString(), null, of(paramWithDefault.getName(), paramWithDefault.getDefaultValue()));
@@ -280,13 +280,13 @@ public class QProfileRuleImplTest {
     QProfileDto profile = createProfile(rule);
 
     // initial activation -> param "max" has a default value
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     List<ActiveRuleChange> changes = activate(profile, activation);
     db.getDbClient().activeRuleDao().deleteParametersByRuleProfileUuids(db.getSession(), asList(profile.getRulesProfileUuid()));
     assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, emptyMap());
 
     // contrary to activerule, the param is supposed to be inserted but not updated
-    RuleActivation updateActivation = RuleActivation.create(rule.getKey(), null, of(param.getName(), ""));
+    RuleActivation updateActivation = RuleActivation.create(rule.getId(), rule.getKey(), null, of(param.getName(), ""));
     changes = activate(profile, updateActivation);
 
     assertThatRuleIsUpdated(profile, rule, rule.getSeverityString(), null, of(param.getName(), param.getDefaultValue()));
@@ -299,11 +299,11 @@ public class QProfileRuleImplTest {
     QProfileDto profile = createProfile(rule);
 
     // initial activation
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     activate(profile, activation);
 
     // update with exactly the same severity and params
-    activation = RuleActivation.create(rule.getKey());
+    activation = RuleActivation.create(rule.getId(), rule.getKey());
     List<ActiveRuleChange> changes = activate(profile, activation);
 
     assertThat(changes).isEmpty();
@@ -316,11 +316,11 @@ public class QProfileRuleImplTest {
     QProfileDto profile = createProfile(rule);
 
     // initial activation -> param "max" has a default value
-    RuleActivation activation = RuleActivation.create(rule.getKey(), BLOCKER, of(param.getName(), "20"));
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), BLOCKER, of(param.getName(), "20"));
     activate(profile, activation);
 
     // update without any severity or params => keep
-    RuleActivation update = RuleActivation.create(rule.getKey());
+    RuleActivation update = RuleActivation.create(rule.getId(), rule.getKey());
     List<ActiveRuleChange> changes = activate(profile, update);
 
     assertThat(changes).isEmpty();
@@ -331,7 +331,7 @@ public class QProfileRuleImplTest {
     RuleDefinitionDto rule = createRule();
     QProfileDto profile = createProfile(rule);
     RuleKey ruleKey = RuleKey.parse("unknown:xxx");
-    RuleActivation activation = RuleActivation.create(ruleKey);
+    RuleActivation activation = RuleActivation.create(rule.getId(), ruleKey);
 
     expectFailure("Rule not found: " + ruleKey, () -> activate(profile, activation));
   }
@@ -340,7 +340,7 @@ public class QProfileRuleImplTest {
   public void fail_to_activate_rule_if_profile_is_on_different_languages() {
     RuleDefinitionDto rule = createJavaRule();
     QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage("js"));
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
 
     expectFailure("java rule " + rule.getKey() + " cannot be activated on js profile " + profile.getKee(), () -> activate(profile, activation));
   }
@@ -349,7 +349,7 @@ public class QProfileRuleImplTest {
   public void fail_to_activate_rule_if_rule_has_REMOVED_status() {
     RuleDefinitionDto rule = db.rules().insert(r -> r.setStatus(RuleStatus.REMOVED));
     QProfileDto profile = createProfile(rule);
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
 
     expectFailure("Rule was removed: " + rule.getKey(), () -> activate(profile, activation));
   }
@@ -358,7 +358,7 @@ public class QProfileRuleImplTest {
   public void fail_to_activate_if_template() {
     RuleDefinitionDto rule = db.rules().insert(r -> r.setIsTemplate(true));
     QProfileDto profile = createProfile(rule);
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
 
     expectFailure("Rule template can't be activated on a Quality profile: " + rule.getKey(), () -> activate(profile, activation));
   }
@@ -369,7 +369,7 @@ public class QProfileRuleImplTest {
     RuleParamDto param = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10").setType(PropertyType.INTEGER.name()));
     QProfileDto profile = createProfile(rule);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey(), null, of(param.getName(), "foo"));
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), null, of(param.getName(), "foo"));
     expectFailure("Value 'foo' must be an integer.", () -> activate(profile, activation));
   }
 
@@ -382,12 +382,12 @@ public class QProfileRuleImplTest {
     QProfileDto profile = createProfile(customRule);
 
     // initial activation
-    RuleActivation activation = RuleActivation.create(customRule.getKey(), MAJOR, emptyMap());
+    RuleActivation activation = RuleActivation.create(customRule.getId(), customRule.getKey(), MAJOR, emptyMap());
     activate(profile, activation);
     assertThatRuleIsActivated(profile, customRule, null, MAJOR, null, of("format", "txt"));
 
     // update -> parameter is not changed
-    RuleActivation updateActivation = RuleActivation.create(customRule.getKey(), BLOCKER, of("format", "xml"));
+    RuleActivation updateActivation = RuleActivation.create(customRule.getId(), customRule.getKey(), BLOCKER, of("format", "xml"));
     activate(profile, updateActivation);
     assertThatRuleIsActivated(profile, customRule, null, BLOCKER, null, of("format", "txt"));
   }
@@ -397,7 +397,7 @@ public class QProfileRuleImplTest {
     userSession.logIn();
     RuleDefinitionDto rule = createRule();
     QProfileDto profile = createProfile(rule);
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     activate(profile, activation);
 
     List<ActiveRuleChange> changes = deactivate(profile, rule);
@@ -411,7 +411,7 @@ public class QProfileRuleImplTest {
   public void system_deactivates_a_rule() {
     RuleDefinitionDto rule = createRule();
     QProfileDto profile = createProfile(rule);
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     activate(profile, activation);
 
     List<ActiveRuleChange> changes = deactivate(profile, rule);
@@ -450,7 +450,7 @@ public class QProfileRuleImplTest {
   public void deactivate_rule_that_has_REMOVED_status() {
     RuleDefinitionDto rule = createRule();
     QProfileDto profile = createProfile(rule);
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     activate(profile, activation);
 
     rule.setStatus(RuleStatus.REMOVED);
@@ -468,7 +468,7 @@ public class QProfileRuleImplTest {
     QProfileDto childProfile = createChildProfile(parentProfile);
     QProfileDto grandChildProfile = createChildProfile(childProfile);
 
-    List<ActiveRuleChange> changes = activate(childProfile, RuleActivation.create(rule.getKey()));
+    List<ActiveRuleChange> changes = activate(childProfile, RuleActivation.create(rule.getId(), rule.getKey()));
     assertThatProfileHasNoActiveRules(parentProfile);
     assertThatRuleIsActivated(childProfile, rule, changes, rule.getSeverityString(), null, emptyMap());
     assertThatRuleIsActivated(grandChildProfile, rule, changes, rule.getSeverityString(), INHERITED, emptyMap());
@@ -482,10 +482,10 @@ public class QProfileRuleImplTest {
     QProfileDto childProfile = createChildProfile(parentProfile);
     QProfileDto grandChildProfile = createChildProfile(childProfile);
 
-    RuleActivation initialActivation = RuleActivation.create(rule.getKey(), MAJOR, of(param.getName(), "foo"));
+    RuleActivation initialActivation = RuleActivation.create(rule.getId(), rule.getKey(), MAJOR, of(param.getName(), "foo"));
     activate(childProfile, initialActivation);
 
-    RuleActivation updateActivation = RuleActivation.create(rule.getKey(), CRITICAL, of(param.getName(), "bar"));
+    RuleActivation updateActivation = RuleActivation.create(rule.getId(), rule.getKey(), CRITICAL, of(param.getName(), "bar"));
     List<ActiveRuleChange> changes = activate(childProfile, updateActivation);
 
     assertThatProfileHasNoActiveRules(parentProfile);
@@ -502,10 +502,10 @@ public class QProfileRuleImplTest {
     QProfileDto childProfile = createChildProfile(parentProfile);
     QProfileDto grandChildProfile = createChildProfile(childProfile);
 
-    RuleActivation initialActivation = RuleActivation.create(rule.getKey(), MAJOR, of(param.getName(), "foo"));
+    RuleActivation initialActivation = RuleActivation.create(rule.getId(), rule.getKey(), MAJOR, of(param.getName(), "foo"));
     activate(childProfile, initialActivation);
 
-    RuleActivation overrideActivation = RuleActivation.create(rule.getKey(), CRITICAL, of(param.getName(), "bar"));
+    RuleActivation overrideActivation = RuleActivation.create(rule.getId(), rule.getKey(), CRITICAL, of(param.getName(), "bar"));
     List<ActiveRuleChange> changes = activate(grandChildProfile, overrideActivation);
 
     assertThatProfileHasNoActiveRules(parentProfile);
@@ -522,14 +522,14 @@ public class QProfileRuleImplTest {
     QProfileDto childProfile = createChildProfile(parentProfile);
     QProfileDto grandChildProfile = createChildProfile(childProfile);
 
-    RuleActivation initialActivation = RuleActivation.create(rule.getKey(), MAJOR, of(param.getName(), "foo"));
+    RuleActivation initialActivation = RuleActivation.create(rule.getId(), rule.getKey(), MAJOR, of(param.getName(), "foo"));
     activate(childProfile, initialActivation);
 
-    RuleActivation overrideActivation = RuleActivation.create(rule.getKey(), CRITICAL, of(param.getName(), "bar"));
+    RuleActivation overrideActivation = RuleActivation.create(rule.getId(), rule.getKey(), CRITICAL, of(param.getName(), "bar"));
     activate(grandChildProfile, overrideActivation);
 
     // update child --> do not touch grandChild
-    RuleActivation updateActivation = RuleActivation.create(rule.getKey(), BLOCKER, of(param.getName(), "baz"));
+    RuleActivation updateActivation = RuleActivation.create(rule.getId(), rule.getKey(), BLOCKER, of(param.getName(), "baz"));
     List<ActiveRuleChange> changes = activate(childProfile, updateActivation);
 
     assertThatProfileHasNoActiveRules(parentProfile);
@@ -546,14 +546,14 @@ public class QProfileRuleImplTest {
     QProfileDto childProfile = createChildProfile(parentProfile);
     QProfileDto grandChildProfile = createChildProfile(childProfile);
 
-    RuleActivation initialActivation = RuleActivation.create(rule.getKey(), MAJOR, of(param.getName(), "foo"));
+    RuleActivation initialActivation = RuleActivation.create(rule.getId(), rule.getKey(), MAJOR, of(param.getName(), "foo"));
     activate(parentProfile, initialActivation);
 
-    RuleActivation overrideActivation = RuleActivation.create(rule.getKey(), CRITICAL, of(param.getName(), "bar"));
+    RuleActivation overrideActivation = RuleActivation.create(rule.getId(), rule.getKey(), CRITICAL, of(param.getName(), "bar"));
     activate(grandChildProfile, overrideActivation);
 
     // reset parent --> touch child but not grandChild
-    RuleActivation updateActivation = RuleActivation.createReset(rule.getKey());
+    RuleActivation updateActivation = RuleActivation.createReset(rule.getId(), rule.getKey());
     List<ActiveRuleChange> changes = activate(parentProfile, updateActivation);
 
     assertThatRuleIsUpdated(parentProfile, rule, rule.getSeverityString(), null, of(param.getName(), param.getDefaultValue()));
@@ -569,10 +569,10 @@ public class QProfileRuleImplTest {
     QProfileDto parentProfile = createProfile(rule);
     QProfileDto childProfile = createChildProfile(parentProfile);
 
-    RuleActivation childActivation = RuleActivation.create(rule.getKey(), MAJOR, of(param.getName(), "foo"));
+    RuleActivation childActivation = RuleActivation.create(rule.getId(), rule.getKey(), MAJOR, of(param.getName(), "foo"));
     activate(childProfile, childActivation);
 
-    RuleActivation parentActivation = RuleActivation.create(rule.getKey(), CRITICAL, of(param.getName(), "bar"));
+    RuleActivation parentActivation = RuleActivation.create(rule.getId(), rule.getKey(), CRITICAL, of(param.getName(), "bar"));
     List<ActiveRuleChange> changes = activate(parentProfile, parentActivation);
 
     assertThatRuleIsUpdated(parentProfile, rule, CRITICAL, null, of(param.getName(), "bar"));
@@ -587,10 +587,10 @@ public class QProfileRuleImplTest {
     QProfileDto parentProfile = createProfile(rule);
     QProfileDto childProfile = createChildProfile(parentProfile);
 
-    RuleActivation parentActivation = RuleActivation.create(rule.getKey(), MAJOR, of(param.getName(), "foo"));
+    RuleActivation parentActivation = RuleActivation.create(rule.getId(), rule.getKey(), MAJOR, of(param.getName(), "foo"));
     activate(parentProfile, parentActivation);
 
-    RuleActivation overrideActivation = RuleActivation.create(rule.getKey(), MAJOR, of(param.getName(), "foo"));
+    RuleActivation overrideActivation = RuleActivation.create(rule.getId(), rule.getKey(), MAJOR, of(param.getName(), "foo"));
     List<ActiveRuleChange> changes = activate(childProfile, overrideActivation);
 
     assertThatRuleIsUpdated(childProfile, rule, MAJOR, INHERITED, of(param.getName(), "foo"));
@@ -603,7 +603,7 @@ public class QProfileRuleImplTest {
     QProfileDto parentProfile = createProfile(rule);
     QProfileDto childProfile = createChildProfile(parentProfile);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     List<ActiveRuleChange> changes = activate(parentProfile, activation);
     assertThatRuleIsActivated(parentProfile, rule, changes, rule.getSeverityString(), null, emptyMap());
     assertThatRuleIsActivated(childProfile, rule, changes, rule.getSeverityString(), INHERITED, emptyMap());
@@ -620,12 +620,12 @@ public class QProfileRuleImplTest {
     QProfileDto parentProfile = createProfile(rule);
     QProfileDto childProfile = createChildProfile(parentProfile);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     List<ActiveRuleChange> changes = activate(parentProfile, activation);
     assertThatRuleIsActivated(parentProfile, rule, changes, rule.getSeverityString(), null, emptyMap());
     assertThatRuleIsActivated(childProfile, rule, changes, rule.getSeverityString(), INHERITED, emptyMap());
 
-    activation = RuleActivation.create(rule.getKey(), CRITICAL, null);
+    activation = RuleActivation.create(rule.getId(), rule.getKey(), CRITICAL, null);
     activate(childProfile, activation);
 
     changes = deactivate(parentProfile, rule);
@@ -640,7 +640,7 @@ public class QProfileRuleImplTest {
     QProfileDto parentProfile = createProfile(rule);
     QProfileDto childProfile = createChildProfile(parentProfile);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     List<ActiveRuleChange> changes = activate(parentProfile, activation);
     assertThatRuleIsActivated(parentProfile, rule, changes, rule.getSeverityString(), null, emptyMap());
     assertThatRuleIsActivated(childProfile, rule, changes, rule.getSeverityString(), INHERITED, emptyMap());
@@ -656,18 +656,18 @@ public class QProfileRuleImplTest {
     QProfileDto parentProfile = createProfile(rule);
     QProfileDto childProfile = createChildProfile(parentProfile);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey(), CRITICAL, null);
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), CRITICAL, null);
     List<ActiveRuleChange> changes = activate(parentProfile, activation);
     assertThatRuleIsActivated(parentProfile, rule, changes, CRITICAL, null, emptyMap());
     assertThatRuleIsActivated(childProfile, rule, changes, CRITICAL, INHERITED, emptyMap());
     assertThat(changes).hasSize(2);
 
-    RuleActivation childActivation = RuleActivation.create(rule.getKey(), BLOCKER, null);
+    RuleActivation childActivation = RuleActivation.create(rule.getId(), rule.getKey(), BLOCKER, null);
     changes = activate(childProfile, childActivation);
     assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRule.Inheritance.OVERRIDES, emptyMap());
     assertThat(changes).hasSize(1);
 
-    RuleActivation resetActivation = RuleActivation.createReset(rule.getKey());
+    RuleActivation resetActivation = RuleActivation.createReset(rule.getId(), rule.getKey());
     changes = activate(childProfile, resetActivation);
     assertThatRuleIsUpdated(childProfile, rule, CRITICAL, INHERITED, emptyMap());
     assertThatRuleIsUpdated(parentProfile, rule, CRITICAL, null, emptyMap());
@@ -681,21 +681,21 @@ public class QProfileRuleImplTest {
     QProfileDto childProfile = createChildProfile(baseProfile);
     QProfileDto grandChildProfile = createChildProfile(childProfile);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey(), CRITICAL, null);
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), CRITICAL, null);
     List<ActiveRuleChange> changes = activate(baseProfile, activation);
     assertThatRuleIsActivated(baseProfile, rule, changes, CRITICAL, null, emptyMap());
     assertThatRuleIsActivated(childProfile, rule, changes, CRITICAL, INHERITED, emptyMap());
     assertThatRuleIsActivated(grandChildProfile, rule, changes, CRITICAL, INHERITED, emptyMap());
     assertThat(changes).hasSize(3);
 
-    RuleActivation childActivation = RuleActivation.create(rule.getKey(), BLOCKER, null);
+    RuleActivation childActivation = RuleActivation.create(rule.getId(), rule.getKey(), BLOCKER, null);
     changes = activate(childProfile, childActivation);
     assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRule.Inheritance.OVERRIDES, emptyMap());
     assertThatRuleIsUpdated(grandChildProfile, rule, BLOCKER, INHERITED, emptyMap());
     assertThat(changes).hasSize(2);
 
     // Reset on parent do not change child nor grandchild
-    RuleActivation resetActivation = RuleActivation.createReset(rule.getKey());
+    RuleActivation resetActivation = RuleActivation.createReset(rule.getId(), rule.getKey());
     changes = activate(baseProfile, resetActivation);
     assertThatRuleIsUpdated(baseProfile, rule, rule.getSeverityString(), null, emptyMap());
     assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRule.Inheritance.OVERRIDES, emptyMap());
@@ -703,7 +703,7 @@ public class QProfileRuleImplTest {
     assertThat(changes).hasSize(1);
 
     // Reset on child change grandchild
-    resetActivation = RuleActivation.createReset(rule.getKey());
+    resetActivation = RuleActivation.createReset(rule.getId(), rule.getKey());
     changes = activate(childProfile, resetActivation);
     assertThatRuleIsUpdated(baseProfile, rule, rule.getSeverityString(), null, emptyMap());
     assertThatRuleIsUpdated(childProfile, rule, rule.getSeverityString(), INHERITED, emptyMap());
@@ -717,7 +717,7 @@ public class QProfileRuleImplTest {
     QProfileDto parentProfile = createProfile(rule);
     QProfileDto childProfile = createChildProfile(parentProfile);
 
-    RuleActivation resetActivation = RuleActivation.createReset(rule.getKey());
+    RuleActivation resetActivation = RuleActivation.createReset(rule.getId(), rule.getKey());
     List<ActiveRuleChange> changes = activate(parentProfile, resetActivation);
     verifyNoActiveRules();
     assertThat(changes).hasSize(0);
@@ -791,7 +791,7 @@ public class QProfileRuleImplTest {
     QProfileDto parentProfile = createProfile(rule);
     QProfileDto childProfile = createChildProfile(parentProfile);
 
-    List<ActiveRuleChange> changes = activate(parentProfile, RuleActivation.create(rule.getKey()));
+    List<ActiveRuleChange> changes = activate(parentProfile, RuleActivation.create(rule.getId(), rule.getKey()));
     assertThatRuleIsActivated(parentProfile, rule, null, rule.getSeverityString(), null, emptyMap());
     assertThatRuleIsActivated(childProfile, rule, null, rule.getSeverityString(), INHERITED, emptyMap());
 
@@ -816,8 +816,8 @@ public class QProfileRuleImplTest {
     QProfileDto childProfile = createChildProfile(parentProfile);
     QProfileDto grandchildProfile = createChildProfile(childProfile);
 
-    activate(parentProfile, RuleActivation.create(rule1.getKey()));
-    activate(parentProfile, RuleActivation.create(rule2.getKey()));
+    activate(parentProfile, RuleActivation.create(rule1.getId(), rule1.getKey()));
+    activate(parentProfile, RuleActivation.create(rule2.getId(), rule2.getKey()));
 
     ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());
 
@@ -848,10 +848,10 @@ public class QProfileRuleImplTest {
     QProfileDto childProfile = createChildProfile(parentProfile);
     QProfileDto grandChildProfile = createChildProfile(childProfile);
 
-    RuleActivation activation = RuleActivation.create(rule.getKey(), CRITICAL, null);
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), CRITICAL, null);
     activate(parentProfile, activation);
 
-    RuleActivation overrideActivation = RuleActivation.create(rule.getKey(), BLOCKER, null);
+    RuleActivation overrideActivation = RuleActivation.create(rule.getId(), rule.getKey(), BLOCKER, null);
     activate(grandChildProfile, overrideActivation);
 
     // Reset on parent do not change child nor grandchild
@@ -874,7 +874,7 @@ public class QProfileRuleImplTest {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The built-in profile " + builtInProfile.getName() + " is read-only and can't be updated");
 
-    underTest.activateAndCommit(db.getSession(), builtInProfile, singleton(RuleActivation.create(rule.getKey())));
+    underTest.activateAndCommit(db.getSession(), builtInProfile, singleton(RuleActivation.create(rule.getId(), rule.getKey())));
   }
 
   private void assertThatProfileHasNoActiveRules(QProfileDto profile) {
index 0012109e9389bdfca1ec5773fba6175e601eead1..36718e93ac4367649cbe7236b1588048b9b18fe3 100644 (file)
@@ -110,11 +110,11 @@ public class QProfileTreeImplTest {
     RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("bar"));
 
     QProfileDto parentProfile = createProfile(rule1);
-    List<ActiveRuleChange> changes = activate(parentProfile, RuleActivation.create(rule1.getKey()));
+    List<ActiveRuleChange> changes = activate(parentProfile, RuleActivation.create(rule1.getId(), rule1.getKey()));
     assertThat(changes).hasSize(1);
 
     QProfileDto childProfile = createProfile(rule2);
-    changes = activate(childProfile, RuleActivation.create(rule2.getKey()));
+    changes = activate(childProfile, RuleActivation.create(rule2.getId(), rule2.getKey()));
     assertThat(changes).hasSize(1);
 
     expectedException.expect(BadRequestException.class);
@@ -129,11 +129,11 @@ public class QProfileTreeImplTest {
     RuleDefinitionDto rule2 = createJavaRule();
 
     QProfileDto profile1 = createProfile(rule1);
-    List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getKey()));
+    List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getId(), rule1.getKey()));
     assertThat(changes).hasSize(1);
 
     QProfileDto profile2 = createProfile(rule2);
-    changes = activate(profile2, RuleActivation.create(rule2.getKey()));
+    changes = activate(profile2, RuleActivation.create(rule2.getId(), rule2.getKey()));
     assertThat(changes).hasSize(1);
 
     changes = underTest.setParentAndCommit(db.getSession(), profile2, profile1);
@@ -152,11 +152,11 @@ public class QProfileTreeImplTest {
     RuleDefinitionDto rule1 = createJavaRule();
     RuleDefinitionDto rule2 = createJavaRule();
     QProfileDto profile1 = createProfile(rule1);
-    List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getKey()));
+    List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getId(), rule1.getKey()));
     assertThat(changes).hasSize(1);
 
     QProfileDto profile2 = createProfile(rule2);
-    changes = activate(profile2, RuleActivation.create(rule2.getKey()));
+    changes = activate(profile2, RuleActivation.create(rule2.getId(), rule2.getKey()));
     assertThat(changes).hasSize(1);
 
     changes = underTest.setParentAndCommit(db.getSession(), profile2, profile1);
@@ -164,7 +164,7 @@ public class QProfileTreeImplTest {
     assertThatRuleIsActivated(profile2, rule1, changes, rule1.getSeverityString(), INHERITED, emptyMap());
     assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
 
-    RuleActivation activation = RuleActivation.create(rule1.getKey(), BLOCKER, null);
+    RuleActivation activation = RuleActivation.create(rule1.getId(), rule1.getKey(), BLOCKER, null);
     changes = activate(profile2, activation);
     assertThat(changes).hasSize(1);
     assertThatRuleIsUpdated(profile2, rule1, BLOCKER, ActiveRule.Inheritance.OVERRIDES, emptyMap());
@@ -182,8 +182,8 @@ public class QProfileTreeImplTest {
     RuleDefinitionDto rule1 = createJavaRule();
     RuleDefinitionDto rule2 = createJavaRule();
     QProfileDto parentProfile = createProfile(rule1);
-    activate(parentProfile, RuleActivation.create(rule1.getKey()));
-    activate(parentProfile, RuleActivation.create(rule2.getKey()));
+    activate(parentProfile, RuleActivation.create(rule1.getId(), rule1.getKey()));
+    activate(parentProfile, RuleActivation.create(rule2.getId(), rule2.getKey()));
 
     rule1.setStatus(RuleStatus.REMOVED);
     db.rules().update(rule1);
index 2d5993407890a0fa3527953a20af6bdccd6b4766..cc2983410bfbc72a8f705ba74aac00ca0820c840 100644 (file)
@@ -260,7 +260,7 @@ public class RegisterQualityProfilesNotificationTest {
     db.qualityProfiles().activateRule(builtInQProfileDto, rule);
     QProfileDto childQProfileDto = insertProfile(organization,
       orgQProfile -> orgQProfile.setIsBuiltIn(false).setLanguage(language).setParentKee(builtInQProfileDto.getKee()));
-    qProfileRules.activateAndCommit(db.getSession(), childQProfileDto, singleton(RuleActivation.create(rule.getKey())));
+    qProfileRules.activateAndCommit(db.getSession(), childQProfileDto, singleton(RuleActivation.create(rule.getId(), rule.getKey())));
     db.commit();
 
     addPluginProfile(builtInQProfileDto);
index ab1f04ad2b1f7de3f18b3d099de38a80bf162526..044f81e78d0a54ff37e050adafc6cea33ef840b2 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.permission.OrganizationPermission;
 import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.db.rule.RuleTesting;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.BadRequestException;
@@ -140,10 +141,10 @@ public class ActivateRuleActionTest {
   public void activate_rule_in_default_organization() {
     userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
     QProfileDto qualityProfile = db.qualityProfiles().insert(defaultOrganization);
-    RuleKey ruleKey = RuleTesting.randomRuleKey();
+    RuleDefinitionDto rule = db.rules().insert(RuleTesting.randomRuleKey());
     TestRequest request = ws.newRequest()
       .setMethod("POST")
-      .setParam(PARAM_RULE, ruleKey.toString())
+      .setParam(PARAM_RULE, rule.getKey().toString())
       .setParam(PARAM_KEY, qualityProfile.getKee())
       .setParam("severity", "BLOCKER")
       .setParam("params", "key1=v1;key2=v2")
@@ -160,7 +161,7 @@ public class ActivateRuleActionTest {
     assertThat(activations).hasSize(1);
 
     RuleActivation activation = activations.iterator().next();
-    assertThat(activation.getRuleKey()).isEqualTo(ruleKey);
+    assertThat(activation.getRuleKey()).isEqualTo(rule.getKey());
     assertThat(activation.getSeverity()).isEqualTo(Severity.BLOCKER);
     assertThat(activation.isReset()).isFalse();
   }
@@ -170,6 +171,7 @@ public class ActivateRuleActionTest {
     userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
     QProfileDto qualityProfile = db.qualityProfiles().insert(organization);
     RuleKey ruleKey = RuleTesting.randomRuleKey();
+    db.rules().insert(ruleKey);
     TestRequest request = ws.newRequest()
       .setMethod("POST")
       .setParam(PARAM_RULE, ruleKey.toString())
@@ -200,6 +202,7 @@ public class ActivateRuleActionTest {
     db.qualityProfiles().addUserPermission(qualityProfile, user);
     userSession.logIn(user);
     RuleKey ruleKey = RuleTesting.randomRuleKey();
+    db.rules().insert(ruleKey);
 
     ws.newRequest()
       .setMethod("POST")
index 7f8d7e50e3373b4931c9e9eba847704256acba2a..0bb3a68e9381b07578a5b931e0b0195deaf8507a 100644 (file)
@@ -280,7 +280,7 @@ public class InheritanceActionTest {
   }
 
   private void overrideActiveRuleSeverity(RuleDefinitionDto rule, QProfileDto profile, String severity) {
-    qProfileRules.activateAndCommit(dbSession, profile, singleton(RuleActivation.create(rule.getKey(), severity, null)));
+    qProfileRules.activateAndCommit(dbSession, profile, singleton(RuleActivation.create(rule.getId(), rule.getKey(), severity, null)));
 //    dbSession.commit();
 //    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
   }
index f59614b4f0313d67066975268bb4ebae120ac323..01e9923df95c83e6f7c60c94e7920f3c08ceeadf 100644 (file)
@@ -613,7 +613,7 @@ public class SearchActionTest {
     OrganizationDto organization = db.organizations().insert();
     QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage("java"));
     RuleDefinitionDto rule = createJavaRule();
-    RuleActivation activation = RuleActivation.create(rule.getKey(), BLOCKER, null);
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey(), BLOCKER, null);
     qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
 
     indexRules();
@@ -660,7 +660,7 @@ public class SearchActionTest {
         .setDescription("Empty Param")
         .setName("empty_var"));
 
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     List<ActiveRuleChange> activeRuleChanges1 = qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
     qProfileRules.activateAndCommit(db.getSession(), waterproofProfile, singleton(activation));
 
@@ -716,7 +716,7 @@ public class SearchActionTest {
         .setDescription("My small description")
         .setName("my_var"));
 
-    RuleActivation activation = RuleActivation.create(rule.getKey());
+    RuleActivation activation = RuleActivation.create(rule.getId(), rule.getKey());
     List<ActiveRuleChange> activeRuleChanges = qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
 
     // Insert directly in database a rule parameter with a null value
@@ -779,7 +779,7 @@ public class SearchActionTest {
       .setSeverity("MAJOR")
       .setStatus(RuleStatus.DEPRECATED)
       .setType(RuleType.VULNERABILITY));
-    RuleActivation activation = RuleActivation.create(rule2.getKey(), null, null);
+    RuleActivation activation = RuleActivation.create(rule2.getId(), rule2.getKey(), null, null);
     qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
 
     // on other language, not activated => no match