]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 Revert find ids to rule finder logic (removed rules are returned)
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 1 Jul 2014 11:45:42 +0000 (13:45 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 1 Jul 2014 11:45:42 +0000 (13:45 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java
sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java

index 6e93bf5b7fee974328a1343c645d1fb044929791..89fd99a10b2434d0a58070eae27db45f263a57d7 100644 (file)
@@ -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
index a7374945361601a8473070fdc28f6ba8593f6137..4939964bf251a801989e8d0149619b93b2026890 100644 (file)
@@ -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;
   }
index 92875e0c3c557e8b759fb966859a79c70e11c2d6..d014dbbe1b6a4c63b0e66ae75e099bab5d8a640d 100644 (file)
@@ -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.<Integer>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