summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2012-09-26 12:54:51 +0200
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2012-09-26 12:57:14 +0200
commitb2c8e5248d2ebc7090b61ea83544e544c7eab1be (patch)
tree798cdfc5d586f10f895b6faa013cd2b4cac96045
parent424a818ede8e8f782bc125021e93b2786d0e4088 (diff)
downloadsonarqube-b2c8e5248d2ebc7090b61ea83544e544c7eab1be.tar.gz
sonarqube-b2c8e5248d2ebc7090b61ea83544e544c7eab1be.zip
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
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java6
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java21
2 files changed, 22 insertions, 5 deletions
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);