From 54a6901006ec1ec7f498cbb968c47a05e4075937 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Tue, 8 Feb 2011 01:05:56 +0100 Subject: [PATCH] SONAR-726 Add a unit test --- .../configuration/PropertiesBackupTest.java | 21 +++++++++++++++++++ .../backup-with-multiline-property.xml | 19 +++++++++++++++++ .../shouldImportMultilineProperties.xml | 6 ++++++ 3 files changed, 46 insertions(+) create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/backup-with-multiline-property.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportMultilineProperties.xml diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java index 7b6f191a815..2a49a5058c0 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java @@ -20,14 +20,20 @@ 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 index 00000000000..3d577e3f4ab --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/backup-with-multiline-property.xml @@ -0,0 +1,19 @@ + + + + + + + + + JBJk2Ke7ZrTZvmO00u366sv9IY + rqqMuWRPpRNNRompPqrtwqnoPpMoqqprMrVVvVXXVtVppQ + RrnmqmUUnorrvrtommmmmUCasdaswommmmmUUJlkXoUUn + mmmm]]> + + + + + + \ 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 index 00000000000..7c6403b5e4a --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/PropertiesBackupTest/shouldImportMultilineProperties.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file -- 2.39.5