]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2052: Should be possible to restore backup without inheritance information
authorGodin <mandrikov@gmail.com>
Wed, 22 Dec 2010 09:06:18 +0000 (09:06 +0000)
committerGodin <mandrikov@gmail.com>
Wed, 22 Dec 2010 09:06:18 +0000 (09:06 +0000)
sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java
sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java
sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-without-inheritance.xml [new file with mode: 0644]

index 543606779fb78acab3c137ef5f10462ea1ce423e..2ca434ee7eefa63ffa99fa0aaf04f21fec5da11b 100644 (file)
@@ -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;
       }
 
index 08f75114341968f0b36402f1a0ec6ed060e82670..0abc449a411f4d6da62a31e5764ef3098e231bbc 100644 (file)
@@ -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<RulesProfile> 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 (file)
index 0000000..77498b9
--- /dev/null
@@ -0,0 +1,25 @@
+<sonar-config>
+  <version><![CDATA[54]]></version>
+  <date><![CDATA[2008-11-18]]></date>
+  <profiles>
+    <profile>
+      <name><![CDATA[test name]]></name>
+      <default-profile><![CDATA[true]]></default-profile>
+      <provided><![CDATA[true]]></provided>
+      <language><![CDATA[test language]]></language>
+      <active-rules>
+        <active-rule>
+          <key><![CDATA[test key]]></key>
+          <plugin><![CDATA[test plugin]]></plugin>
+          <level><![CDATA[ERROR]]></level>
+          <params>
+            <param>
+              <key><![CDATA[test param key]]></key>
+              <value><![CDATA[test value]]></value>
+            </param>
+          </params>
+        </active-rule>
+      </active-rules>
+    </profile>
+  </profiles>
+</sonar-config>