From cbe3819ae9e045049816761ff598ae5e74eac2e2 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 1 Jul 2014 13:45:42 +0200 Subject: [PATCH] SONAR-5007 Revert find ids to rule finder logic (removed rules are returned) --- .../java/org/sonar/api/rules/RuleFinder.java | 2 ++ .../sonar/server/rule/DefaultRuleFinder.java | 5 +--- .../rule/DefaultRuleFinderMediumTest.java | 23 ++++++++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java index 6e93bf5b7fe..89fd99a10b2 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java @@ -34,8 +34,10 @@ public interface RuleFinder extends TaskComponent, ServerComponent { /** * @since 2.5 + * @deprecated since 4.4, Please use {@link #findByKey(org.sonar.api.rule.RuleKey)}} */ @CheckForNull + @Deprecated Rule findById(int ruleId); @CheckForNull diff --git a/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java b/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java index a7374945361..4939964bf25 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java @@ -39,7 +39,6 @@ import java.util.List; import static com.google.common.collect.Lists.newArrayList; -@Deprecated /** * Will be removed in the future. Please use {@link org.sonar.server.rule.RuleService} */ @@ -68,9 +67,7 @@ public class DefaultRuleFinder implements RuleFinder { return rules; } for (Rule rule : index.getByIds(ruleIds)) { - if (rule.status() != RuleStatus.REMOVED) { - rules.add(toRule(rule)); - } + rules.add(toRule(rule)); } return rules; } diff --git a/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java b/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java index 92875e0c3c5..d014dbbe1b6 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java @@ -111,8 +111,7 @@ public class DefaultRuleFinderMediumTest { Assertions.assertThat(finder.findById(2)).isNull(); // should_find_by_ids - // 2 is returned even its status is REMOVED !!! Conflicts with IMPL. //TODO check with @Simon - assertThat(finder.findByIds(newArrayList(2, 3))).hasSize(1); + assertThat(finder.findByIds(newArrayList(2, 3))).hasSize(2); // should_find_by_key Rule rule = finder.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"); @@ -128,7 +127,7 @@ public class DefaultRuleFinderMediumTest { Assertions.assertThat(finder.findAll(RuleQuery.create().withRepositoryKey("checkstyle"))).hasSize(2); // find_all_enabled - //Assertions.assertThat(finder.findAll(RuleQuery.create())).onProperty("id").containsOnly(1, 3, 4); + Assertions.assertThat(finder.findAll(RuleQuery.create())).onProperty("id").containsOnly(1, 3, 4, 5); Assertions.assertThat(finder.findAll(RuleQuery.create())).hasSize(4); // do_not_find_disabled_rules @@ -142,6 +141,24 @@ public class DefaultRuleFinderMediumTest { assertThat(finder.findByIds(Collections.emptyList())).isEmpty(); } + @Test + public void find_ids_including_removed_rule() { + // find rule with id 2 is REMOVED + assertThat(finder.findByIds(newArrayList(2))).hasSize(1); + } + + @Test + public void find_id_return_null_on_removed_rule() { + // find rule with id 2 is REMOVED + assertThat(finder.findById(2)).isNull(); + } + + @Test + public void find_all_not_include_removed_rule() { + // find rule with id 2 is REMOVED + Assertions.assertThat(finder.findAll(RuleQuery.create())).onProperty("id").containsOnly(1, 3, 4, 5); + } + @Test public void find_manual_rule() { // find by id -- 2.39.5