aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-03-04 11:03:37 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-03-04 14:57:45 +0100
commit2593c337e721282228699637692c6a80fd2871e7 (patch)
treef7dd0e7ece2a1aab4677575532038fc9f73f4162 /sonar-db/src/test
parent1b239a703582f3f95fcb220dbb9f13b25a00811e (diff)
downloadsonarqube-2593c337e721282228699637692c6a80fd2871e7.tar.gz
sonarqube-2593c337e721282228699637692c6a80fd2871e7.zip
SONAR-7330 When searching active rules by profile, ignore active rule on removed rules
Diffstat (limited to 'sonar-db/src/test')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java b/sonar-db/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
index bf20c99f5b0..8389519dc81 100644
--- a/sonar-db/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
@@ -23,6 +23,8 @@ import java.util.Collections;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
@@ -84,6 +86,29 @@ public class ActiveRuleDaoTest {
}
@Test
+ public void select_by_profile() throws Exception {
+ ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(QPROFILE_1, RULE_1).setSeverity(Severity.BLOCKER);
+ ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(QPROFILE_1, RULE_2).setSeverity(Severity.BLOCKER);
+ underTest.insert(dbTester.getSession(), activeRule1);
+ underTest.insert(dbTester.getSession(), activeRule2);
+ dbSession.commit();
+
+ assertThat(underTest.selectByProfileKey(dbSession, QPROFILE_1.getKey())).hasSize(2);
+ assertThat(underTest.selectByProfileKey(dbSession, QPROFILE_2.getKey())).isEmpty();
+ }
+
+ @Test
+ public void select_by_profile_ignore_removed_rules() throws Exception {
+ RuleDto removedRule = RuleTesting.newDto(RuleKey.of("removed", "rule")).setStatus(RuleStatus.REMOVED);
+ dbClient.ruleDao().insert(dbTester.getSession(), removedRule);
+ ActiveRuleDto activeRule = ActiveRuleDto.createFor(QPROFILE_1, removedRule).setSeverity(Severity.BLOCKER);
+ underTest.insert(dbTester.getSession(), activeRule);
+ dbSession.commit();
+
+ assertThat(underTest.selectByProfileKey(dbSession, QPROFILE_1.getKey())).isEmpty();
+ }
+
+ @Test
public void select_by_rule_ids() {
ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(QPROFILE_1, RULE_1).setSeverity(Severity.BLOCKER);
ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(QPROFILE_1, RULE_2).setSeverity(Severity.BLOCKER);