From ab91e0d0fad3ef5dfea26f601f6943a376896ef3 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Tue, 17 May 2011 12:21:06 +0200 Subject: [PATCH] SONAR-2347 Update the "updated_at" column when closing reviews --- .../core/sensors/CloseReviewsDecorator.java | 2 +- .../core/sensors/CloseReviewsDecoratorTest.java | 14 ++++++++++++-- ...eReviewWithoutCorrespondingViolation-result.xml | 6 +++--- .../sonar/test/persistence/DatabaseTestCase.java | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java index b46108b8840..e24e5c1289e 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java @@ -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)"; } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest.java index 493352c1147..ea6d4a19aea 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest.java @@ -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 + } } } diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest/shouldCloseReviewWithoutCorrespondingViolation-result.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest/shouldCloseReviewWithoutCorrespondingViolation-result.xml index d46429ddf3d..db7bf76f0e0 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest/shouldCloseReviewWithoutCorrespondingViolation-result.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/CloseReviewsDecoratorTest/shouldCloseReviewWithoutCorrespondingViolation-result.xml @@ -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]"/> + 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]"/> + 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]"/> \ No newline at end of file diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/persistence/DatabaseTestCase.java b/sonar-testing-harness/src/main/java/org/sonar/test/persistence/DatabaseTestCase.java index ba9e47b6e76..7c8d4543d6c 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/persistence/DatabaseTestCase.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/persistence/DatabaseTestCase.java @@ -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 { -- 2.39.5