aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/test
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-02-03 17:37:34 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-02-03 17:37:34 +0100
commit31af09b42f8aafb2a56522e8670b574603cd9eee (patch)
tree8ad623c3a6a658b4cb45a755367ad24adf995747 /sonar-server/src/test
parent68e772f2ce0b97b4c2cdb7f5d16c4bb6202b02d6 (diff)
downloadsonarqube-31af09b42f8aafb2a56522e8670b574603cd9eee.tar.gz
sonarqube-31af09b42f8aafb2a56522e8670b574603cd9eee.zip
SONAR-2094 Do not delete ACTIVE_RULES rows when rules are disabled
Diffstat (limited to 'sonar-server/src/test')
-rw-r--r--sonar-server/src/test/java/org/sonar/server/configuration/ProfilesBackupTest.java4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/EnableProfilesTest.java63
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldDisableProfilesWithMissingLanguages-result.xml9
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldDisableProfilesWithMissingLanguages.xml7
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldEnableProfilesWithKnownLanguages-result.xml11
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldEnableProfilesWithKnownLanguages.xml7
6 files changed, 99 insertions, 2 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/ProfilesBackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/ProfilesBackupTest.java
index dfec8d7d3a1..2387aba138f 100644
--- a/sonar-server/src/test/java/org/sonar/server/configuration/ProfilesBackupTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/configuration/ProfilesBackupTest.java
@@ -119,8 +119,8 @@ public class ProfilesBackupTest extends AbstractDbUnitTestCase {
RulesProfile testProfile = new RulesProfile("testProfile", "lang", false, false);
ActiveRule ar = new ActiveRule(null, new Rule("testPlugin", "testKey"), RulePriority.MAJOR);
ar.getActiveRuleParams().add(new ActiveRuleParam(null, new RuleParam(null, "paramKey", null, null), "testValue"));
- testProfile.getActiveRules().add(ar);
- testProfile.getActiveRules().add(new ActiveRule(null, new Rule("testPlugin", "testKey2"), RulePriority.MINOR));
+ testProfile.addActiveRule(ar);
+ testProfile.addActiveRule(new ActiveRule(null, new Rule("testPlugin", "testKey2"), RulePriority.MINOR));
testProfile.getAlerts().add(new Alert(null, new Metric("testKey"), Alert.OPERATOR_EQUALS, "10", "22"));
testProfile.getAlerts().add(new Alert(null, new Metric("testKey2"), Alert.OPERATOR_GREATER, "10", "22"));
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/EnableProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/startup/EnableProfilesTest.java
new file mode 100644
index 00000000000..c7ec1fec395
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/startup/EnableProfilesTest.java
@@ -0,0 +1,63 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.server.startup;
+
+import org.junit.Test;
+import org.sonar.api.resources.AbstractLanguage;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.Language;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
+public class EnableProfilesTest extends AbstractDbUnitTestCase {
+
+ @Test
+ public void shouldDisableProfilesWithMissingLanguages() {
+ setupData("shouldDisableProfilesWithMissingLanguages");
+
+ Language[] languages = new Language[]{Java.INSTANCE, new Php()};
+ EnableProfiles task = new EnableProfiles(languages, getSessionFactory(), null);
+ task.start();
+
+ checkTables("shouldDisableProfilesWithMissingLanguages", "rules_profiles");
+ }
+
+ @Test
+ public void shouldEnableProfilesWithKnownLanguages() {
+ setupData("shouldEnableProfilesWithKnownLanguages");
+
+ Language[] languages = new Language[]{Java.INSTANCE, new Php()};
+ EnableProfiles task = new EnableProfiles(languages, getSessionFactory(), null);
+ task.start();
+
+ checkTables("shouldEnableProfilesWithKnownLanguages", "rules_profiles");
+ }
+
+ private static class Php extends AbstractLanguage {
+
+ public Php() {
+ super("php");
+ }
+
+ public String[] getFileSuffixes() {
+ return new String[0];
+ }
+ }
+}
+
diff --git a/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldDisableProfilesWithMissingLanguages-result.xml b/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldDisableProfilesWithMissingLanguages-result.xml
new file mode 100644
index 00000000000..62dce741d80
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldDisableProfilesWithMissingLanguages-result.xml
@@ -0,0 +1,9 @@
+<dataset>
+ <rules_profiles id="1" provided="true" name="Java 1" default_profile="0" language="java" enabled="true" PARENT_NAME="[null]"/>
+ <rules_profiles id="2" provided="false" name="Java 2" default_profile="1" language="java" enabled="true" PARENT_NAME="[null]"/>
+ <rules_profiles id="3" provided="true" name="Php" default_profile="0" language="php" enabled="true" PARENT_NAME="[null]"/>
+
+ <!-- disabled -->
+ <rules_profiles id="4" provided="true" name="Cobol 1" default_profile="1" language="cobol" enabled="false" PARENT_NAME="[null]"/>
+ <rules_profiles id="5" provided="false" name="Cobol 2" default_profile="0" language="cobol" enabled="false" PARENT_NAME="[null]"/>
+</dataset> \ No newline at end of file
diff --git a/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldDisableProfilesWithMissingLanguages.xml b/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldDisableProfilesWithMissingLanguages.xml
new file mode 100644
index 00000000000..f2c684b5735
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldDisableProfilesWithMissingLanguages.xml
@@ -0,0 +1,7 @@
+<dataset>
+ <rules_profiles id="1" provided="true" name="Java 1" default_profile="0" language="java" enabled="true" PARENT_NAME="[null]"/>
+ <rules_profiles id="2" provided="false" name="Java 2" default_profile="1" language="java" enabled="true" PARENT_NAME="[null]"/>
+ <rules_profiles id="3" provided="true" name="Php" default_profile="0" language="php" enabled="true" PARENT_NAME="[null]"/>
+ <rules_profiles id="4" provided="true" name="Cobol 1" default_profile="1" language="cobol" enabled="true" PARENT_NAME="[null]"/>
+ <rules_profiles id="5" provided="false" name="Cobol 2" default_profile="0" language="cobol" enabled="true" PARENT_NAME="[null]"/>
+</dataset> \ No newline at end of file
diff --git a/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldEnableProfilesWithKnownLanguages-result.xml b/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldEnableProfilesWithKnownLanguages-result.xml
new file mode 100644
index 00000000000..d89acc7ae0b
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldEnableProfilesWithKnownLanguages-result.xml
@@ -0,0 +1,11 @@
+<dataset>
+ <rules_profiles id="1" provided="true" name="Java 1" default_profile="0" language="java" enabled="true" PARENT_NAME="[null]"/>
+ <rules_profiles id="2" provided="false" name="Java 2" default_profile="1" language="java" enabled="true" PARENT_NAME="[null]"/>
+
+ <!-- enabled -->
+ <rules_profiles id="3" provided="true" name="Disabled Php 1" default_profile="0" language="php" enabled="true" PARENT_NAME="[null]"/>
+ <rules_profiles id="4" provided="false" name="Disabled Php 2" default_profile="1" language="php" enabled="true" PARENT_NAME="[null]"/>
+
+ <!-- keep disabled -->
+ <rules_profiles id="5" provided="true" name="Disabled Cobol" default_profile="1" language="cobol" enabled="false" PARENT_NAME="[null]"/>
+</dataset> \ No newline at end of file
diff --git a/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldEnableProfilesWithKnownLanguages.xml b/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldEnableProfilesWithKnownLanguages.xml
new file mode 100644
index 00000000000..c32281a33db
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/startup/EnableProfilesTest/shouldEnableProfilesWithKnownLanguages.xml
@@ -0,0 +1,7 @@
+<dataset>
+ <rules_profiles id="1" provided="true" name="Java 1" default_profile="0" language="java" enabled="true" PARENT_NAME="[null]"/>
+ <rules_profiles id="2" provided="false" name="Java 2" default_profile="1" language="java" enabled="true" PARENT_NAME="[null]"/>
+ <rules_profiles id="3" provided="true" name="Disabled Php 1" default_profile="0" language="php" enabled="false" PARENT_NAME="[null]"/>
+ <rules_profiles id="4" provided="false" name="Disabled Php 2" default_profile="1" language="php" enabled="false" PARENT_NAME="[null]"/>
+ <rules_profiles id="5" provided="true" name="Disabled Cobol" default_profile="1" language="cobol" enabled="false" PARENT_NAME="[null]"/>
+</dataset> \ No newline at end of file