]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-726 Add a unit test
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 8 Feb 2011 00:05:56 +0000 (01:05 +0100)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 8 Feb 2011 00:05:56 +0000 (01:05 +0100)
sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java
sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/backup-with-multiline-property.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportMultilineProperties.xml [new file with mode: 0644]

index 7b6f191a81593016fb1f7fedf5a02653b038a5ce..2a49a5058c0b5e4852343b169c7a77697cddc592 100644 (file)
 package org.sonar.server.configuration;
 
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.CharEncoding;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.database.configuration.Property;
 import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.test.TestUtils;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.startsWith;
 import static org.hamcrest.collection.IsCollectionContaining.hasItem;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
@@ -87,4 +93,19 @@ public class PropertiesBackupTest extends AbstractDbUnitTestCase {
     checkTables("shouldImportProperties", "properties");
   }
 
+  @Test
+  public void shouldImportMultilineProperties() throws Exception {
+    setupData("shouldImportMultilineProperties");
+
+    new Backup(getSession()).doImportXml(
+        FileUtils.readFileToString(
+            TestUtils.getResource(getClass(), "backup-with-multiline-property.xml"), CharEncoding.UTF_8));
+
+    getSession().commit();
+
+    Property property = getSession().getSingleResult(Property.class, "key", "sonar.multiline.secured");
+    assertThat(property.getValue(), startsWith("ONQwdcwcwwdadalkdmaiQGMqMVnhtAbhxwjjoVkHbWgx"));
+    assertThat(property.getValue(), endsWith("mmmm"));
+
+  }
 }
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/backup-with-multiline-property.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/backup-with-multiline-property.xml
new file mode 100644 (file)
index 0000000..3d577e3
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sonar-config>
+  <version><![CDATA[180]]></version>
+  <date><![CDATA[2011-02-08]]></date>
+  <metrics/>
+  <properties>
+    <property>
+      <key><![CDATA[sonar.multiline.secured]]></key>
+      <value><![CDATA[ONQwdcwcwwdadalkdmaiQGMqMVnhtAbhxwjjoVkHbWgx
+                       mi2KrURzVJmEZQD1l0T>JBJk2Ke7ZrTZvmO00u366sv9IY
+                       rqqMuWRPpRNNRompPqrtwqnoPpMoqqprMrVVvVXXVtVppQ
+                       RrnmqmUUnorrvrtommmmmUCasdaswommmmmUUJlkXoUUn
+                       mmmm]]></value>
+    </property>
+  </properties>
+  <profiles>
+  </profiles>
+  <rules/>
+</sonar-config>
\ No newline at end of file
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportMultilineProperties.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportMultilineProperties.xml
new file mode 100644 (file)
index 0000000..7c6403b
--- /dev/null
@@ -0,0 +1,6 @@
+<dataset>
+  <!-- global properties -->
+  <properties id="1" prop_key="key1" text_value="oldvalue" resource_id="[null]" user_id="[null]"/>
+
+
+</dataset>
\ No newline at end of file