}
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)";
}
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;
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
+ }
}
}
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
}
}
+ 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 {