From: Simon Brandhof Date: Wed, 14 Sep 2016 15:20:03 +0000 (+0200) Subject: SONAR-8079 improve tests X-Git-Tag: 6.1-RC1~73 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1252%2Fhead;p=sonarqube.git SONAR-8079 improve tests --- diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java index 03465614bc1..f1236bd115d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java @@ -34,6 +34,7 @@ import org.sonar.api.server.rule.RulesDefinition; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.db.DbClient; +import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; @@ -48,6 +49,7 @@ import org.sonar.server.rule.index.RuleIndexer; import org.sonar.server.rule.index.RuleQuery; import static com.google.common.collect.Sets.newHashSet; +import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -117,7 +119,19 @@ public class RegisterRulesTest { assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(RULE_KEY1, RULE_KEY2); // verify repositories - assertThat(dbClient.ruleRepositoryDao().selectAll(dbTester.getSession())).extracting(RuleRepositoryDto::getKee).containsOnly("fake"); + assertThat(dbClient.ruleRepositoryDao().selectAll(dbTester.getSession())).extracting(RuleRepositoryDto::getKey).containsOnly("fake"); + } + + @Test + public void delete_repositories_that_have_been_uninstalled() { + RuleRepositoryDto repository = new RuleRepositoryDto("findbugs", "java", "Findbugs"); + DbSession dbSession = dbTester.getSession(); + dbTester.getDbClient().ruleRepositoryDao().insert(dbSession, asList(repository)); + dbSession.commit(); + + execute(new FakeRepositoryV1()); + + assertThat(dbTester.getDbClient().ruleRepositoryDao().selectAll(dbSession)).extracting(RuleRepositoryDto::getKey).containsOnly("fake"); } @Test @@ -173,7 +187,7 @@ public class RegisterRulesTest { assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(RULE_KEY1, RULE_KEY3); // verify repositories - assertThat(dbClient.ruleRepositoryDao().selectAll(dbTester.getSession())).extracting(RuleRepositoryDto::getKee).containsOnly("fake"); + assertThat(dbClient.ruleRepositoryDao().selectAll(dbTester.getSession())).extracting(RuleRepositoryDto::getKey).containsOnly("fake"); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RepositoriesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RepositoriesActionTest.java index ef9152dd8be..d73535d881b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RepositoriesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RepositoriesActionTest.java @@ -60,8 +60,6 @@ public class RepositoriesActionTest { newRequest().setParam("q", "common").execute().assertJson(this.getClass(), "repositories_common.json"); newRequest().setParam("q", "squid").execute().assertJson(this.getClass(), "repositories_squid.json"); newRequest().setParam("q", "sonar").execute().assertJson(this.getClass(), "repositories_sonar.json"); - newRequest().setParam("ps", "4").execute().assertJson(this.getClass(), "repositories.json"); - newRequest().setParam("ps", "100").execute().assertJson(this.getClass(), "repositories.json"); } protected TestRequest newRequest() {