diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-03-19 22:43:47 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-03-20 11:07:25 +0100 |
commit | 12ccd9132e30df9e91e42369dd4af0ee7b2b590d (patch) | |
tree | 412cec3a5bc63c1a10256b2c7be15de5853f3706 /server | |
parent | 3ac5f1a896f947a6dd7128bbe9f80a2db2765abd (diff) | |
download | sonarqube-12ccd9132e30df9e91e42369dd4af0ee7b2b590d.tar.gz sonarqube-12ccd9132e30df9e91e42369dd4af0ee7b2b590d.zip |
Fix coupling of some db tests with local timezone
Diffstat (limited to 'server')
13 files changed, 50 insertions, 101 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java index b434afc2dca..d6c8f06dd75 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java @@ -21,8 +21,6 @@ package org.sonar.server.issue; import com.google.common.base.Objects; import com.google.common.base.Strings; -import com.google.common.collect.HashMultiset; -import com.google.common.collect.Multiset; import org.apache.commons.lang.StringUtils; import org.sonar.api.ServerComponent; import org.sonar.api.issue.ActionPlan; @@ -46,7 +44,6 @@ import org.sonar.core.issue.db.IssueStorage; import org.sonar.core.issue.workflow.IssueWorkflow; import org.sonar.core.issue.workflow.Transition; import org.sonar.core.persistence.DbSession; -import org.sonar.core.rule.RuleDto; import org.sonar.server.db.DbClient; import org.sonar.server.es.SearchOptions; import org.sonar.server.es.SearchResult; @@ -63,8 +60,12 @@ import org.sonar.server.user.index.UserIndex; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; public class IssueService implements ServerComponent { @@ -279,24 +280,6 @@ public class IssueService implements ServerComponent { } } - // TODO result should be replaced by an aggregation object in IssueIndex - public RulesAggregation findRulesByComponent(String componentKey, @Nullable Date periodDate, DbSession session) { - RulesAggregation rulesAggregation = new RulesAggregation(); - for (RuleDto ruleDto : deprecatedIssueDao.findRulesByComponent(componentKey, periodDate, session)) { - rulesAggregation.add(ruleDto); - } - return rulesAggregation; - } - - // TODO result should be replaced by an aggregation object in IssueIndex - public Multiset<String> findSeveritiesByComponent(String componentKey, @Nullable Date periodDate, DbSession session) { - Multiset<String> aggregation = HashMultiset.create(); - for (String severity : deprecatedIssueDao.findSeveritiesByComponent(componentKey, periodDate, session)) { - aggregation.add(severity); - } - return aggregation; - } - public Issue getByKey(String key) { return issueIndex.getByKey(key); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java index 443ad6d6a79..94f8c1ca48b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java @@ -271,11 +271,11 @@ public class SnapshotDaoTest extends AbstractDaoTestCase { .setPeriodParam(3, "32") .setPeriodParam(4, "33") .setPeriodParam(5, "34") - .setPeriodDate(1, DateUtils.parseDate("2011-09-24").getTime()) - .setPeriodDate(2, DateUtils.parseDate("2011-09-25").getTime()) - .setPeriodDate(3, DateUtils.parseDate("2011-09-26").getTime()) - .setPeriodDate(4, DateUtils.parseDate("2011-09-27").getTime()) - .setPeriodDate(5, DateUtils.parseDate("2011-09-28").getTime()) - .setBuildDate(DateUtils.parseDate("2011-09-29").getTime()); + .setPeriodDate(1, 1_500_000_000_001L) + .setPeriodDate(2, 1_500_000_000_002L) + .setPeriodDate(3, 1_500_000_000_003L) + .setPeriodDate(4, 1_500_000_000_004L) + .setPeriodDate(5, 1_500_000_000_005L) + .setBuildDate(1_500_000_000_006L); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java index bf4456f66ab..2b34564c7b1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java @@ -39,7 +39,6 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.sonar.api.utils.DateUtils.parseDate; import static org.sonar.core.computation.db.AnalysisReportDto.Status.PENDING; import static org.sonar.core.computation.db.AnalysisReportDto.Status.WORKING; @@ -64,8 +63,7 @@ public class AnalysisReportDaoTest { this.system2 = mock(System2.class); this.sut = new AnalysisReportDao(system2); - when(system2.now()).thenReturn(parseDate("2014-09-26").getTime()); - when(system2.newDate()).thenReturn(parseDate("2014-09-26")); + when(system2.now()).thenReturn(1_500_000_000_000L); } @After @@ -156,10 +154,10 @@ public class AnalysisReportDaoTest { AnalysisReportDto report = sut.selectById(session, 1L); assertThat(report.getProjectKey()).isEqualTo(DEFAULT_PROJECT_KEY); - assertThat(report.getCreatedAt()).isEqualTo(parseDate("2014-09-24").getTime()); - assertThat(report.getUpdatedAt()).isEqualTo(parseDate("2014-09-25").getTime()); - assertThat(report.getStartedAt()).isEqualTo(parseDate("2014-09-26").getTime()); - assertThat(report.getFinishedAt()).isEqualTo(parseDate("2014-09-27").getTime()); + assertThat(report.getCreatedAt()).isEqualTo(1_500_000_000_001L); + assertThat(report.getUpdatedAt()).isEqualTo(1_500_000_000_002L); + assertThat(report.getStartedAt()).isEqualTo(1_500_000_000_003L); + assertThat(report.getFinishedAt()).isEqualTo(1_500_000_000_004L); assertThat(report.getStatus()).isEqualTo(WORKING); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java index 8f9f5730607..911581eec05 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java @@ -21,7 +21,6 @@ package org.sonar.server.issue; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterators; -import com.google.common.collect.Multiset; import com.google.common.collect.Sets; import org.junit.After; import org.junit.Before; @@ -457,36 +456,6 @@ public class IssueServiceMediumTest { } @Test - public void find_rules_by_component() throws Exception { - RuleDto rule = newRule(); - ComponentDto project = newProject(); - ComponentDto file = newFile(project); - - // 2 issues on the same rule - saveIssue(IssueTesting.newDto(rule, file, project)); - saveIssue(IssueTesting.newDto(rule, file, project)); - - RulesAggregation result = service.findRulesByComponent(file.key(), null, session); - assertThat(result.rules()).hasSize(1); - } - - @Test - public void find_rules_by_severity() throws Exception { - RuleDto rule = newRule(); - ComponentDto project = newProject(); - ComponentDto file = newFile(project); - - saveIssue(IssueTesting.newDto(rule, file, project).setSeverity(Severity.MAJOR)); - saveIssue(IssueTesting.newDto(rule, file, project).setSeverity(Severity.MAJOR)); - saveIssue(IssueTesting.newDto(rule, file, project).setSeverity(Severity.INFO)); - - Multiset<String> result = service.findSeveritiesByComponent(file.key(), null, session); - assertThat(result.count("MAJOR")).isEqualTo(2); - assertThat(result.count("INFO")).isEqualTo(1); - assertThat(result.count("UNKNOWN")).isEqualTo(0); - } - - @Test public void search_issues() { RuleDto rule = newRule(); ComponentDto project = newProject(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java index f4a9f6372f4..afca99bb5f4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueStorageTest.java @@ -101,7 +101,7 @@ public class ServerIssueStorageTest extends AbstractDaoTestCase { // override generated key comment.setKey("FGHIJ"); - Date date = DateUtils.parseDate("2013-05-18"); + Date date = DateUtils.parseDateTime("2013-05-18T12:00:00+0000"); DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setNew(true) @@ -137,7 +137,7 @@ public class ServerIssueStorageTest extends AbstractDaoTestCase { // override generated key comment.setKey("FGHIJ"); - Date date = DateUtils.parseDate("2013-05-18"); + Date date = DateUtils.parseDateTime("2013-05-18T12:00:00+0000"); DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setNew(false) diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/db/IssueDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/db/IssueDaoTest.java index 74a54905655..7a6f9a6f0e2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/db/IssueDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/db/IssueDaoTest.java @@ -23,7 +23,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.DateUtils; import org.sonar.core.component.ComponentDto; import org.sonar.core.issue.db.IssueDto; import org.sonar.core.persistence.AbstractDaoTestCase; @@ -151,11 +150,11 @@ public class IssueDaoTest extends AbstractDaoTestCase { dto.setChecksum("123456789"); dto.setMessage("the message"); - dto.setIssueCreationDate(DateUtils.parseDate("2013-05-18")); - dto.setIssueUpdateDate(DateUtils.parseDate("2013-05-19")); - dto.setIssueCloseDate(DateUtils.parseDate("2013-05-20")); - dto.setCreatedAt(1400000000000L); - dto.setUpdatedAt(1450000000000L); + dto.setIssueCreationTime(1_500_000_000_000L); + dto.setIssueUpdateTime(1_500_000_000_001L); + dto.setIssueCloseTime(1_500_000_000_002L); + dto.setCreatedAt(1_400_000_000_000L); + dto.setUpdatedAt(1_450_000_000_000L); sut.insert(session, dto); session.commit(); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml index 094c6be6cb4..a138d68b188 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml @@ -2,12 +2,12 @@ <snapshots id="1" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1" status="P" islast="[true]" purge_status="1" - period1_mode="days1" period1_param="30" period1_date="1316815200000" - period2_mode="days2" period2_param="31" period2_date="1316901600000" - period3_mode="days3" period3_param="32" period3_date="1316988000000" - period4_mode="days4" period4_param="33" period4_date="1317074400000" - period5_mode="days5" period5_param="34" period5_date="1317160800000" - depth="1" scope="DIR" qualifier="PAC" created_at="1403042400000" build_date="1317247200000" + period1_mode="days1" period1_param="30" period1_date="1500000000001" + period2_mode="days2" period2_param="31" period2_date="1500000000002" + period3_mode="days3" period3_param="32" period3_date="1500000000003" + period4_mode="days4" period4_param="33" period4_date="1500000000004" + period5_mode="days5" period5_param="34" period5_date="1500000000005" + depth="1" scope="DIR" qualifier="PAC" created_at="1403042400000" build_date="1500000000006" version="2.1-SNAPSHOT" path="1.2."/> </dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml index bc6bbc5b63e..4fd579504fe 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml @@ -7,8 +7,8 @@ report_status="PENDING" started_at="[null]" finished_at="[null]" - created_at="1411682400000" - updated_at="1411682400000" + created_at="1500000000000" + updated_at="1500000000000" /> <analysis_reports id="2" @@ -18,7 +18,7 @@ report_status="PENDING" started_at="[null]" finished_at="[null]" - created_at="1411682400000" - updated_at="1411682400000" + created_at="1500000000000" + updated_at="1500000000000" /> </dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml index a4e07b73029..c38ac125e00 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml @@ -4,9 +4,9 @@ project_key="123456789-987654321" uuid="REPORT_1" report_status="WORKING" - created_at="1411509600000" - updated_at="1411596000000" - started_at="1411682400000" - finished_at="1411768800000" + created_at="1500000000001" + updated_at="1500000000002" + started_at="1500000000003" + finished_at="1500000000004" /> </dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending-result.xml index 2c240ea4bc4..16fb8dc0895 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending-result.xml @@ -7,7 +7,7 @@ uuid="UUID_1" report_status="PENDING" created_at="1411509600000" - updated_at="1411682400000" + updated_at="1500000000000" started_at="[null]" finished_at="[null]" /> @@ -18,7 +18,7 @@ uuid="UUID_2" report_status="PENDING" created_at="1411596000000" - updated_at="1411682400000" + updated_at="1500000000000" started_at="[null]" finished_at="[null]" /> @@ -29,7 +29,7 @@ uuid="UUID_3" report_status="PENDING" created_at="1411682400000" - updated_at="1411682400000" + updated_at="1500000000000" started_at="[null]" finished_at="[null]" /> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues-result.xml index 40fc2fb5a22..b63e969de7f 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues-result.xml @@ -16,9 +16,9 @@ issue_attributes="foo=bar" tags="[null]" action_plan_key="[null]" - issue_creation_date="1368828000000" - issue_update_date="1368828000000" - issue_close_date="1368828000000" + issue_creation_date="1368878400000" + issue_update_date="1368878400000" + issue_close_date="1368878400000" /> <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik" diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml index e7975e281f2..f0fc706f0fc 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml @@ -21,9 +21,9 @@ issue_attributes="foo=bar" tags="[null]" action_plan_key="[null]" - issue_creation_date="1368828000000" - issue_update_date="1368828000000" - issue_close_date="1368828000000" + issue_creation_date="1368878400000" + issue_update_date="1368878400000" + issue_close_date="1368878400000" /> <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik" diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/db/IssueDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/db/IssueDaoTest/insert-result.xml index 8827644b2c8..fc1543cb2b9 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/db/IssueDaoTest/insert-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/db/IssueDaoTest/insert-result.xml @@ -19,9 +19,9 @@ assignee="karadoc" issue_attributes="JIRA=FOO-1234" tags="[null]" - issue_creation_date="1368828000000" - issue_update_date="1368914400000" - issue_close_date="1369000800000" + issue_creation_date="1500000000000" + issue_update_date="1500000000001" + issue_close_date="1500000000002" created_at="1400000000000" updated_at="1450000000000" action_plan_key="current_sprint" |