aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/test
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-12-08 16:13:31 +0000
committerGodin <mandrikov@gmail.com>2010-12-08 16:13:31 +0000
commite72a923c48b7a428f2d43c105a4d72cb0a289546 (patch)
tree10250bf53ac4e8cdce178d228168cb6d2aad3905 /sonar-server/src/test
parentee3e40b22465e90477a772d5222ea7bf8e858060 (diff)
downloadsonarqube-e72a923c48b7a428f2d43c105a4d72cb0a289546.tar.gz
sonarqube-e72a923c48b7a428f2d43c105a4d72cb0a289546.zip
SONAR-1987: Improve test
Diffstat (limited to 'sonar-server/src/test')
-rw-r--r--sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java41
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-valid.xml17
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-valid.xml17
3 files changed, 68 insertions, 7 deletions
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 6b28a22366e..0e008fe8362 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,6 +19,7 @@
*/
package org.sonar.server.configuration;
+import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.CharEncoding;
@@ -30,10 +31,7 @@ import org.sonar.api.database.configuration.Property;
import org.sonar.api.measures.Metric;
import org.sonar.api.profiles.Alert;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.ActiveRuleParam;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RulePriority;
+import org.sonar.api.rules.*;
import java.io.IOException;
import java.io.InputStream;
@@ -42,10 +40,11 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -66,11 +65,12 @@ public class BackupTest {
@Test
public void shouldReturnAValidXml() throws Exception {
Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null),
- new ProfilesBackup((DatabaseSession) null)));
+ new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null)));
SonarConfig sonarConfig = getSonarConfig();
sonarConfig.setMetrics(getMetrics());
sonarConfig.setProperties(getProperties());
sonarConfig.setProfiles(getProfiles());
+ sonarConfig.setRules(getUserRules());
String xml = backup.getXmlFromSonarConfig(sonarConfig);
assertXmlAreSimilar(xml, "backup-valid.xml");
@@ -99,7 +99,7 @@ public class BackupTest {
@Test
public void shouldImportXml() {
Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null),
- new ProfilesBackup((DatabaseSession) null)));
+ new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null)));
String xml = getFileFromClasspath("backup-restore-valid.xml");
SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml);
@@ -141,6 +141,21 @@ public class BackupTest {
assertEquals("testWarn", testAlert.getValueWarning());
assertNotNull(testAlert.getMetric());
assertEquals("test key", testAlert.getMetric().getKey());
+
+ Collection<Rule> rules = sonarConfig.getRules();
+ assertThat(rules.size(), is(1));
+ Rule rule = rules.iterator().next();
+ assertThat(rule.getParent().getRepositoryKey(), is("test plugin"));
+ assertThat(rule.getParent().getKey(), is("test key"));
+ assertThat(rule.getRepositoryKey(), is("test plugin"));
+ assertThat(rule.getKey(), is("test key2"));
+ assertThat(rule.getName(), is("test name"));
+ assertThat(rule.getDescription(), is("test description"));
+ assertThat(rule.getSeverity(), is(RulePriority.INFO));
+ assertThat(rule.getParams().size(), is(1));
+ RuleParam param = rule.getParams().get(0);
+ assertThat(param.getKey(), is("test param key"));
+ assertThat(param.getDefaultValue(), is("test param value"));
}
@Test
@@ -244,6 +259,18 @@ public class BackupTest {
return profiles;
}
+ private List<Rule> getUserRules() {
+ List<Rule> rules = Lists.newArrayList();
+ Rule parentRule = Rule.create("test plugin", "test key", null);
+ Rule rule = Rule.create("test plugin", "test key2", "test name")
+ .setDescription("test description")
+ .setSeverity(RulePriority.INFO)
+ .setParent(parentRule);
+ rule.createParameter().setKey("test param key").setDefaultValue("test param value");
+ rules.add(rule);
+ return rules;
+ }
+
private List<Property> getProperties() {
List<Property> properties = new ArrayList<Property>();
properties.add(new Property("key1", "value1"));
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-valid.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-valid.xml
index a18ba48b425..a7761157cb2 100644
--- a/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-valid.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-valid.xml
@@ -68,4 +68,21 @@
<alerts/>
</profile>
</profiles>
+ <rules>
+ <rule>
+ <parentRepositoryKey><![CDATA[test plugin]]></parentRepositoryKey>
+ <parentKey><![CDATA[test key]]></parentKey>
+ <repositoryKey><![CDATA[test plugin]]></repositoryKey>
+ <key><![CDATA[test key2]]></key>
+ <level><![CDATA[INFO]]></level>
+ <name><![CDATA[test name]]></name>
+ <description><![CDATA[test description]]></description>
+ <params>
+ <param>
+ <key><![CDATA[test param key]]></key>
+ <value><![CDATA[test param value]]></value>
+ </param>
+ </params>
+ </rule>
+ </rules>
</sonar-config>
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-valid.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-valid.xml
index 2ab59320a07..37235bd3765 100644
--- a/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-valid.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-valid.xml
@@ -70,4 +70,21 @@
<alerts/>
</profile>
</profiles>
+ <rules>
+ <rule>
+ <parentRepositoryKey><![CDATA[test plugin]]></parentRepositoryKey>
+ <parentKey><![CDATA[test key]]></parentKey>
+ <repositoryKey><![CDATA[test plugin]]></repositoryKey>
+ <key><![CDATA[test key2]]></key>
+ <level><![CDATA[INFO]]></level>
+ <name><![CDATA[test name]]></name>
+ <description><![CDATA[test description]]></description>
+ <params>
+ <param>
+ <key><![CDATA[test param key]]></key>
+ <value><![CDATA[test param value]]></value>
+ </param>
+ </params>
+ </rule>
+ </rules>
</sonar-config>