diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-08-21 18:08:14 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-08-21 18:08:14 +0200 |
commit | ba289080fb11d824b25e21cca57a1d57322616d7 (patch) | |
tree | 00a4687b2f7e6c556471ba0f10ab038ff85abbdd | |
parent | ac37e02d6d3d99e3e6acd3557e9a3fc202fe742f (diff) | |
download | sonarqube-ba289080fb11d824b25e21cca57a1d57322616d7.tar.gz sonarqube-ba289080fb11d824b25e21cca57a1d57322616d7.zip |
Add some unit tests
2 files changed, 45 insertions, 0 deletions
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; @@ -69,6 +73,13 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { } @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"); profilesManager.ruleSeverityChanged(2, 3, RulePriority.BLOCKER, RulePriority.CRITICAL, "admin"); @@ -76,6 +87,13 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { } @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"); profilesManager.revert(2, 3, "admin"); @@ -83,6 +101,20 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { } @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"); profilesManager.changeParentProfile(2, "parent", "admin"); 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 @@ +<dataset> + + <rules id="2" name="bar" description="test2" plugin_config_key="checker/bar" + plugin_rule_key="checkstyle.rule2" plugin_name="plugin" status="READY" cardinality="SINGLE" parent_id="[null]"/> + <rules_profiles id="1" version="1" used_profile="true" name="parent" language="java" parent_name="[null]" /> + + <rules_profiles id="2" version="1" used_profile="true" name="child" language="java" parent_name="parent" /> + + <active_rules id="2" profile_id="1" rule_id="2" failure_level="2" inheritance="[null]"/> + + <active_rules id="3" profile_id="2" rule_id="2" failure_level="3" inheritance="OVERRIDES"/> + +</dataset> |