From 68ed2127f97f4bab341edb91b4180b1ffd6fc485 Mon Sep 17 00:00:00 2001 From: Godin Date: Wed, 22 Dec 2010 09:06:18 +0000 Subject: [PATCH] SONAR-2052: Should be possible to restore backup without inheritance information --- .../server/configuration/ProfilesBackup.java | 4 ++- .../server/configuration/BackupTest.java | 18 +++++++++++-- .../backup-restore-without-inheritance.xml | 25 +++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-without-inheritance.xml 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 543606779fb..2ca434ee7ee 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 @@ -205,7 +205,9 @@ public class ProfilesBackup implements Backupable { ActiveRule activeRule = new ActiveRule(null, new Rule(valuesRule.get("plugin"), valuesRule.get("key")), RulePriority .valueOf(valuesRule.get("level"))); activeRule.setActiveRuleParams(params); - activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.valueOf(valuesRule.get("inherited"))); + if (valuesRule.containsKey("inherited")) { + activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.valueOf(valuesRule.get("inherited"))); + } return activeRule; } diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java index 08f75114341..0abc449a411 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java @@ -19,8 +19,6 @@ */ package org.sonar.server.configuration; -import org.sonar.api.rules.ActiveRuleInheritanceStatus; - import com.google.common.collect.Lists; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; @@ -170,6 +168,22 @@ public class BackupTest { assertThat(param.getDefaultValue(), is("test param value")); } + @Test + public void shouldImportXmlWithoutInheritanceInformation() { + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null), + new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null))); + + String xml = getFileFromClasspath("backup-restore-without-inheritance.xml"); + SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); + + Collection profiles = sonarConfig.getProfiles(); + assertThat(profiles.size(), is(1)); + RulesProfile testProfile = profiles.iterator().next(); + assertThat(testProfile.getActiveRules().size(), is(1)); + ActiveRule activeRule = testProfile.getActiveRules().get(0); + assertThat(activeRule.getInheritanceStatus(), is(ActiveRuleInheritanceStatus.NO)); + } + @Test public void shouldImportXmlWithXmlIlliciteCharacters() { Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null))); diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-without-inheritance.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-without-inheritance.xml new file mode 100644 index 00000000000..77498b9ece7 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-without-inheritance.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5