diff options
Diffstat (limited to 'sonar-server')
4 files changed, 31 insertions, 30 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java index b3bc7f1a9c7..55de2e4efb5 100644 --- a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java +++ b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java @@ -67,7 +67,6 @@ public final class DeprecatedRuleRepositories { } } - class DeprecatedRuleRepository extends RuleRepository { private RulesRepository deprecatedRepository; @@ -116,7 +115,7 @@ class DeprecatedRuleRepository extends RuleRepository { private Rule cloneRule(Rule deprecatedRule) { Rule rule = Rule.create(getKey(), deprecatedRule.getKey(), deprecatedRule.getName()); rule.setConfigKey(deprecatedRule.getConfigKey()); - rule.setPriority(deprecatedRule.getPriority()); + rule.setSeverity(deprecatedRule.getSeverity()); rule.setDescription(deprecatedRule.getDescription()); rule.setEnabled(true); if (deprecatedRule.getParams() != null) { 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 6526d1d04fd..c222152667c 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 @@ -70,11 +70,11 @@ public final class RegisterRules { List<Integer> deprecatedUserRuleIds = new ArrayList<Integer>(); deprecatedUserRuleIds.addAll(session.createQuery( "SELECT r.id FROM " + Rule.class.getSimpleName() + - " r WHERE r.parent IS NOT NULL AND NOT EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p)").getResultList()); + " r WHERE r.parent IS NOT NULL AND NOT EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p)").getResultList()); deprecatedUserRuleIds.addAll(session.createQuery( "SELECT r.id FROM " + Rule.class.getSimpleName() + - " r WHERE r.parent IS NOT NULL AND EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p and p.enabled=false)").getResultList()); + " r WHERE r.parent IS NOT NULL AND EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p and p.enabled=false)").getResultList()); for (Integer deprecatedUserRuleId : deprecatedUserRuleIds) { Rule rule = session.getSingleResult(Rule.class, "id", deprecatedUserRuleId); @@ -127,7 +127,7 @@ public final class RegisterRules { persistedRule.setName(rule.getName()); persistedRule.setConfigKey(rule.getConfigKey()); persistedRule.setDescription(rule.getDescription()); - persistedRule.setPriority(rule.getPriority()); + persistedRule.setSeverity(rule.getSeverity()); persistedRule.setEnabled(true); persistedRule.setCardinality(rule.getCardinality()); diff --git a/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java index 187a3ed8e1f..7ae3f3bcda0 100644 --- a/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java @@ -25,7 +25,6 @@ import org.sonar.api.rules.RulePriority; import org.sonar.api.utils.ValidationMessages; import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsNull.nullValue; import static org.junit.Assert.assertThat; public class DeprecatedProfilesTest { @@ -44,13 +43,13 @@ public class DeprecatedProfilesTest { assertThat(def.getRules().size(), is(2)); assertThat(def.getRulesByRepositoryKey("checkstyle").size(), is(1)); - assertThat(def.getRulesByRepositoryKey("checkstyle").get(0).getPriority(), is(RulePriority.BLOCKER)); + assertThat(def.getRulesByRepositoryKey("checkstyle").get(0).getSeverity(), is(RulePriority.BLOCKER)); } @Test public void priorityIsOptional() { DeprecatedProfiles.DefaultProfileDefinition def = DeprecatedProfiles.DefaultProfileDefinition.create("sonar way", "java"); - def.activateRule(Rule.create("checkstyle", "IllegalRegexp", "Illegal regexp").setPriority(RulePriority.BLOCKER), null); - assertThat(def.getRules().get(0).getPriority(), is(RulePriority.BLOCKER)); + def.activateRule(Rule.create("checkstyle", "IllegalRegexp", "Illegal regexp").setSeverity(RulePriority.BLOCKER), null); + assertThat(def.getRules().get(0).getSeverity(), is(RulePriority.BLOCKER)); } } 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 2f76ab1d3bd..a43aa3403b1 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 @@ -23,18 +23,22 @@ import org.junit.Test; import org.sonar.api.rules.*; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import static org.hamcrest.Matchers.is; import static org.hamcrest.number.OrderingComparisons.greaterThan; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void saveNewRepositories() { setupData("shared"); - RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()}); + RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() }); task.start(); List<Rule> result = getSession().getResults(Rule.class, "pluginName", "fake"); @@ -50,7 +54,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void disableDeprecatedRepositories() { setupData("shared"); - RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()}); + RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() }); task.start(); List<Rule> rules = (List<Rule>) getSession() @@ -65,7 +69,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void disableDeprecatedActiveRules() { setupData("disableDeprecatedActiveRules"); - RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()}); + RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() }); task.start(); List<Rule> result = getSession().getResults(Rule.class, "pluginName", "fake"); @@ -82,10 +86,10 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void disableDeprecatedActiveRuleParameters() { setupData("disableDeprecatedActiveRuleParameters"); - RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()}); + RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() }); task.start(); - ActiveRule arule= getSession().getSingleResult(ActiveRule.class, "id", 1); + ActiveRule arule = getSession().getSingleResult(ActiveRule.class, "id", 1); assertThat(arule.getActiveRuleParams().size(), is(2)); assertNull(getSession().getSingleResult(ActiveRuleParam.class, "id", 3)); } @@ -93,7 +97,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void disableDeprecatedRules() { setupData("disableDeprecatedRules"); - RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()}); + RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() }); task.start(); Rule rule = getSession().getSingleResult(Rule.class, "id", 1); @@ -106,21 +110,21 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void updateRuleFields() { setupData("updadeRuleFields"); - RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()}); + RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() }); task.start(); // fields have been updated with new values Rule rule = getSession().getSingleResult(Rule.class, "id", 1); assertThat(rule.getName(), is("One")); assertThat(rule.getDescription(), is("Description of One")); - assertThat(rule.getPriority(), is(RulePriority.BLOCKER)); + assertThat(rule.getSeverity(), is(RulePriority.BLOCKER)); assertThat(rule.getConfigKey(), is("config1")); } @Test public void updateRuleParameters() { setupData("updateRuleParameters"); - RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()}); + RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() }); task.start(); Rule rule = getSession().getSingleResult(Rule.class, "id", 1); @@ -140,7 +144,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void doNotDisableUserRulesIfParentIsEnabled() { setupData("doNotDisableUserRulesIfParentIsEnabled"); - RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()}); + RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() }); task.start(); Rule rule = getSession().getSingleResult(Rule.class, "id", 2); @@ -150,7 +154,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void disableUserRulesIfParentIsDisabled() { setupData("disableUserRulesIfParentIsDisabled"); - RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new FakeRepository()}); + RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new FakeRepository() }); task.start(); Rule rule = getSession().getSingleResult(Rule.class, "id", 2); @@ -160,7 +164,7 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase { @Test public void volumeTesting() { setupData("shared"); - RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[]{new VolumeRepository()}); + RegisterRules task = new RegisterRules(getSessionFactory(), null, new RuleRepository[] { new VolumeRepository() }); task.start(); List<Rule> result = getSession().getResults(Rule.class, "enabled", true); @@ -176,14 +180,14 @@ class FakeRepository extends RuleRepository { public List<Rule> createRules() { Rule rule1 = Rule.create("fake", "rule1", "One"); rule1.setDescription("Description of One"); - rule1.setPriority(RulePriority.BLOCKER); + rule1.setSeverity(RulePriority.BLOCKER); rule1.setConfigKey("config1"); rule1.createParameter("param1").setDescription("parameter one"); rule1.createParameter("param2").setDescription("parameter two"); - + Rule rule2 = Rule.create("fake", "rule2", "Two"); - rule2.setPriority(RulePriority.INFO); - + rule2.setSeverity(RulePriority.INFO); + return Arrays.asList(rule1, rule2); } } @@ -195,12 +199,11 @@ class VolumeRepository extends RuleRepository { super("volume", "java"); } - public List<Rule> createRules() { List<Rule> rules = new ArrayList<Rule>(); for (int i = 0; i < SIZE; i++) { Rule rule = Rule.create("volume", "rule" + i, "description of " + i); - rule.setPriority(RulePriority.BLOCKER); + rule.setSeverity(RulePriority.BLOCKER); for (int j = 0; j < 20; j++) { rule.createParameter("param" + j); } @@ -208,4 +211,4 @@ class VolumeRepository extends RuleRepository { } return rules; } -}
\ No newline at end of file +} |