From 9bf3be187a4893ad424eb09e3cd3c8e7c54f06d6 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 16 Jul 2012 09:50:56 +0200 Subject: [PATCH] Try to fix postgresql unit test --- .../sonar/core/properties/PropertiesDao.java | 1 - .../core/properties/PropertiesDaoTest.java | 23 +++++++++++-------- .../insertGlobalProperties-result.xml | 5 ++++ .../insertGlobalProperties.xml | 3 +++ .../saveGlobalProperties-result.xml | 18 --------------- .../updateGlobalProperties-result.xml | 12 ++++++++++ ...perties.xml => updateGlobalProperties.xml} | 3 --- 7 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/insertGlobalProperties-result.xml create mode 100644 sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/insertGlobalProperties.xml delete mode 100644 sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties-result.xml create mode 100644 sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties-result.xml rename sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/{saveGlobalProperties.xml => updateGlobalProperties.xml} (78%) diff --git a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java index 7dfab47df1e..a496d826fc6 100644 --- a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java +++ b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java @@ -122,7 +122,6 @@ public class PropertiesDao implements BatchComponent, ServerComponent { for (Map.Entry entry : properties.entrySet()) { mapper.deleteGlobalProperty(entry.getKey()); } - session.commit();//required for postgresql bulk inserts (?) for (Map.Entry entry : properties.entrySet()) { mapper.insert(new PropertyDto().setKey(entry.getKey()).setValue(entry.getValue())); } diff --git a/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java b/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java index 6fef82d9fd7..6e7ad7fffa7 100644 --- a/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java @@ -19,13 +19,12 @@ */ package org.sonar.core.properties; -import com.google.common.collect.Maps; +import com.google.common.collect.ImmutableMap; import org.junit.Before; import org.junit.Test; import org.sonar.core.persistence.AbstractDaoTestCase; import java.util.List; -import java.util.TreeMap; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.is; @@ -116,15 +115,21 @@ public class PropertiesDaoTest extends AbstractDaoTestCase { } @Test - public void saveGlobalProperties() { - setupData("saveGlobalProperties"); + public void insertGlobalProperties() { + setupData("insertGlobalProperties"); - TreeMap props = Maps.newTreeMap(); - props.put("to_be_inserted", "inserted"); - props.put("to_be_updated", "updated"); - dao.saveGlobalProperties(props); + dao.saveGlobalProperties(ImmutableMap.of("to_be_inserted", "inserted")); - checkTable("saveGlobalProperties", "properties", "prop_key", "text_value", "resource_id", "user_id"); + checkTable("insertGlobalProperties", "properties", "prop_key", "text_value", "resource_id", "user_id"); + } + + @Test + public void updateGlobalProperties() { + setupData("updateGlobalProperties"); + + dao.saveGlobalProperties(ImmutableMap.of("to_be_updated", "updated")); + + checkTable("updateGlobalProperties", "properties", "prop_key", "text_value", "resource_id", "user_id"); } private PropertyDto findById(List properties, int id) { diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/insertGlobalProperties-result.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/insertGlobalProperties-result.xml new file mode 100644 index 00000000000..5594180c370 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/insertGlobalProperties-result.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/insertGlobalProperties.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/insertGlobalProperties.xml new file mode 100644 index 00000000000..871dedcb5e9 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/insertGlobalProperties.xml @@ -0,0 +1,3 @@ + + + diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties-result.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties-result.xml deleted file mode 100644 index f12984a944b..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties-result.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties-result.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties-result.xml new file mode 100644 index 00000000000..c873ec3bd76 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties-result.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties.xml similarity index 78% rename from sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties.xml rename to sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties.xml index b0fa0be6deb..43cdd8c7d10 100644 --- a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties.xml +++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties.xml @@ -7,7 +7,4 @@ - - - -- 2.39.5