From ba289080fb11d824b25e21cca57a1d57322616d7 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 21 Aug 2013 18:08:14 +0200 Subject: Add some unit tests --- .../sonar/server/configuration/RuleChangeTest.java | 32 ++++++++++++++++++++++ ...ack_param_change_on_rule_revert_if_no_param.xml | 13 +++++++++ 2 files changed, 45 insertions(+) create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_param_change_on_rule_revert_if_no_param.xml diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/RuleChangeTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/RuleChangeTest.java index 43f543a7be9..652a0552c53 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/RuleChangeTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/RuleChangeTest.java @@ -21,10 +21,14 @@ package org.sonar.server.configuration; import org.junit.Before; import org.junit.Test; +import org.sonar.api.rules.ActiveRuleChange; +import org.sonar.api.rules.ActiveRuleParamChange; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; import org.sonar.jpa.test.AbstractDbUnitTestCase; +import static org.fest.assertions.Assertions.assertThat; + public class RuleChangeTest extends AbstractDbUnitTestCase { private ProfilesManager profilesManager; @@ -68,6 +72,13 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { checkTables("ruleParamChanged", new String[]{"change_date"}, "active_rule_changes", "active_rule_param_changes"); } + @Test + public void should_not_track_rule_param_change_if_no_change() { + setupData("initialData"); + profilesManager.ruleParamChanged(2, 3, "param1", "20", "20", "admin"); + assertThat(getHQLCount(ActiveRuleChange.class)).isEqualTo(0); + } + @Test public void should_track_rule_severity_change() { setupData("initialData"); @@ -75,6 +86,13 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { checkTables("ruleSeverityChanged", new String[]{"change_date"}, "active_rule_changes"); } + @Test + public void should_not_track_rule_severity_change_if_no_change() { + setupData("initialData"); + profilesManager.ruleSeverityChanged(2, 3, RulePriority.BLOCKER, RulePriority.BLOCKER, "admin"); + assertThat(getHQLCount(ActiveRuleChange.class)).isEqualTo(0); + } + @Test public void should_track_rule_revert() { setupData("ruleReverted"); @@ -82,6 +100,20 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { checkTables("ruleReverted", new String[]{"change_date"}, "active_rule_changes", "active_rule_param_changes"); } + @Test + public void should_not_track_param_change_on_rule_revert_if_no_param() { + setupData("should_not_track_param_change_on_rule_revert_if_no_param"); + profilesManager.revert(2, 3, "admin"); + assertThat(getHQLCount(ActiveRuleParamChange.class)).isEqualTo(0); + } + + @Test + public void should_not_track_param_change_on_rule_revert_if_no_change() { + setupData("should_not_track_param_change_on_rule_revert_if_no_param"); + profilesManager.revert(2, 3, "admin"); + assertThat(getHQLCount(ActiveRuleParamChange.class)).isEqualTo(0); + } + @Test public void should_track_change_parent_profile() { setupData("changeParentProfile"); diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_param_change_on_rule_revert_if_no_param.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_param_change_on_rule_revert_if_no_param.xml new file mode 100644 index 00000000000..3aa3efa4fb3 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_param_change_on_rule_revert_if_no_param.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + -- cgit v1.2.3