]> source.dussan.org Git - sonarqube.git/commitdiff
Try to fix postgresql unit test
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 16 Jul 2012 07:50:56 +0000 (09:50 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 16 Jul 2012 07:50:56 +0000 (09:50 +0200)
sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java
sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/insertGlobalProperties-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/insertGlobalProperties.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties.xml [new file with mode: 0644]

index 7dfab47df1ed898928d913c3515337ebe57c857b..a496d826fc68e535908417fb4968f1895193d25c 100644 (file)
@@ -122,7 +122,6 @@ public class PropertiesDao implements BatchComponent, ServerComponent {
       for (Map.Entry<String, String> entry : properties.entrySet()) {
         mapper.deleteGlobalProperty(entry.getKey());
       }
-      session.commit();//required for postgresql bulk inserts (?)
       for (Map.Entry<String, String> entry : properties.entrySet()) {
         mapper.insert(new PropertyDto().setKey(entry.getKey()).setValue(entry.getValue()));
       }
index 6fef82d9fd76188b33b70d56a09e0ee20d98c5e8..6e7ad7fffa7f278e050129e8b724e2b64d57096e 100644 (file)
  */
 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<String, String> 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<PropertyDto> 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 (file)
index 0000000..5594180
--- /dev/null
@@ -0,0 +1,5 @@
+<dataset>
+
+  <properties prop_key="to_be_inserted" text_value="inserted" resource_id="[null]" user_id="[null]"/>
+
+</dataset>
\ 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 (file)
index 0000000..871dedc
--- /dev/null
@@ -0,0 +1,3 @@
+<dataset>
+
+</dataset>
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 (file)
index f12984a..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<dataset>
-
-  <!-- global -->
-  <!--<properties id="1" prop_key="to_be_updated" text_value="old value" resource_id="[null]" user_id="[null]"/>-->
-  <properties id="2" prop_key="to_not_change" text_value="xxx" resource_id="[null]" user_id="[null]"/>
-
-  <!-- project - do not update this project property that has the same key -->
-  <properties id="3" prop_key="to_be_updated" text_value="new_project" resource_id="10" user_id="[null]"/>
-
-  <!-- user -->
-  <properties id="4" prop_key="user.key" text_value="new_user" resource_id="[null]" user_id="100"/>
-
-
-  <properties id="5" prop_key="to_be_inserted" text_value="inserted" resource_id="[null]" user_id="[null]"/>
-  <properties id="6" prop_key="to_be_updated" text_value="updated" resource_id="[null]" user_id="[null]"/>
-
-
-</dataset>
\ No newline at end of file
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/saveGlobalProperties.xml
deleted file mode 100644 (file)
index b0fa0be..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
-  <!-- global -->
-  <properties id="1" prop_key="to_be_updated" text_value="old value" resource_id="[null]" user_id="[null]"/>
-  <properties id="2" prop_key="to_not_change" text_value="xxx" resource_id="[null]" user_id="[null]"/>
-
-  <!-- project - do not update this project property that has the same key -->
-  <properties id="3" prop_key="to_be_updated" text_value="new_project" resource_id="10" user_id="[null]"/>
-
-  <!-- user -->
-  <properties id="4" prop_key="user.key" text_value="new_user" resource_id="[null]" user_id="100"/>
-
-</dataset>
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 (file)
index 0000000..c873ec3
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+
+  <!-- global -->
+  <!--<properties prop_key="to_be_updated" text_value="old value" resource_id="[null]" user_id="[null]"/>-->
+  <properties prop_key="to_not_change" text_value="xxx" resource_id="[null]" user_id="[null]"/>
+
+  <!-- project - do not update this project property that has the same key -->
+  <properties prop_key="to_be_updated" text_value="new_project" resource_id="10" user_id="[null]"/>
+
+
+  <properties prop_key="to_be_updated" text_value="updated" resource_id="[null]" user_id="[null]"/>
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/updateGlobalProperties.xml
new file mode 100644 (file)
index 0000000..43cdd8c
--- /dev/null
@@ -0,0 +1,10 @@
+<dataset>
+
+  <!-- global -->
+  <properties id="1" prop_key="to_be_updated" text_value="old value" resource_id="[null]" user_id="[null]"/>
+  <properties id="2" prop_key="to_not_change" text_value="xxx" resource_id="[null]" user_id="[null]"/>
+
+  <!-- project - do not update this project property that has the same key -->
+  <properties id="3" prop_key="to_be_updated" text_value="new_project" resource_id="10" user_id="[null]"/>
+
+</dataset>