]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3769 Startup must check not only null but also blank rule names
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Wed, 26 Sep 2012 10:54:51 +0000 (12:54 +0200)
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Wed, 26 Sep 2012 10:57:14 +0000 (12:57 +0200)
=> When a rule doesn't have a description, a quality profile
   containing this rule can't be displayed when using Oracle DB

sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java

index 839672c40505725138bc550bd9768b0575778ef2..f033f5deef5cd9b1f1c2e466532e5f11d014bafd 100644 (file)
@@ -119,11 +119,11 @@ public final class RegisterRules {
   }
 
   private void validateRule(Rule rule, String repositoryKey) {
-    if (rule.getName() == null && ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH) == null) {
+    if (StringUtils.isBlank(rule.getName()) && StringUtils.isBlank(ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
       throw new SonarException("The following rule (repository: " + repositoryKey + ") must have a name: " + rule);
     }
-    if (rule.getDescription() == null && ruleI18nManager.getDescription(repositoryKey, rule.getKey(), Locale.ENGLISH) == null) {
-      if (rule.getName() != null && ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH) == null) {
+    if (StringUtils.isBlank(rule.getDescription()) && StringUtils.isBlank(ruleI18nManager.getDescription(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
+      if (StringUtils.isNotBlank(rule.getName()) && StringUtils.isBlank(ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
         // specific case
         throw new SonarException("No description found for the rule '" + rule.getName() + "' (repository: " + repositoryKey + ") because the entry 'rule."
           + repositoryKey + "." + rule.getKey() + ".name' is missing from the bundle.");
index 59d7a3e7a6bedb610edf64fb851b8e25868de3b9..2be99f6e3a69764ae9207fad975f337e76ee4c27 100644 (file)
@@ -198,7 +198,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
     assertThat(result.size(), is(VolumeRepository.SIZE));
   }
 
-  // http://jira.codehaus.org/browse/SONAR-3305
+  // SONAR-3305
   @Test
   public void shouldFailRuleWithoutName() throws Exception {
     RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);
@@ -219,7 +219,24 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
     task.start();
   }
 
-  // http://jira.codehaus.org/browse/SONAR-3305
+  // SONAR-3769
+  @Test
+  public void shouldFailRuleWithBlankName() throws Exception {
+    RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);
+    when(ruleI18nManager.getName(anyString(), anyString(), any(Locale.class))).thenReturn("");
+    task = new RegisterRules(getSessionFactory(), new RuleRepository[] {new RuleWithoutNameRepository()}, ruleI18nManager);
+    setupData("shared");
+
+    // the rule has no name, it should fail
+    try {
+      task.start();
+      fail("Rule must have a name");
+    } catch (SonarException e) {
+      assertThat(e.getMessage(), containsString("must have a name"));
+    }
+  }
+
+  // SONAR-3305
   @Test
   public void shouldFailRuleWithoutDescription() throws Exception {
     RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);