]> source.dussan.org Git - sonarqube.git/commitdiff
Add some unit tests
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 21 Aug 2013 16:08:14 +0000 (18:08 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 21 Aug 2013 16:08:14 +0000 (18:08 +0200)
sonar-server/src/test/java/org/sonar/server/configuration/RuleChangeTest.java
sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/should_not_track_param_change_on_rule_revert_if_no_param.xml [new file with mode: 0644]

index 43f543a7be980404b0ed1e3dc56ac484ebc9dea8..652a0552c535b4f1a279313c31441d7d3cc3059b 100644 (file)
@@ -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 (file)
index 0000000..3aa3efa
--- /dev/null
@@ -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>