From ab09254608fa6dcf5595891d9070e4d9faf21276 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 20 Aug 2013 11:29:36 +0200 Subject: [PATCH] Add unit tests on rule change tracking on first version profile --- .../configuration/ProfilesManagerTest.java | 7 ++-- .../server/configuration/RuleChangeTest.java | 37 ++++++++++++++----- ..._not_used_first_version_profile-result.xml | 5 +++ ...tion_on_not_used_first_version_profile.xml | 14 +++++++ ...n_on_used_first_version_profile-result.xml | 5 +++ ...tivation_on_used_first_version_profile.xml | 14 +++++++ 6 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_rule_activation_on_not_used_first_version_profile-result.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_rule_activation_on_not_used_first_version_profile.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_track_rule_activation_on_used_first_version_profile-result.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_track_rule_activation_on_used_first_version_profile.xml diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/ProfilesManagerTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/ProfilesManagerTest.java index 4e2ce583632..f3d3f9ee605 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/ProfilesManagerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/ProfilesManagerTest.java @@ -37,17 +37,18 @@ public class ProfilesManagerTest extends AbstractDbUnitTestCase { } @Test - public void test_delete_all_profiles() { + public void should_delete_all_profiles() { RulesProfile test1 = RulesProfile.create("test1", "java"); test1.setDefaultProfile(true); RulesProfile test2 = RulesProfile.create("test2", "java"); getSession().save(test1, test2); - assertThat(getHQLCount(RulesProfile.class)).isEqualTo(new Long(2)); + assertThat(getHQLCount(RulesProfile.class)).isEqualTo(2); manager.deleteAllProfiles(); - assertThat(getHQLCount(RulesProfile.class)).isEqualTo(new Long(0)); + assertThat(getHQLCount(RulesProfile.class)).isEqualTo(0); } + } 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 25a9ba2e7df..710e86eccc1 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,13 @@ package org.sonar.server.configuration; import org.junit.Before; import org.junit.Test; +import org.sonar.api.rules.ActiveRuleChange; 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; @@ -34,63 +37,79 @@ public class RuleChangeTest extends AbstractDbUnitTestCase { } @Test - public void testVersionIncreaseIfUsed() { + public void should_increase_version_if_used() { setupData("initialData"); profilesManager.activated(2, 3, "admin"); checkTables("versionIncreaseIfUsed", "rules_profiles"); } @Test - public void testVersionIncreaseIfUsedAndInChildren() { + public void should_increase_version_if_used_and_in_children() { setupData("initialData"); profilesManager.activated(1, 1, "admin"); checkTables("versionIncreaseIfUsedAndInChildren", "rules_profiles"); } @Test - public void testRuleActivated() { + public void should_track_rule_activation() { setupData("initialData"); profilesManager.activated(2, 3, "admin"); checkTables("ruleActivated", new String[]{"change_date"}, "active_rule_changes"); } @Test - public void testRuleDeactivated() { + public void should_not_track_rule_activation_on_not_used_first_version_profile() { + setupData("should_not_track_rule_activation_on_not_used_first_version_profile"); + profilesManager.activated(1, 1, "admin"); + assertThat(getHQLCount(ActiveRuleChange.class)).isEqualTo(0); + checkTables("should_not_track_rule_activation_on_not_used_first_version_profile", "rules_profiles"); + } + + @Test + public void should_track_rule_activation_on_used_first_version_profile() { + setupData("should_track_rule_activation_on_used_first_version_profile"); + profilesManager.activated(1, 1, "admin"); + assertThat(getHQLCount(ActiveRuleChange.class)).isEqualTo(1); + checkTables("should_track_rule_activation_on_used_first_version_profile", "rules_profiles"); + } + + @Test + public void should_track_rule_deactivation() { setupData("initialData"); profilesManager.deactivated(2, 3, "admin"); checkTables("ruleDeactivated", new String[]{"change_date"}, "active_rule_changes"); } @Test - public void testRuleParamChanged() { + public void should_track_rule_param_change() { setupData("initialData"); profilesManager.ruleParamChanged(2, 3, "param1", "20", "30", "admin"); checkTables("ruleParamChanged", new String[]{"change_date"}, "active_rule_changes", "active_rule_param_changes"); } @Test - public void testRuleSeverityChanged() { + public void should_track_rule_severity_change() { setupData("initialData"); profilesManager.ruleSeverityChanged(2, 3, RulePriority.BLOCKER, RulePriority.CRITICAL, "admin"); checkTables("ruleSeverityChanged", new String[]{"change_date"}, "active_rule_changes"); } @Test - public void testRuleReverted() { + public void should_track_rule_revert() { setupData("ruleReverted"); profilesManager.revert(2, 3, "admin"); checkTables("ruleReverted", new String[]{"change_date"}, "active_rule_changes", "active_rule_param_changes"); } @Test - public void testChangeParentProfile() { + public void should_track_change_parent_profile() { setupData("changeParentProfile"); profilesManager.changeParentProfile(2, "parent", "admin"); checkTables("changeParentProfile", new String[]{"change_date"}, "active_rule_changes"); } @Test - public void testRemoveActivatedRules() { + public void should_track_remove_activated_rules() { setupData("initialData"); Rule rule = getSession().reattach(Rule.class, 1); profilesManager.removeActivatedRules(rule); diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_rule_activation_on_not_used_first_version_profile-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_rule_activation_on_not_used_first_version_profile-result.xml new file mode 100644 index 00000000000..9d335e0993e --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_rule_activation_on_not_used_first_version_profile-result.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_rule_activation_on_not_used_first_version_profile.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_rule_activation_on_not_used_first_version_profile.xml new file mode 100644 index 00000000000..0493b0f09e6 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_rule_activation_on_not_used_first_version_profile.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_track_rule_activation_on_used_first_version_profile-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_track_rule_activation_on_used_first_version_profile-result.xml new file mode 100644 index 00000000000..fd6eacc30ef --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_track_rule_activation_on_used_first_version_profile-result.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_track_rule_activation_on_used_first_version_profile.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_track_rule_activation_on_used_first_version_profile.xml new file mode 100644 index 00000000000..a1f36c6a350 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_track_rule_activation_on_used_first_version_profile.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + -- 2.39.5