From d7f4511dc8328893e04c7e27b9059973fc5c168e Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 14 Sep 2016 17:20:03 +0200 Subject: [PATCH] SONAR-8079 improve tests --- .../sonar/server/rule/RegisterRulesTest.java | 18 ++++++++++++++++-- .../server/rule/ws/RepositoriesActionTest.java | 2 -- 2 files changed, 16 insertions(+), 4 deletions(-) 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() { -- 2.39.5