diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-03-31 18:30:41 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-03-31 18:32:16 +0200 |
commit | 22ae199fb6c1e162ccf5be8e45794ab00c85ddbb (patch) | |
tree | 2b17e8c41592d6d91d440bb9a4bcd40a791b2e7b /server | |
parent | 4d6f98c25cb492e3b6059d7edd8dffa07cf2a168 (diff) | |
download | sonarqube-22ae199fb6c1e162ccf5be8e45794ab00c85ddbb.tar.gz sonarqube-22ae199fb6c1e162ccf5be8e45794ab00c85ddbb.zip |
Fix some tests failing on none GMT+1 timezone
Diffstat (limited to 'server')
8 files changed, 131 insertions, 36 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java index fc6aa2d0f2c..03ad53ab61c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java @@ -142,10 +142,10 @@ public class FeedFileSources extends BaseDataChange { "AND fs.file_uuid IS NULL"; private static final class FileSourceBuilder implements MassUpdate.Handler { - private final Date now; + private final long now; public FileSourceBuilder(System2 system) { - now = new Date(system.now()); + now = system.now(); } @Override @@ -199,8 +199,8 @@ public class FeedFileSources extends BaseDataChange { update.setString(1, projectUuid) .setString(2, fileUuid) - .setLong(3, now.getTime()) - .setLong(4, (updatedAt == null ? now : updatedAt).getTime()) + .setLong(3, now) + .setLong(4, updatedAt == null ? now : updatedAt.getTime()) .setString(5, sourceData[0]) .setString(6, sourceData[1]) .setString(7, ""); diff --git a/server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityResultSetIteratorTest.java index b2d8b6b064b..b52b4fabc2e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityResultSetIteratorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityResultSetIteratorTest.java @@ -80,7 +80,7 @@ public class ActivityResultSetIteratorTest { assertThat(it.hasNext()).isFalse(); it.close(); - assertThat(it.getMaxRowDate()).isEqualTo(1420066800000L); + assertThat(formatLongDate(it.getMaxRowDate())).startsWith("2015-01-01"); } @Test @@ -97,7 +97,7 @@ public class ActivityResultSetIteratorTest { assertThat(it.hasNext()).isFalse(); it.close(); - assertThat(it.getMaxRowDate()).isEqualTo(1420066800000L); + assertThat(formatLongDate(it.getMaxRowDate())).startsWith("2015-01-01"); } @Test @@ -110,4 +110,8 @@ public class ActivityResultSetIteratorTest { assertThat(it.getMaxRowDate()).isEqualTo(0L); } + + private String formatLongDate(long dateInMs) { + return DateUtils.formatDateTime(DateUtils.longToDate(dateInMs)); + } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationTest.java index b4c30d3a9d6..2230437771c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationTest.java @@ -32,6 +32,10 @@ import org.sonar.core.persistence.DbTester; import org.sonar.core.properties.PropertiesDao; import org.sonar.core.properties.PropertyDto; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -62,7 +66,17 @@ public class ConvertIssueDebtToMinutesMigrationTest { migration.execute(); - db.assertDbUnit(getClass(), "migrate_issues_debt_result.xml", "issues"); + db.assertDbUnit(getClass(), "migrate_issues_debt_result.xml", new String[] {"updated_at"}, "issues"); + + // Check only updated_at columns values, but we could also remove db unit file and check all fields + List<Map<String, Object>> results = db.select("select updated_at as \"updatedAt\" from issues"); + assertThat(results).hasSize(5); + assertThat(results.get(0).get("updatedAt").toString()).startsWith("2014-02-19"); + assertThat(results.get(1).get("updatedAt").toString()).startsWith("2014-02-19"); + assertThat(results.get(2).get("updatedAt").toString()).startsWith("2014-02-19"); + assertThat(results.get(3).get("updatedAt").toString()).startsWith("2014-02-19"); + // Not updated because no debt + assertThat(results.get(4).get("updatedAt").toString()).startsWith("2012-01-05"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java index 9607166b22d..1434e2c11cb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java @@ -31,8 +31,10 @@ import org.sonar.core.persistence.DbTester; import java.sql.Connection; import java.sql.PreparedStatement; -import java.util.Date; +import java.util.List; +import java.util.Map; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -41,6 +43,8 @@ public class FeedFileSourcesTest { @ClassRule public static DbTester db = new DbTester().schema(FeedFileSourcesTest.class, "schema.sql"); + private static final long NOW = 1414770242000L; + FeedFileSources migration; System2 system; @@ -55,8 +59,7 @@ public class FeedFileSourcesTest { db.executeUpdateSql("truncate table file_sources"); system = mock(System2.class); - Date now = DateUtils.parseDateTime("2014-11-17T16:27:00+0100"); - when(system.now()).thenReturn(now.getTime()); + when(system.now()).thenReturn(NOW); migration = new FeedFileSources(db.database(), system); } @@ -81,7 +84,25 @@ public class FeedFileSourcesTest { migration.execute(); - db.assertDbUnit(getClass(), "after.xml", "file_sources"); + List<Map<String, Object>> results = db.select("select project_uuid as \"projectUuid\", file_uuid as \"fileUuid\", created_at as \"createdAt\", " + + "updated_at as \"updatedAt\", data as \"data\", data as \"data\", line_hashes as \"lineHashes\", data_hash as \"dataHash\" from file_sources"); + assertThat(results).hasSize(2); + + assertThat(results.get(0).get("projectUuid")).isEqualTo("uuid-MyProject"); + assertThat(results.get(0).get("fileUuid")).isEqualTo("uuid-Migrated.xoo"); + assertThat(results.get(0).get("data")).isEqualTo(""); + assertThat(results.get(0).get("lineHashes")).isEqualTo(""); + assertThat(results.get(0).get("dataHash")).isEqualTo(""); + assertThat(results.get(0).get("updatedAt")).isEqualTo(NOW); + assertThat(results.get(0).get("createdAt")).isEqualTo(1416238020000L); + + assertThat(results.get(1).get("projectUuid")).isEqualTo("uuid-MyProject"); + assertThat(results.get(1).get("fileUuid")).isEqualTo("uuid-MyFile.xoo"); + assertThat(results.get(1).get("data")).isEqualTo(",,,,,,,,,,,,,,,class Foo {\r\n,,,,,,,,,,,,,,, // Empty\r\n,,,,,,,,,,,,,,,}\r\n,,,,,,,,,,,,,,,\r\n"); + assertThat(results.get(1).get("lineHashes")).isEqualTo("6a19ce786467960a3a9b0d26383a464a\naab2dbc5fdeaa80b050b1d049ede357c\ncbb184dd8e05c9709e5dcaedaa0495cf\n\n"); + assertThat(results.get(1).get("dataHash")).isEqualTo(""); + assertThat(formatLongDate((long) results.get(1).get("updatedAt")).toString()).startsWith("2014-10-31"); + assertThat(results.get(1).get("createdAt")).isEqualTo(NOW); } @Test @@ -212,7 +233,27 @@ public class FeedFileSourcesTest { migration.execute(); - db.assertDbUnit(getClass(), "after-with-scm.xml", "file_sources"); + List<Map<String, Object>> results = db.select("select project_uuid as \"projectUuid\", file_uuid as \"fileUuid\", created_at as \"createdAt\", " + + "updated_at as \"updatedAt\", data as \"data\", data as \"data\", line_hashes as \"lineHashes\", data_hash as \"dataHash\" from file_sources"); + assertThat(results).hasSize(2); + + assertThat(results.get(0).get("projectUuid")).isEqualTo("uuid-MyProject"); + assertThat(results.get(0).get("fileUuid")).isEqualTo("uuid-Migrated.xoo"); + assertThat(results.get(0).get("data")).isEqualTo(""); + assertThat(results.get(0).get("lineHashes")).isEqualTo(""); + assertThat(results.get(0).get("dataHash")).isEqualTo(""); + assertThat(results.get(0).get("updatedAt")).isEqualTo(NOW); + assertThat(results.get(0).get("createdAt")).isEqualTo(1416238020000L); + + assertThat(results.get(1).get("projectUuid")).isEqualTo("uuid-MyProject"); + assertThat(results.get(1).get("fileUuid")).isEqualTo("uuid-MyFile.xoo"); + assertThat(results.get(1).get("data")).isEqualTo( + "aef12a,alice,2014-04-25T12:34:56+0100,1,4,2,2,5,3,3,6,4,,,1,class Foo {\r\nabe465,bob,2014-07-25T12:34:56+0100,,,,,,,,,,,,2, " + + "// Empty\r\nafb789,carol,2014-03-23T12:34:56+0100,0,,,0,,,0,,,,,,}\r\nafb789,carol,2014-03-23T12:34:56+0100,,,,,,,,,,,,,\r\n"); + assertThat(results.get(1).get("lineHashes")).isEqualTo("6a19ce786467960a3a9b0d26383a464a\naab2dbc5fdeaa80b050b1d049ede357c\ncbb184dd8e05c9709e5dcaedaa0495cf\n\n"); + assertThat(results.get(1).get("dataHash")).isEqualTo(""); + assertThat(formatLongDate((long) results.get(1).get("updatedAt")).toString()).startsWith("2014-10-31"); + assertThat(results.get(1).get("createdAt")).isEqualTo(NOW); } @Test @@ -250,6 +291,30 @@ public class FeedFileSourcesTest { migration.execute(); - db.assertDbUnit(getClass(), "after-with-invalid-duplication.xml", "file_sources"); + // db.assertDbUnit(getClass(), "after-with-invalid-duplication.xml", "file_sources"); + + List<Map<String, Object>> results = db.select("select project_uuid as \"projectUuid\", file_uuid as \"fileUuid\", created_at as \"createdAt\", " + + "updated_at as \"updatedAt\", data as \"data\", data as \"data\", line_hashes as \"lineHashes\", data_hash as \"dataHash\" from file_sources"); + assertThat(results).hasSize(2); + + assertThat(results.get(0).get("projectUuid")).isEqualTo("uuid-MyProject"); + assertThat(results.get(0).get("fileUuid")).isEqualTo("uuid-Migrated.xoo"); + assertThat(results.get(0).get("data")).isEqualTo(""); + assertThat(results.get(0).get("lineHashes")).isEqualTo(""); + assertThat(results.get(0).get("dataHash")).isEqualTo(""); + assertThat(results.get(0).get("updatedAt")).isEqualTo(NOW); + assertThat(results.get(0).get("createdAt")).isEqualTo(1416238020000L); + + assertThat(results.get(1).get("projectUuid")).isEqualTo("uuid-MyProject"); + assertThat(results.get(1).get("fileUuid")).isEqualTo("uuid-MyFile.xoo"); + assertThat(results.get(1).get("data")).isEqualTo(",,,,,,,,,,,,,,,class Foo {\r\n,,,,,,,,,,,,,,, // Empty\r\n,,,,,,,,,,,,,,,}\r\n,,,,,,,,,,,,,,,\r\n"); + assertThat(results.get(1).get("lineHashes")).isEqualTo("6a19ce786467960a3a9b0d26383a464a\naab2dbc5fdeaa80b050b1d049ede357c\ncbb184dd8e05c9709e5dcaedaa0495cf\n\n"); + assertThat(results.get(1).get("dataHash")).isEqualTo(""); + assertThat(formatLongDate((long) results.get(1).get("updatedAt")).toString()).startsWith("2014-10-31"); + assertThat(results.get(1).get("createdAt")).isEqualTo(NOW); + } + + private String formatLongDate(long dateInMs) { + return DateUtils.formatDateTime(DateUtils.longToDate(dateInMs)); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java index 6e7ee3749d3..2dca1fa5b79 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java @@ -87,8 +87,8 @@ public class SearchActionComponentsMediumTest { .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") .setStatus("OPEN").setResolution("OPEN") .setSeverity("MAJOR") - .setIssueCreationDate(DateUtils.parseDate("2014-09-04")) - .setIssueUpdateDate(DateUtils.parseDate("2017-12-04")); + .setIssueCreationDate(DateUtils.parseDateTime("2014-09-04T00:00:00+0100")) + .setIssueUpdateDate(DateUtils.parseDateTime("2017-12-04T00:00:00+0100")); db.issueDao().insert(session, issue); ComponentDto project2 = insertComponent(ComponentTesting.newProjectDto("DBCA").setKey("MyProject2")); @@ -98,8 +98,8 @@ public class SearchActionComponentsMediumTest { .setKee("92fd47d4-b650-4037-80bc-7b112bd4eac2") .setStatus("OPEN").setResolution("OPEN") .setSeverity("MAJOR") - .setIssueCreationDate(DateUtils.parseDate("2014-09-04")) - .setIssueUpdateDate(DateUtils.parseDate("2017-12-04")); + .setIssueCreationDate(DateUtils.parseDateTime("2014-09-04T00:00:00+0100")) + .setIssueUpdateDate(DateUtils.parseDateTime("2017-12-04T00:00:00+0100")); db.issueDao().insert(session, issue2); session.commit(); tester.get(IssueIndexer.class).indexAll(); @@ -488,7 +488,6 @@ public class SearchActionComponentsMediumTest { IssueDto issue1 = IssueTesting.newDto(newRule, file, project).setAuthorLogin("vader").setKee("2bd4eac2-b650-4037-80bc-7b112bd4eac2"); IssueDto issue2 = IssueTesting.newDto(newRule, file, project).setAuthorLogin("anakin@skywalker.name").setKee("82fd47d4-b650-4037-80bc-7b1182fd47d4"); - db.issueDao().insert(session, issue1, issue2); session.commit(); tester.get(IssueIndexer.class).indexAll(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java index 174005a2ccf..0db8498e682 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java @@ -117,14 +117,13 @@ public class SearchActionMediumTest { .setAssignee("simon") .setReporter("fabrice") .setActionPlanKey("AP-ABCD") - .setIssueCreationDate(DateUtils.parseDate("2014-09-04")) - .setIssueUpdateDate(DateUtils.parseDate("2017-12-04")); + .setIssueCreationDate(DateUtils.parseDateTime("2014-09-04T00:00:00+0100")) + .setIssueUpdateDate(DateUtils.parseDateTime("2017-12-04T00:00:00+0100")); db.issueDao().insert(session, issue); session.commit(); tester.get(IssueIndexer.class).indexAll(); WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute(); - // TODO date assertion is complex to test, and components id are not predictable, that's why strict boolean is set to false result.assertJson(this.getClass(), "issue.json"); } @@ -209,9 +208,9 @@ public class SearchActionMediumTest { .setStatus("OPEN") .setProjectId(project.getId()) .setUserLogin("simon") - .setDeadLine(DateUtils.parseDateTime("2014-01-24T19:10:03+0100")) - .setCreatedAt(DateUtils.parseDateTime("2014-01-22T19:10:03+0100")) - .setUpdatedAt(DateUtils.parseDateTime("2014-01-23T19:10:03+0100"))); + .setDeadLine(DateUtils.parseDateTime("2014-01-24T19:10:03+0000")) + .setCreatedAt(DateUtils.parseDateTime("2014-01-22T19:10:03+0000")) + .setUpdatedAt(DateUtils.parseDateTime("2014-01-23T19:10:03+0000"))); IssueDto issue = IssueTesting.newDto(newRule(), file, project) .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") @@ -285,8 +284,8 @@ public class SearchActionMediumTest { .setComponent(removedFile) .setStatus("OPEN").setResolution("OPEN") .setSeverity("MAJOR") - .setIssueCreationDate(DateUtils.parseDate("2014-09-04")) - .setIssueUpdateDate(DateUtils.parseDate("2017-12-04")); + .setIssueCreationDate(DateUtils.parseDateTime("2014-09-04T00:00:00+0100")) + .setIssueUpdateDate(DateUtils.parseDateTime("2017-12-04T00:00:00+0100")); db.issueDao().insert(session, issue); session.commit(); tester.get(IssueIndexer.class).indexAll(); @@ -573,9 +572,15 @@ public class SearchActionMediumTest { ComponentDto project = insertComponent(ComponentTesting.newProjectDto("ABCD").setKey("MyProject")); setDefaultProjectPermission(project); ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, "BCDE").setKey("MyComponent")); - db.issueDao().insert(session, IssueTesting.newDto(rule, file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac1").setIssueUpdateDate(DateUtils.parseDate("2014-11-02"))); - db.issueDao().insert(session, IssueTesting.newDto(rule, file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2").setIssueUpdateDate(DateUtils.parseDate("2014-11-01"))); - db.issueDao().insert(session, IssueTesting.newDto(rule, file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac3").setIssueUpdateDate(DateUtils.parseDate("2014-11-03"))); + db.issueDao().insert(session, IssueTesting.newDto(rule, file, project) + .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac1") + .setIssueUpdateDate(DateUtils.parseDateTime("2014-11-02T00:00:00+0100"))); + db.issueDao().insert(session, IssueTesting.newDto(rule, file, project) + .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2") + .setIssueUpdateDate(DateUtils.parseDateTime("2014-11-01T00:00:00+0100"))); + db.issueDao().insert(session, IssueTesting.newDto(rule, file, project) + .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac3") + .setIssueUpdateDate(DateUtils.parseDateTime("2014-11-03T00:00:00+0100"))); session.commit(); tester.get(IssueIndexer.class).indexAll(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java index 5469413de01..da1a0aedcf6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java @@ -34,7 +34,10 @@ import org.sonar.server.db.DbClient; import org.sonar.test.DbTests; import java.util.Date; +import java.util.List; +import java.util.Map; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -50,7 +53,15 @@ public class RenameIssueWidgetsTest { doStart(); - dbTester.assertDbUnit(this.getClass(), "after.xml", "widgets", "widget_properties", "loaded_templates"); + dbTester.assertDbUnit(this.getClass(), "after.xml", new String[] {"updated_at"}, "widgets", "widget_properties", "loaded_templates"); + + List<Map<String, Object>> results = dbTester.select("select updated_at as \"updatedAt\" from widgets"); + assertThat(results).hasSize(6); + // First widget is not updated + assertThat(results.get(0).get("updatedAt")).isNull(); + for (int i = 1; i < results.size(); i++) { + assertThat(results.get(i).get("updatedAt").toString()).startsWith("2003-03-23"); + } } @Test diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_action_plan.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_action_plan.json index 878af790fef..67836dba67f 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_action_plan.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_action_plan.json @@ -12,12 +12,9 @@ "status": "OPEN", "project": "MyProject", "userLogin": "simon", - "deadLine": "2014-01-24T19:10:03+0100", - "fDeadLine": "Jan 24, 2014 7:10 PM", - "createdAt": "2014-01-22T19:10:03+0100", - "fCreatedAt": "Jan 22, 2014 7:10 PM", - "updatedAt": "2014-01-23T19:10:03+0100", - "fUpdatedAt": "Jan 23, 2014 7:10 PM" + "deadLine": "2014-01-24T19:10:03+0000", + "createdAt": "2014-01-22T19:10:03+0000", + "updatedAt": "2014-01-23T19:10:03+0000" } ] } |