aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-12-07 13:22:58 +0000
committerGodin <mandrikov@gmail.com>2010-12-07 13:22:58 +0000
commit1045ca4608b9d9d5627fc2ec022e0b9532e6972a (patch)
tree92b62329a2a09754df1c82e62edaad96acb5cdf9 /sonar-server
parenta02e4a3754fd80a0ee47fa1349e017d1da1aec59 (diff)
downloadsonarqube-1045ca4608b9d9d5627fc2ec022e0b9532e6972a.tar.gz
sonarqube-1045ca4608b9d9d5627fc2ec022e0b9532e6972a.zip
SONAR-1819: Ignore id of metric during restore backup
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/configuration/MetricsBackup.java3
-rw-r--r--sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java18
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-with-id-for-metrics.xml18
3 files changed, 36 insertions, 3 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/MetricsBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/MetricsBackup.java
index 41f838a22a3..1fc7fd5c24b 100644
--- a/sonar-server/src/main/java/org/sonar/server/configuration/MetricsBackup.java
+++ b/sonar-server/src/main/java/org/sonar/server/configuration/MetricsBackup.java
@@ -26,8 +26,8 @@ import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import org.sonar.api.database.DatabaseSession;
-import org.sonar.jpa.dao.MeasuresDao;
import org.sonar.api.measures.Metric;
+import org.sonar.jpa.dao.MeasuresDao;
import java.util.Collection;
@@ -80,6 +80,7 @@ public class MetricsBackup implements Backupable {
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
Metric unmarshalled = (Metric) builtIn.unmarshal(reader, context);
+ unmarshalled.setId(null); // See http://jira.codehaus.org/browse/SONAR-1819
unmarshalled.setUserManaged(true);
unmarshalled.setEnabled(true);
return unmarshalled;
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 dcc13131cf4..07d86fce8e6 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
@@ -39,7 +39,11 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
-import static org.junit.Assert.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -166,11 +170,21 @@ public class BackupTest {
assertTrue(CollectionUtils.isEqualCollection(sonarConfig.getProperties(), getPropertiesWithUtf8Characters()));
}
+ @Test
+ public void shouldNotImportMetricIds() {
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null)));
+
+ String xml = getFileFromClasspath("backup-with-id-for-metrics.xml");
+ SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml);
+
+ Metric metric = sonarConfig.getMetrics().iterator().next();
+ assertThat(metric.getId(), nullValue());
+ }
+
private SonarConfig getSonarConfig() throws ParseException {
DateFormat dateFormat = new SimpleDateFormat(Backup.DATE_FORMAT);
Date date = dateFormat.parse("2008-11-18");
return new SonarConfig(54, date);
-
}
private List<Metric> getMetrics() {
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-with-id-for-metrics.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-with-id-for-metrics.xml
new file mode 100644
index 00000000000..7d201084514
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-with-id-for-metrics.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sonar-config>
+ <version><![CDATA[92]]></version>
+ <date><![CDATA[2010-09-27]]></date>
+ <metrics>
+ <metric>
+ <id><![CDATA[68]]></id>
+ <key><![CDATA[team_velocity]]></key>
+ <description><![CDATA[The team's velocity during one sprint. Measured at sprint ending (completed SP).]]></description>
+ <type><![CDATA[INT]]></type>
+ <direction><![CDATA[0]]></direction>
+ <domain><![CDATA[Management]]></domain>
+ <name><![CDATA[Team Velocity]]></name>
+ <qualitative><![CDATA[false]]></qualitative>
+ <origin><![CDATA[GUI]]></origin>
+ </metric>
+ </metrics>
+</sonar-config>