]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 - Severity is null for manual rules
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 1 Jul 2014 10:50:03 +0000 (12:50 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 1 Jul 2014 11:35:56 +0000 (13:35 +0200)
sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java

index be224ea5b0fe35b74131db14ead626fe09e45074..a7374945361601a8473070fdc28f6ba8593f6137 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.server.search.QueryOptions;
 import org.sonar.server.search.Result;
 
 import javax.annotation.CheckForNull;
+
 import java.util.Collection;
 import java.util.List;
 
@@ -118,7 +119,7 @@ public class DefaultRuleFinder implements RuleFinder {
       .setUpdatedAt(rule.updatedAt())
       .setDescription(rule.htmlDescription())
       .setRepositoryKey(rule.key().repository())
-      .setSeverity(RulePriority.valueOf(rule.severity()))
+      .setSeverity(rule.severity() != null ? RulePriority.valueOf(rule.severity()) : null)
       .setStatus(rule.status().name())
       .setDefaultCharacteristicKey(rule.defaultDebtCharacteristicKey())
       .setDefaultSubCharacteristicKey(rule.defaultDebtSubCharacteristicKey())
index c683d6234f00ed711c4d49b625ef8bc95c657c03..92875e0c3c557e8b759fb966859a79c70e11c2d6 100644 (file)
 package org.sonar.server.rule;
 
 import org.fest.assertions.Assertions;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.*;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleQuery;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.server.db.DbClient;
-import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.tester.ServerTester;
 
 import java.util.Collections;
@@ -44,16 +40,25 @@ public class DefaultRuleFinderMediumTest {
   @ClassRule
   public static ServerTester tester = new ServerTester();
 
+  private DbClient dbClient;
   private DefaultRuleFinder finder;
   private DbSession session;
 
   @Before
-  public void setup() {
+  public void setUp() throws Exception {
     finder = tester.get(DefaultRuleFinder.class);
+    dbClient = tester.get(DbClient.class);
+    session = dbClient.openSession(false);
+  }
 
-    session = tester.get(DbClient.class).openSession(false);
-
-    tester.get(RuleDao.class).insert(session,
+  /**
+   * Testing with ids required data to be identical to all tests
+   */
+  @BeforeClass
+  public static void setupClass() {
+    tester.clearDbAndIndexes();
+    DbSession session = tester.get(DbClient.class).openSession(false);
+    tester.get(DbClient.class).ruleDao().insert(session,
       new RuleDto()
         .setName("Check Header")
         .setConfigKey("Checker/Treewalker/HeaderCheck")
@@ -81,9 +86,11 @@ public class DefaultRuleFinderMediumTest {
         .setRuleKey("CallSuperFirst")
         .setRepositoryKey("pmd")
         .setSeverity(2)
-        .setStatus(RuleStatus.READY)
+        .setStatus(RuleStatus.READY),
+      RuleTesting.newManualRule("Manual_Rule").setName("Manual Rule")
     );
     session.commit();
+    session.close();
   }
 
   @After
@@ -91,7 +98,6 @@ public class DefaultRuleFinderMediumTest {
     session.close();
   }
 
-
   @Test
   public void should_success_finder_wrap() {
 
@@ -123,7 +129,7 @@ public class DefaultRuleFinderMediumTest {
 
     // find_all_enabled
     //Assertions.assertThat(finder.findAll(RuleQuery.create())).onProperty("id").containsOnly(1, 3, 4);
-    Assertions.assertThat(finder.findAll(RuleQuery.create())).hasSize(3);
+    Assertions.assertThat(finder.findAll(RuleQuery.create())).hasSize(4);
 
     // do_not_find_disabled_rules
     Assertions.assertThat(finder.findByKey("checkstyle", "DisabledCheck")).isNull();
@@ -135,4 +141,15 @@ public class DefaultRuleFinderMediumTest {
     tester.clearDbAndIndexes();
     assertThat(finder.findByIds(Collections.<Integer>emptyList())).isEmpty();
   }
+
+  @Test
+  public void find_manual_rule() {
+    // find by id
+    Assertions.assertThat(finder.findById(5)).isNotNull();
+
+    // find by key
+    Rule rule = finder.findByKey("manual", "Manual_Rule");
+    Assertions.assertThat(rule).isNotNull();
+    Assertions.assertThat(rule.isEnabled()).isTrue();
+  }
 }