summaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-02-02 14:31:14 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-02-02 14:32:36 +0100
commit2bc382aaeace31072352a0b7e18c5878815a692a (patch)
tree63a790c4e3fe2d9f8aee2e3c08d36501a94e715f /sonar-server/src
parent303de3527f9d9bc4394bf997dfa287a8f7b3b375 (diff)
downloadsonarqube-2bc382aaeace31072352a0b7e18c5878815a692a.tar.gz
sonarqube-2bc382aaeace31072352a0b7e18c5878815a692a.zip
SONAR-2094 Support backups without the field <enabled>
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/configuration/Backup.java8
-rw-r--r--sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/configuration/ProfilesBackupTest.java34
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/configuration/ProfilesBackupTest/shouldSupportEnabledField.xml28
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/configuration/ProfilesBackupTest/shouldSupportMissingEnabledField.xml17
5 files changed, 85 insertions, 6 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java b/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java
index eba4e481083..c610f065535 100644
--- a/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java
+++ b/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java
@@ -103,13 +103,17 @@ public class Backup {
public void importXml(String xml) {
try {
startDb();
- SonarConfig sonarConfig = getSonarConfigFromXml(xml);
- importBackupablesXml(sonarConfig);
+ doImportXml(xml);
} finally {
stopDb();
}
}
+ void doImportXml(String xml) {
+ SonarConfig sonarConfig = getSonarConfigFromXml(xml);
+ importBackupablesXml(sonarConfig);
+ }
+
protected void importBackupablesXml(SonarConfig sonarConfig) {
for (Backupable backupable : backupables) {
backupable.importXml(sonarConfig);
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java
index 71d57d8c148..4067d83d37a 100644
--- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java
+++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java
@@ -85,6 +85,10 @@ public class ProfilesBackup implements Backupable {
}
public void importProfile(RulesDao rulesDao, RulesProfile toImport) {
+ if (toImport.getEnabled()==null) {
+ // backward-compatibility with versions < 2.6. The field "enabled" did not exist. Default value is true.
+ toImport.setEnabled(true);
+ }
importActiveRules(rulesDao, toImport);
importAlerts(toImport);
session.save(toImport);
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 d129f7e524c..dfec8d7d3a1 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
@@ -19,6 +19,7 @@
*/
package org.sonar.server.configuration;
+import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.measures.Metric;
@@ -26,11 +27,14 @@ import org.sonar.api.profiles.Alert;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.*;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.test.TestUtils;
+import java.io.IOException;
import java.util.Arrays;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.collection.IsCollectionContaining.hasItem;
+import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
public class ProfilesBackupTest extends AbstractDbUnitTestCase {
@@ -78,8 +82,7 @@ public class ProfilesBackupTest extends AbstractDbUnitTestCase {
}
@Test
- public void testExportWithNoProfiles() {
-
+ public void shouldImportProvidedProfiles() {
RulesProfile profileProvided = new RulesProfile("test provided", "lang", false, true);
RulesProfile profileNotProvided = new RulesProfile("test not provided", "lang", false, false);
getSession().save(profileProvided, profileNotProvided);
@@ -98,8 +101,7 @@ public class ProfilesBackupTest extends AbstractDbUnitTestCase {
}
@Test
- public void testExportWithProfilesAndAlerts() {
-
+ public void shouldImportProfiles() {
RulesProfile profileProvided = new RulesProfile("test provided", "lang", false, true);
RulesProfile profileNotProvided = new RulesProfile("test not provided", "lang", false, false);
getSession().save(profileProvided, profileNotProvided);
@@ -139,6 +141,30 @@ public class ProfilesBackupTest extends AbstractDbUnitTestCase {
assertEquals(2, newProfile.getActiveRules().size());
assertEquals(1, newProfile.getActiveRules(RulePriority.MAJOR).get(0).getActiveRuleParams().size());
assertEquals(2, newProfile.getAlerts().size());
+ }
+
+ /**
+ * The field <profile><enabled> has been added in version 2.6. Profiles imported from backup of previous releases must
+ * be considered as enabled.
+ */
+ @Test
+ public void shouldSupportMissingEnabledField() throws IOException {
+ Backup backup = new Backup(getSession());
+ backup.doImportXml(FileUtils.readFileToString(TestUtils.getResource(getClass(), "shouldSupportMissingEnabledField.xml")));
+
+ RulesProfile profile = getSession().getSingleResult(RulesProfile.class, "name", "Missing enabled field");
+ assertThat(profile.getEnabled(), is(Boolean.TRUE));
+ }
+
+ @Test
+ public void shouldSupportEnabledField() throws IOException {
+ Backup backup = new Backup(getSession());
+ backup.doImportXml(FileUtils.readFileToString(TestUtils.getResource(getClass(), "shouldSupportEnabledField.xml")));
+
+ RulesProfile enabledProfile = getSession().getSingleResult(RulesProfile.class, "name", "Enabled");
+ assertThat(enabledProfile.getEnabled(), is(Boolean.TRUE));
+ RulesProfile disabledProfile = getSession().getSingleResult(RulesProfile.class, "name", "Disabled");
+ assertThat(disabledProfile.getEnabled(), is(Boolean.FALSE));
}
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/ProfilesBackupTest/shouldSupportEnabledField.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/ProfilesBackupTest/shouldSupportEnabledField.xml
new file mode 100644
index 00000000000..cbd461b32e2
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/configuration/ProfilesBackupTest/shouldSupportEnabledField.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sonar-config>
+ <version><![CDATA[59]]></version>
+ <date><![CDATA[2009-02-19]]></date>
+ <metrics/>
+ <profiles>
+ <profile>
+ <name><![CDATA[Disabled]]></name>
+ <default-profile><![CDATA[false]]></default-profile>
+ <provided><![CDATA[false]]></provided>
+ <language><![CDATA[java]]></language>
+ <enabled><![CDATA[false]]></enabled>
+ <active-rules>
+ </active-rules>
+ <alerts/>
+ </profile>
+ <profile>
+ <name><![CDATA[Enabled]]></name>
+ <default-profile><![CDATA[false]]></default-profile>
+ <provided><![CDATA[false]]></provided>
+ <language><![CDATA[java]]></language>
+ <enabled><![CDATA[true]]></enabled>
+ <active-rules>
+ </active-rules>
+ <alerts/>
+ </profile>
+ </profiles>
+</sonar-config>
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/ProfilesBackupTest/shouldSupportMissingEnabledField.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/ProfilesBackupTest/shouldSupportMissingEnabledField.xml
new file mode 100644
index 00000000000..4ba3d1f7053
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/configuration/ProfilesBackupTest/shouldSupportMissingEnabledField.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sonar-config>
+ <version><![CDATA[59]]></version>
+ <date><![CDATA[2009-02-19]]></date>
+ <metrics/>
+ <profiles>
+ <profile>
+ <name><![CDATA[Missing enabled field]]></name>
+ <default-profile><![CDATA[false]]></default-profile>
+ <provided><![CDATA[false]]></provided>
+ <language><![CDATA[java]]></language>
+ <active-rules>
+ </active-rules>
+ <alerts/>
+ </profile>
+ </profiles>
+</sonar-config>