From: Fabrice Bellingard Date: Wed, 26 Sep 2012 10:54:51 +0000 (+0200) Subject: SONAR-3769 Startup must check not only null but also blank rule names X-Git-Tag: 3.3~204 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b2c8e5248d2ebc7090b61ea83544e544c7eab1be;p=sonarqube.git SONAR-3769 Startup must check not only null but also blank rule names => When a rule doesn't have a description, a quality profile containing this rule can't be displayed when using Oracle DB --- diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java index 839672c4050..f033f5deef5 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java @@ -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."); diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java index 59d7a3e7a6b..2be99f6e3a6 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java @@ -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);