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;
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;
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");
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;
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
db.qualityProfileDao().insert(dbSession, profileDto);
dbSession.commit();
dbSession.clearCache();
+ ruleIndexer.index();
}
@After
@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);
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);
@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);
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);
@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"));
}
*/
@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"));
}
*/
@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"));
}
*/
@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);
}
@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);
@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();
}
@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"));
}
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
@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);
@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");
@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 {
@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);
}
@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);
@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();
@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);
}
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
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
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
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
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
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
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);
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);
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'");
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
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);
// 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
// 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);
}
// 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);
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
@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());
// 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();
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);
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
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.
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));
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();
}
}