]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1987: Add rule configKey to backup too
authorGodin <mandrikov@gmail.com>
Wed, 8 Dec 2010 16:30:08 +0000 (16:30 +0000)
committerGodin <mandrikov@gmail.com>
Wed, 8 Dec 2010 16:30:08 +0000 (16:30 +0000)
sonar-server/src/main/java/org/sonar/server/configuration/RulesBackup.java
sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java
sonar-server/src/test/java/org/sonar/server/configuration/RulesBackupTest.java
sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-valid.xml
sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-valid.xml

index 87ac7b5803df2a7f2a915671f67c97562430169b..f97cee3685b7edd02cb616c6c47ca8e612d37762 100644 (file)
@@ -101,6 +101,9 @@ public class RulesBackup implements Backupable {
           "pluginName", rule.getRepositoryKey(),
           "key", rule.getKey());
       if (matchingRuleInDb != null) {
+        // merge
+        matchingRuleInDb.setParent(matchingParentRuleInDb);
+        matchingRuleInDb.setConfigKey(rule.getConfigKey());
         matchingRuleInDb.setName(rule.getName());
         matchingRuleInDb.setDescription(rule.getDescription());
         matchingRuleInDb.setSeverity(rule.getSeverity());
@@ -123,6 +126,7 @@ public class RulesBackup implements Backupable {
         writeNode(writer, "parentKey", rule.getParent().getKey());
         writeNode(writer, "repositoryKey", rule.getRepositoryKey());
         writeNode(writer, "key", rule.getKey());
+        writeNode(writer, "configKey", rule.getConfigKey());
         writeNode(writer, "level", rule.getSeverity().name());
         writeNode(writer, "name", rule.getName());
         writeNode(writer, "description", rule.getDescription());
@@ -165,6 +169,7 @@ public class RulesBackup implements Backupable {
         rule.setParent(parent)
             .setRepositoryKey(valuesRule.get("repositoryKey"))
             .setKey(valuesRule.get("key"))
+            .setConfigKey(valuesRule.get("configKey"))
             .setName(valuesRule.get("name"))
             .setDescription(valuesRule.get("description"))
             .setSeverity(RulePriority.valueOf(valuesRule.get("level")));
index 0e008fe836206b0a6c36e0b8caacd33529dcafe0..a9eac6a43a866fd90836ad7454ac438f7ed3cf13 100644 (file)
@@ -149,6 +149,7 @@ public class BackupTest {
     assertThat(rule.getParent().getKey(), is("test key"));
     assertThat(rule.getRepositoryKey(), is("test plugin"));
     assertThat(rule.getKey(), is("test key2"));
+    assertThat(rule.getConfigKey(), is("test config key"));
     assertThat(rule.getName(), is("test name"));
     assertThat(rule.getDescription(), is("test description"));
     assertThat(rule.getSeverity(), is(RulePriority.INFO));
@@ -264,6 +265,7 @@ public class BackupTest {
     Rule parentRule = Rule.create("test plugin", "test key", null);
     Rule rule = Rule.create("test plugin", "test key2", "test name")
         .setDescription("test description")
+        .setConfigKey("test config key")
         .setSeverity(RulePriority.INFO)
         .setParent(parentRule);
     rule.createParameter().setKey("test param key").setDefaultValue("test param value");
index d8caaa5a93c4275e914fc670c6808be22a9c04ac..f5d32822f8383e6b5ece2a58a406e8daa345e87d 100644 (file)
@@ -72,6 +72,10 @@ public class RulesBackupTest extends AbstractDbUnitTestCase {
     sonarConfig.setRules(Arrays.asList(createUserRule()));
     rulesBackup.importXml(sonarConfig);
 
+    verify();
+  }
+
+  private void verify() {
     assertThat(getSession().getResults(Rule.class).size(), is(2));
     Rule importedRule = getDao().getRulesDao().getRuleByKey("repo", "key2");
     assertThat(importedRule.getParent(), is(rule));
@@ -88,12 +92,12 @@ public class RulesBackupTest extends AbstractDbUnitTestCase {
   @Test
   public void shouldUpdateRules() {
     getSession().save(rule);
-    getSession().save(createUserRule());
+    getSession().save(Rule.create("repo", "key2", ""));
 
     sonarConfig.setRules(Arrays.asList(createUserRule()));
     rulesBackup.importXml(sonarConfig);
 
-    assertThat(getSession().getResults(Rule.class).size(), is(2));
+    verify();
   }
 
   @Test
index a7761157cb281973be0019634b92806a216429ba..2f3f7dfa4e2705634cafa3fd33f93504740a65f6 100644 (file)
@@ -74,6 +74,7 @@
       <parentKey><![CDATA[test key]]></parentKey>
       <repositoryKey><![CDATA[test plugin]]></repositoryKey>
       <key><![CDATA[test key2]]></key>
+      <configKey><![CDATA[test config key]]></configKey>
       <level><![CDATA[INFO]]></level>
       <name><![CDATA[test name]]></name>
       <description><![CDATA[test description]]></description>
index 37235bd376507b692de49a7fd4f714af411d65b9..37b9a64a06b83ae6d713369aba11046691f0e9c3 100644 (file)
@@ -76,6 +76,7 @@
       <parentKey><![CDATA[test key]]></parentKey>
       <repositoryKey><![CDATA[test plugin]]></repositoryKey>
       <key><![CDATA[test key2]]></key>
+      <configKey><![CDATA[test config key]]></configKey>
       <level><![CDATA[INFO]]></level>
       <name><![CDATA[test name]]></name>
       <description><![CDATA[test description]]></description>