]> source.dussan.org Git - sonarqube.git/commitdiff
Add unit tests on rule change tracking on first version profile
authorJulien Lancelot <julien.lancelot@gmail.com>
Tue, 20 Aug 2013 09:29:36 +0000 (11:29 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Tue, 20 Aug 2013 09:29:36 +0000 (11:29 +0200)
sonar-server/src/test/java/org/sonar/server/configuration/ProfilesManagerTest.java
sonar-server/src/test/java/org/sonar/server/configuration/RuleChangeTest.java
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 with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_rule_activation_on_not_used_first_version_profile.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_track_rule_activation_on_used_first_version_profile-result.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_track_rule_activation_on_used_first_version_profile.xml [new file with mode: 0644]

index 4e2ce583632609fa503ac5e777b3036d6f96cf4b..f3d3f9ee605bb4fd77a0bf86860ca106336a07e8 100644 (file)
@@ -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);
   }
+
 }
index 25a9ba2e7dfa36d9dcd47de66ca4455f09708ce1..710e86eccc17269609157078fc856d544765d960 100644 (file)
@@ -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 (file)
index 0000000..9d335e0
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+
+  <rules_profiles id="1" version="1" used_profile="false" name="parent" language="java" parent_name="[null]" />
+
+</dataset>
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 (file)
index 0000000..0493b0f
--- /dev/null
@@ -0,0 +1,14 @@
+<dataset>
+
+  <rules id="1" name="foo" description="test" plugin_config_key="checker/foo"
+         plugin_rule_key="checkstyle.rule1" plugin_name="plugin" status="READY" cardinality="SINGLE" parent_id="[null]"/>
+
+  <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_parameters id="13" rule_id="2" name="param1" description="[null]" param_type="REGULAR_EXPRESSION"/>
+
+  <rules_profiles id="1" version="1" used_profile="false" name="parent" language="java" parent_name="[null]" />
+
+  <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
+
+</dataset>
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 (file)
index 0000000..fd6eacc
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+
+  <rules_profiles id="1" version="2" used_profile="false" name="parent" language="java" parent_name="[null]" />
+
+</dataset>
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 (file)
index 0000000..a1f36c6
--- /dev/null
@@ -0,0 +1,14 @@
+<dataset>
+
+  <rules id="1" name="foo" description="test" plugin_config_key="checker/foo"
+         plugin_rule_key="checkstyle.rule1" plugin_name="plugin" status="READY" cardinality="SINGLE" parent_id="[null]"/>
+
+  <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_parameters id="13" rule_id="2" name="param1" description="[null]" param_type="REGULAR_EXPRESSION"/>
+
+  <rules_profiles id="1" version="1" used_profile="true" name="parent" language="java" parent_name="[null]" />
+
+  <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
+
+</dataset>