]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2347 Update the "updated_at" column when closing reviews
authorFabrice Bellingard <bellingard@gmail.com>
Tue, 17 May 2011 10:21:06 +0000 (12:21 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Tue, 17 May 2011 10:21:06 +0000 (12:21 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest.java
plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest/shouldCloseReviewWithoutCorrespondingViolation-result.xml
sonar-testing-harness/src/main/java/org/sonar/test/persistence/DatabaseTestCase.java

index b46108b884030b578e133e7179f0676bf218ec63..e24e5c1289ed9fe306a0f6925b2732eb6b2900d6 100644 (file)
@@ -66,7 +66,7 @@ public class CloseReviewsDecorator implements Decorator {
   }
 
   String generateSqlRequest(int resourceId, int snapshotId) {
-    return "UPDATE reviews SET status='CLOSED' WHERE resource_id = " + resourceId + " AND rule_failure_permanent_id NOT IN "
+    return "UPDATE reviews SET status='CLOSED', updated_at=CURRENT_TIMESTAMP WHERE resource_id = " + resourceId + " AND rule_failure_permanent_id NOT IN "
         + "(SELECT permanent_id FROM rule_failures WHERE snapshot_id = " + snapshotId + " AND permanent_id IS NOT NULL)";
   }
 
index 493352c114766c13669edd9b075b19879896900f..ea6d4a19aea3d146b4ba25cdffc7ac0367e4c4e0 100644 (file)
@@ -21,9 +21,12 @@ package org.sonar.plugins.core.sensors;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
 
 import java.sql.Statement;
 
+import junit.framework.ComparisonFailure;
+
 import org.junit.Test;
 import org.sonar.test.persistence.DatabaseTestCase;
 
@@ -35,11 +38,18 @@ public class CloseReviewsDecoratorTest extends DatabaseTestCase {
 
     CloseReviewsDecorator reviewsDecorator = new CloseReviewsDecorator(null, null);
     String sqlRequest = reviewsDecorator.generateSqlRequest(666, 222);
-    
+
     Statement stmt = getConnection().createStatement();
     int count = stmt.executeUpdate(sqlRequest);
 
     assertThat(count, is(1));
-    assertTables("shouldCloseReviewWithoutCorrespondingViolation", "reviews");
+    assertTables("shouldCloseReviewWithoutCorrespondingViolation", new String[] { "reviews" }, new String[] { "updated_at" });
+
+    try {
+      assertTables("shouldCloseReviewWithoutCorrespondingViolation", new String[] { "reviews" });
+      fail("'updated_at' columns are identical whereas they should be different.");
+    } catch (ComparisonFailure e) {
+      // "updated_at" column must be different, so the comparison should raise this exception
+    }
   }
 }
index d46429ddf3d3fef97942e6da51fd46b095a488e6..db7bf76f0e01a23967d9f22cc4611c0232778379 100644 (file)
@@ -5,18 +5,18 @@
                        status="OPEN"
                        rule_failure_permanent_id="1"
                        resource_id="555"
-                       created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/>
+                       created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
   <reviews
                        id="2"
                        status="CLOSED"
                        rule_failure_permanent_id="2"
                        resource_id="666"
-                       created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/>
+                       created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
   <reviews
                        id="3"
                        status="OPEN"
                        rule_failure_permanent_id="3"
                        resource_id="666"
-                       created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]"/>
+                       created_at="[null]" updated_at="[null]" user_id="[null]" assignee_id="[null]" title="[null]" review_type="[null]" severity="[null]" resource_line="[null]" project_id="[null]"/>
 
 </dataset>
\ No newline at end of file
index ba9e47b6e76133e89a8789404740ed1b1476f191..7c8d4543d6c0256488d854e0b3056abac3ae3931 100644 (file)
@@ -196,6 +196,20 @@ public abstract class DatabaseTestCase {
     }
   }
 
+  protected final void assertTables(String testName, String[] tables, String[] ignoreCols) {
+    try {
+      IDataSet dataSet = getCurrentDataSet();
+      IDataSet expectedDataSet = getExpectedData(testName);
+      for (String table : tables) {
+        Assertion.assertEqualsIgnoreCols(expectedDataSet.getTable(table), dataSet.getTable(table), ignoreCols);
+      }
+    } catch (DataSetException e) {
+      throw translateException("Error while checking results", e);
+    } catch (DatabaseUnitException e) {
+      fail(e.getMessage());
+    }
+  }
+
   protected final void assertEmptyTables(String... emptyTables) {
     for (String table : emptyTables) {
       try {