aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-22 15:29:18 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-29 13:26:54 +0100
commitb4d0c0deb09b79541fb4522f9d3d1772ade46da9 (patch)
tree321e2742446a931826f96fd172924fa34ae64258 /sonar-db/src/test
parent88ef557f33215c01836bd39fcafdf91e6f8f017b (diff)
downloadsonarqube-b4d0c0deb09b79541fb4522f9d3d1772ade46da9.tar.gz
sonarqube-b4d0c0deb09b79541fb4522f9d3d1772ade46da9.zip
SONAR-7330 DefaultRuleFinder is now using only RuleDao
Diffstat (limited to 'sonar-db/src/test')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java42
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/shared.xml9
2 files changed, 50 insertions, 1 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java
index 4a09e16219a..28208807e43 100644
--- a/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java
@@ -22,6 +22,7 @@ package org.sonar.db.rule;
import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.ibatis.session.ResultContext;
@@ -33,6 +34,7 @@ import org.junit.rules.ExpectedException;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
+import org.sonar.api.rules.RuleQuery;
import org.sonar.api.server.debt.DebtRemediationFunction;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
@@ -41,6 +43,7 @@ import org.sonar.db.RowNotFoundException;
import org.sonar.test.DbTests;
import static java.util.Arrays.asList;
+import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.assertThat;
@@ -77,6 +80,17 @@ public class RuleDaoTest {
}
@Test
+ public void selectByIds() {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+ assertThat(underTest.selectByIds(dbTester.getSession(), asList(1))).hasSize(1);
+ assertThat(underTest.selectByIds(dbTester.getSession(), asList(1,2))).hasSize(2);
+ assertThat(underTest.selectByIds(dbTester.getSession(), asList(1,2,3))).hasSize(2);
+
+ assertThat(underTest.selectByIds(dbTester.getSession(), asList(123))).isEmpty();
+ }
+
+ @Test
public void selectOrFailByKey() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
@@ -135,7 +149,7 @@ public class RuleDaoTest {
List<RuleDto> ruleDtos = underTest.selectAll(dbTester.getSession());
- assertThat(ruleDtos).extracting("id").containsOnly(1, 2);
+ assertThat(ruleDtos).extracting("id").containsOnly(1, 2, 10);
}
@Test
@@ -171,6 +185,19 @@ public class RuleDaoTest {
assertThat(ruleDto.getRepositoryKey()).isEqualTo("checkstyle");
}
+
+ @Test
+ public void select_by_query() {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+ assertThat(underTest.selectByQuery(dbTester.getSession(), RuleQuery.create())).hasSize(2);
+ assertThat(underTest.selectByQuery(dbTester.getSession(), RuleQuery.create().withKey("S001"))).hasSize(1);
+ assertThat(underTest.selectByQuery(dbTester.getSession(), RuleQuery.create().withConfigKey("S1"))).hasSize(1);
+ assertThat(underTest.selectByQuery(dbTester.getSession(), RuleQuery.create().withRepositoryKey("java"))).hasSize(2);
+ assertThat(underTest.selectByQuery(dbTester.getSession(),
+ RuleQuery.create().withKey("S001").withConfigKey("S1").withRepositoryKey("java"))).hasSize(1);
+ }
+
@Test
public void insert() throws Exception {
RuleDto newRule = new RuleDto()
@@ -304,6 +331,19 @@ public class RuleDaoTest {
}
@Test
+ public void select_parameters_by_rule_keys() {
+ dbTester.prepareDbUnit(getClass(), "select_parameters_by_rule_key.xml");
+
+ assertThat(underTest.selectRuleParamsByRuleKeys(dbTester.getSession(),
+ Arrays.asList(RuleKey.of("checkstyle", "AvoidNull"), RuleKey.of("unused", "Unused"))
+ )).hasSize(2);
+
+ assertThat(underTest.selectRuleParamsByRuleKeys(dbTester.getSession(),
+ singletonList(RuleKey.of("unknown", "Unknown"))
+ )).isEmpty();
+ }
+
+ @Test
public void insert_parameter() {
dbTester.prepareDbUnit(getClass(), "insert_parameter.xml");
RuleDto rule1 = underTest.selectOrFailByKey(dbTester.getSession(), RuleKey.of("plugin", "NewRuleKey"));
diff --git a/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/shared.xml
index ff4211adfce..94c54d47437 100644
--- a/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/shared.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/shared.xml
@@ -15,4 +15,13 @@
created_at="2014-05-10" updated_at="2014-05-11"
created_at_ms="1500000000000" updated_at_ms="1600000000000"
/>
+
+ <rules id="10" name="Removed" plugin_rule_key="S003"
+ plugin_config_key="S3" plugin_name="java" description="[null]" priority="4" status="REMOVED"
+ is_template="[false]" template_id="[null]"
+ tags="[null]" system_tags="[null]"
+ created_at="2014-05-10" updated_at="2014-05-11"
+ created_at_ms="1500000000000" updated_at_ms="1600000000000"
+ />
+
</dataset>