"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());
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());
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")));
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));
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");
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));
@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
<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>
<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>