2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.server.db.migrations.v51;
23 import org.junit.Before;
24 import org.junit.ClassRule;
25 import org.junit.Test;
26 import org.sonar.api.utils.System2;
27 import org.sonar.core.persistence.DbTester;
28 import org.sonar.server.db.migrations.DatabaseMigration;
30 import static org.assertj.core.api.Assertions.assertThat;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
33 import static org.sonar.api.utils.DateUtils.parseDate;
35 public class FeedProjectMeasuresLongDatesTest {
37 public static DbTester db = new DbTester().schema(FeedProjectMeasuresLongDatesTest.class, "schema.sql");
40 public void before() throws Exception {
41 db.prepareDbUnit(getClass(), "before.xml");
45 public void execute() throws Exception {
46 DatabaseMigration migration = newMigration(System2.INSTANCE);
51 .countSql("select count(*) from project_measures where " +
52 "measure_date_ms is not null");
53 assertThat(count).isEqualTo(2);
57 public void take_now_if_date_in_the_future() throws Exception {
58 System2 system = mock(System2.class);
59 when(system.now()).thenReturn(1234L);
61 DatabaseMigration migration = newMigration(system);
66 .countSql("select count(*) from project_measures where " +
67 "measure_date_ms = 1234");
68 assertThat(count).isEqualTo(1);
72 public void take_snapshot_date_if_in_the_past() throws Exception {
73 DatabaseMigration migration = newMigration(System2.INSTANCE);
77 long snapshotTime = parseDate("2014-09-25").getTime();
79 .countSql("select count(*) from project_measures where " +
80 "measure_date_ms=" + snapshotTime);
81 assertThat(count).isEqualTo(1);
84 private FeedProjectMeasuresLongDates newMigration(System2 system) {
85 return new FeedProjectMeasuresLongDates(db.database(), system);