*/
package org.sonar.server.computation.task.projectanalysis.step;
-import com.google.common.base.Strings;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
private final long analysisDate;
@CheckForNull
private final String currentVersion;
- private final String qualifier;
- public PeriodResolver(DbClient dbClient, DbSession session, String projectUuid, long analysisDate, @Nullable String currentVersion, String qualifier) {
+ public PeriodResolver(DbClient dbClient, DbSession session, String projectUuid, long analysisDate, @Nullable String currentVersion) {
this.dbClient = dbClient;
this.session = session;
this.projectUuid = projectUuid;
this.analysisDate = analysisDate;
this.currentVersion = currentVersion;
- this.qualifier = qualifier;
}
@CheckForNull
- public Period resolve(int index, Settings settings) {
- String propertyValue = getPropertyValue(qualifier, settings, index);
+ public Period resolve(Settings settings) {
+ String propertyValue = getPropertyValue(settings);
if (StringUtils.isBlank(propertyValue)) {
return null;
}
- Period period = resolve(index, propertyValue);
+ Period period = resolve(propertyValue);
if (period == null && StringUtils.isNotBlank(propertyValue)) {
- LOG.debug("Property " + TIMEMACHINE_PERIOD_PREFIX + index + " is not valid: " + propertyValue);
+ LOG.debug("Property " + TIMEMACHINE_PERIOD_PREFIX + 1 + " is not valid: " + propertyValue);
}
return period;
}
@CheckForNull
- private Period resolve(int index, String property) {
+ private Period resolve(String property) {
Integer days = tryToResolveByDays(property);
if (days != null) {
- return findByDays(index, days);
+ return findByDays(days);
}
Date date = DateUtils.parseDateQuietly(property);
if (date != null) {
- return findByDate(index, date);
+ return findByDate(date);
}
if (StringUtils.equals(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, property)) {
- return findByPreviousAnalysis(index);
+ return findByPreviousAnalysis();
}
if (StringUtils.equals(TIMEMACHINE_MODE_PREVIOUS_VERSION, property)) {
- return findByPreviousVersion(index);
+ return findByPreviousVersion();
}
- return findByVersion(index, property);
+ return findByVersion(property);
}
- private Period findByDate(int index, Date date) {
+ private Period findByDate(Date date) {
SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectUuid).setCreatedAfter(date.getTime()).setSort(BY_DATE, ASC));
if (snapshot == null) {
return null;
}
LOG.debug("Compare to date {} (analysis of {})", formatDate(date.getTime()), formatDate(snapshot.getCreatedAt()));
- return new Period(index, TIMEMACHINE_MODE_DATE, DateUtils.formatDate(date), snapshot.getCreatedAt(), snapshot.getUuid());
+ return new Period(TIMEMACHINE_MODE_DATE, DateUtils.formatDate(date), snapshot.getCreatedAt(), snapshot.getUuid());
}
@CheckForNull
- private Period findByDays(int index, int days) {
+ private Period findByDays(int days) {
List<SnapshotDto> snapshots = dbClient.snapshotDao().selectAnalysesByQuery(session, createCommonQuery(projectUuid).setCreatedBefore(analysisDate).setSort(BY_DATE, ASC));
long targetDate = DateUtils.addDays(new Date(analysisDate), -days).getTime();
SnapshotDto snapshot = findNearestSnapshotToTargetDate(snapshots, targetDate);
return null;
}
LOG.debug("Compare over {} days ({}, analysis of {})", String.valueOf(days), formatDate(targetDate), formatDate(snapshot.getCreatedAt()));
- return new Period(index, TIMEMACHINE_MODE_DAYS, String.valueOf(days), snapshot.getCreatedAt(), snapshot.getUuid());
+ return new Period(TIMEMACHINE_MODE_DAYS, String.valueOf(days), snapshot.getCreatedAt(), snapshot.getUuid());
}
@CheckForNull
- private Period findByPreviousAnalysis(int index) {
+ private Period findByPreviousAnalysis() {
SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectUuid).setCreatedBefore(analysisDate).setIsLast(true).setSort(BY_DATE, DESC));
if (snapshot == null) {
return null;
}
LOG.debug("Compare to previous analysis ({})", formatDate(snapshot.getCreatedAt()));
- return new Period(index, TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, formatDate(snapshot.getCreatedAt()), snapshot.getCreatedAt(), snapshot.getUuid());
+ return new Period(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, formatDate(snapshot.getCreatedAt()), snapshot.getCreatedAt(), snapshot.getUuid());
}
@CheckForNull
- private Period findByPreviousVersion(int index) {
+ private Period findByPreviousVersion() {
if (currentVersion == null) {
return null;
}
List<SnapshotDto> snapshotDtos = dbClient.snapshotDao().selectPreviousVersionSnapshots(session, projectUuid, currentVersion);
if (snapshotDtos.isEmpty()) {
// If no previous version is found, the first analysis is returned
- return findByFirstAnalysis(index);
+ return findByFirstAnalysis();
}
SnapshotDto snapshotDto = snapshotDtos.get(0);
LOG.debug("Compare to previous version ({})", formatDate(snapshotDto.getCreatedAt()));
- return new Period(index, TIMEMACHINE_MODE_PREVIOUS_VERSION, snapshotDto.getVersion(), snapshotDto.getCreatedAt(), snapshotDto.getUuid());
+ return new Period(TIMEMACHINE_MODE_PREVIOUS_VERSION, snapshotDto.getVersion(), snapshotDto.getCreatedAt(), snapshotDto.getUuid());
}
@CheckForNull
- private Period findByFirstAnalysis(int index) {
+ private Period findByFirstAnalysis() {
SnapshotDto snapshotDto = dbClient.snapshotDao().selectOldestSnapshot(session, projectUuid);
if (snapshotDto == null) {
return null;
}
LOG.debug("Compare to first analysis ({})", formatDate(snapshotDto.getCreatedAt()));
- return new Period(index, TIMEMACHINE_MODE_PREVIOUS_VERSION, null, snapshotDto.getCreatedAt(), snapshotDto.getUuid());
+ return new Period(TIMEMACHINE_MODE_PREVIOUS_VERSION, null, snapshotDto.getCreatedAt(), snapshotDto.getUuid());
}
@CheckForNull
- private Period findByVersion(int index, String version) {
+ private Period findByVersion(String version) {
SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectUuid).setVersion(version).setSort(BY_DATE, DESC));
if (snapshot == null) {
return null;
}
LOG.debug("Compare to version ({}) ({})", version, formatDate(snapshot.getCreatedAt()));
- return new Period(index, TIMEMACHINE_MODE_VERSION, version, snapshot.getCreatedAt(), snapshot.getUuid());
+ return new Period(TIMEMACHINE_MODE_VERSION, version, snapshot.getCreatedAt(), snapshot.getUuid());
}
@CheckForNull
return DateUtils.formatDate(Date.from(new Date(date).toInstant().truncatedTo(ChronoUnit.SECONDS)));
}
- private static String getPropertyValue(@Nullable String qualifier, Settings settings, int index) {
- String value = settings.getString(TIMEMACHINE_PERIOD_PREFIX + index);
- // For periods 4 and 5 we're also searching for a property prefixed by the qualifier
- if (index > 3 && Strings.isNullOrEmpty(value)) {
- value = settings.getString(TIMEMACHINE_PERIOD_PREFIX + index + "." + qualifier);
- }
- return value;
+ private static String getPropertyValue(Settings settings) {
+ return settings.getString(TIMEMACHINE_PERIOD_PREFIX + 1);
}
}
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.text.SimpleDateFormat;
-import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.sonar.api.config.Settings;
import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.Settings;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.db.DbClient;
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_VERSION;
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_VERSION;
-
@RunWith(DataProviderRunner.class)
public class LoadPeriodsStepTest extends BaseStepTest {
@Rule
public LogTester logTester = new LogTester();
- PeriodsHolderImpl periodsHolder = new PeriodsHolderImpl();
- DbClient dbClient = dbTester.getDbClient();
- Settings settings = new MapSettings();
- SettingsRepository settingsRepository = mock(SettingsRepository.class);
+ private PeriodsHolderImpl periodsHolder = new PeriodsHolderImpl();
+ private DbClient dbClient = dbTester.getDbClient();
+ private Settings settings = new MapSettings();
+ private SettingsRepository settingsRepository = mock(SettingsRepository.class);
- LoadPeriodsStep underTest;
+ private LoadPeriodsStep underTest = new LoadPeriodsStep(dbClient, settingsRepository, treeRootHolder, analysisMetadataHolder, periodsHolder);
@Override
protected ComputationStep step() {
@Before
public void setUp() throws Exception {
analysisMetadataHolder.setAnalysisDate(DATE_FORMAT.parse("2008-11-30").getTime());
-
- underTest = new LoadPeriodsStep(dbClient, settingsRepository, treeRootHolder, analysisMetadataHolder, periodsHolder);
}
private void setupRoot(Component root) {
setupRoot(root);
// No project, no snapshot
-
underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
+
+ assertThat(periodsHolder.getPeriod()).isNull();
}
@Test
@UseDataProvider("projectAndViewRoots")
public void feed_one_period(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
-
String textDate = "2008-11-22";
settings.setProperty("sonar.timemachine.period1", textDate);
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(1);
- Period period = periods.get(0);
+ Period period = periodsHolder.getPeriod();
+ assertThat(period).isNotNull();
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_DATE);
assertThat(period.getModeParameter()).isEqualTo(textDate);
assertThat(period.getSnapshotDate()).isEqualTo(1227358680000L);
@UseDataProvider("projectAndViewRoots")
public void no_period_when_settings_match_no_analysis(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
-
settings.setProperty("sonar.timemachine.period1", "UNKNWOWN VERSION");
underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
+
+ assertThat(periodsHolder.getPeriod()).isNull();
}
@Test
@UseDataProvider("projectAndViewRoots")
public void no_period_when_settings_is_empty(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
-
settings.setProperty("sonar.timemachine.period1", "");
underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
+
+ assertThat(periodsHolder.getPeriod()).isNull();
}
@Test
@UseDataProvider("projectAndViewRoots")
public void ignore_unprocessed_snapshots(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "unprocessed_snapshots.xml");
-
settings.setProperty("sonar.timemachine.period1", "100");
underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
+
+ assertThat(periodsHolder.getPeriod()).isNull();
}
@Test
@UseDataProvider("projectAndViewRoots")
public void feed_period_by_date(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
-
String textDate = "2008-11-22";
settings.setProperty("sonar.timemachine.period1", textDate);
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(1);
- Period period = periods.get(0);
// Return analysis from given date 2008-11-22
+ Period period = periodsHolder.getPeriod();
+ assertThat(period).isNotNull();
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_DATE);
assertThat(period.getModeParameter()).isEqualTo(textDate);
assertThat(period.getSnapshotDate()).isEqualTo(1227358680000L);
@UseDataProvider("projectAndViewRoots")
public void search_by_date_return_nearest_later_analysis(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
String date = "2008-11-24";
-
settings.setProperty("sonar.timemachine.period1", date);
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(1);
// Analysis form 2008-11-29
- Period period = periods.get(0);
+ Period period = periodsHolder.getPeriod();
+ assertThat(period).isNotNull();
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_DATE);
assertThat(period.getModeParameter()).isEqualTo(date);
assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L);
@UseDataProvider("projectAndViewRoots")
public void no_period_by_date(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
-
// No analysis at and after this date
settings.setProperty("sonar.timemachine.period1", "2008-11-30");
underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
+
+ assertThat(periodsHolder.getPeriod()).isNull();
}
@Test
@UseDataProvider("projectAndViewRoots")
public void feed_period_by_days(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
-
settings.setProperty("sonar.timemachine.period1", "10");
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(1);
// return analysis from 2008-11-20
- Period period = periods.get(0);
+ Period period = periodsHolder.getPeriod();
+ assertThat(period).isNotNull();
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_DAYS);
assertThat(period.getModeParameter()).isEqualTo("10");
assertThat(period.getSnapshotDate()).isEqualTo(1227157200000L);
@UseDataProvider("projectAndViewRoots")
public void no_period_by_days(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "empty.xml");
-
settings.setProperty("sonar.timemachine.period1", "0");
underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
+
+ assertThat(periodsHolder.getPeriod()).isNull();
}
@Test
@UseDataProvider("projectAndViewRoots")
public void feed_period_by_previous_analysis(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
-
settings.setProperty("sonar.timemachine.period1", "previous_analysis");
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(1);
// return analysis from 2008-11-29
- Period period = periods.get(0);
+ Period period = periodsHolder.getPeriod();
+ assertThat(period).isNotNull();
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
assertThat(period.getModeParameter()).isNotNull();
assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L);
@UseDataProvider("projectAndViewRoots")
public void no_period_by_previous_analysis(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "empty.xml");
-
settings.setProperty("sonar.timemachine.period1", "previous_analysis");
underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
+
+ assertThat(periodsHolder.getPeriod()).isNull();
}
@Test
public void feed_period_by_previous_version() {
setupRoot(PROJECT_ROOT);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
-
settings.setProperty("sonar.timemachine.period1", "previous_version");
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(1);
// Analysis form 2008-11-12
- Period period = periods.get(0);
+ Period period = periodsHolder.getPeriod();
+ assertThat(period).isNotNull();
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_VERSION);
assertThat(period.getModeParameter()).isEqualTo("1.0");
assertThat(period.getSnapshotDate()).isEqualTo(1226494680000L);
@Test
public void feed_period_by_previous_version_is_not_supported_for_views() {
setupRoot(VIEW_ROOT);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
-
settings.setProperty("sonar.timemachine.period1", "previous_version");
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(0);
+
+ assertThat(periodsHolder.getPeriod()).isNull();
}
@Test
public void feed_period_by_previous_version_with_previous_version_deleted() {
setupRoot(PROJECT_ROOT);
-
dbTester.prepareDbUnit(getClass(), "previous_version_deleted.xml");
-
settings.setProperty("sonar.timemachine.period1", "previous_version");
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(1);
// Analysis form 2008-11-11
- Period period = periods.get(0);
+ Period period = periodsHolder.getPeriod();
+ assertThat(period).isNotNull();
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_VERSION);
assertThat(period.getModeParameter()).isEqualTo("0.9");
assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);
@UseDataProvider("projectAndViewRoots")
public void no_period_by_previous_version(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "empty.xml");
-
settings.setProperty("sonar.timemachine.period1", "previous_version");
underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
+
+ assertThat(periodsHolder.getPeriod()).isNull();
}
@Test
public void feed_period_by_previous_version_with_first_analysis_when_no_previous_version_found() {
setupRoot(PROJECT_ROOT);
-
dbTester.prepareDbUnit(getClass(), "no_previous_version.xml");
-
settings.setProperty("sonar.timemachine.period1", "previous_version");
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(1);
- Period period = periods.get(0);
+ Period period = periodsHolder.getPeriod();
+ assertThat(period).isNotNull();
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_VERSION);
assertThat(period.getModeParameter()).isNull();
assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);
@Test
public void feed_period_by_previous_version_with_first_analysis_when_previous_snapshot_is_the_last_one() {
setupRoot(PROJECT_ROOT);
-
dbTester.prepareDbUnit(getClass(), "previous_version_is_last_one.xml");
-
settings.setProperty("sonar.timemachine.period1", "previous_version");
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(1);
- Period period = periods.get(0);
+ Period period = periodsHolder.getPeriod();
+ assertThat(period).isNotNull();
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_VERSION);
assertThat(period.getModeParameter()).isNull();
assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);
@Test
public void no_period_by_previous_version_when_no_event_version_for_views() {
setupRoot(VIEW_ROOT);
-
dbTester.prepareDbUnit(getClass(), "no_previous_version.xml");
-
settings.setProperty("sonar.timemachine.period1", "previous_version");
underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
+
+ assertThat(periodsHolder.getPeriod()).isNull();
}
@Test
@UseDataProvider("projectAndViewRoots")
public void feed_period_by_version(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "shared.xml");
-
settings.setProperty("sonar.timemachine.period1", "0.9");
underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).hasSize(1);
// Analysis form 2008-11-11
- Period period = periods.get(0);
+ Period period = periodsHolder.getPeriod();
+ assertThat(period).isNotNull();
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_VERSION);
assertThat(period.getModeParameter()).isEqualTo("0.9");
assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);
@UseDataProvider("projectAndViewRoots")
public void no_period_by_version(Component root) {
setupRoot(root);
-
dbTester.prepareDbUnit(getClass(), "empty.xml");
-
settings.setProperty("sonar.timemachine.period1", "0.8");
underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
- }
-
- @Test
- public void all_five_types_of_periods_are_supported_for_PROJECT_component_tree() {
- setupRoot(PROJECT_ROOT);
-
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- settings.setProperty("sonar.timemachine.period1", "2008-11-22"); // Analysis from 2008-11-22 should be returned
- settings.setProperty("sonar.timemachine.period2", "10"); // Analysis from 2008-11-20 should be returned
- settings.setProperty("sonar.timemachine.period3", "previous_analysis"); // Analysis from 2008-11-29 should be returned
- settings.setProperty("sonar.timemachine.period4", "previous_version"); // Analysis from 2008-11-12 should be returned
- settings.setProperty("sonar.timemachine.period5", "0.9"); // Analysis from 2008-11-11
-
- underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
-
- assertThat(periods).extracting("mode").containsExactly(TIMEMACHINE_MODE_DATE, TIMEMACHINE_MODE_DAYS,
- TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, TIMEMACHINE_MODE_PREVIOUS_VERSION,
- TIMEMACHINE_MODE_VERSION);
-
- assertThat(periods.get(0).getMode()).isEqualTo(TIMEMACHINE_MODE_DATE);
- assertThat(periods.get(0).getIndex()).isEqualTo(1);
- assertThat(periods.get(0).getSnapshotDate()).isEqualTo(1227358680000L);
-
- assertThat(periods.get(1).getMode()).isEqualTo(TIMEMACHINE_MODE_DAYS);
- assertThat(periods.get(1).getIndex()).isEqualTo(2);
- assertThat(periods.get(1).getSnapshotDate()).isEqualTo(1227157200000L);
-
- assertThat(periods.get(2).getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
- assertThat(periods.get(2).getIndex()).isEqualTo(3);
- assertThat(periods.get(2).getSnapshotDate()).isEqualTo(1227934800000L);
-
- assertThat(periods.get(3).getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_VERSION);
- assertThat(periods.get(3).getIndex()).isEqualTo(4);
- assertThat(periods.get(3).getSnapshotDate()).isEqualTo(1226494680000L);
-
- assertThat(periods.get(4).getMode()).isEqualTo(TIMEMACHINE_MODE_VERSION);
- assertThat(periods.get(4).getIndex()).isEqualTo(5);
- assertThat(periods.get(4).getSnapshotDate()).isEqualTo(1226379600000L);
- }
-
- @Test
- public void feed_four_different_periods() {
- setupRoot(VIEW_ROOT);
-
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- settings.setProperty("sonar.timemachine.period1", "2008-11-22"); // Analysis from 2008-11-22 should be returned
- settings.setProperty("sonar.timemachine.period2", "10"); // Analysis from 2008-11-20 should be returned
- settings.setProperty("sonar.timemachine.period3", "previous_analysis"); // Analysis from 2008-11-29 should be returned
- settings.setProperty("sonar.timemachine.period4", "previous_version"); // Analysis from 2008-11-12 should be returned
- settings.setProperty("sonar.timemachine.period5", "0.9"); // Analysis from 2008-11-11
-
- underTest.execute();
- List<Period> periods = periodsHolder.getPeriods();
-
- assertThat(periods).extracting("mode").containsExactly(
- TIMEMACHINE_MODE_DATE, TIMEMACHINE_MODE_DAYS,
- TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, TIMEMACHINE_MODE_VERSION);
-
- assertThat(periods.get(0).getMode()).isEqualTo(TIMEMACHINE_MODE_DATE);
- assertThat(periods.get(0).getIndex()).isEqualTo(1);
- assertThat(periods.get(0).getSnapshotDate()).isEqualTo(1227358680000L);
-
- assertThat(periods.get(1).getMode()).isEqualTo(TIMEMACHINE_MODE_DAYS);
- assertThat(periods.get(1).getIndex()).isEqualTo(2);
- assertThat(periods.get(1).getSnapshotDate()).isEqualTo(1227157200000L);
-
- assertThat(periods.get(2).getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
- assertThat(periods.get(2).getIndex()).isEqualTo(3);
- assertThat(periods.get(2).getSnapshotDate()).isEqualTo(1227934800000L);
- assertThat(periods.get(3).getMode()).isEqualTo(TIMEMACHINE_MODE_VERSION);
- assertThat(periods.get(3).getIndex()).isEqualTo(5);
- assertThat(periods.get(3).getSnapshotDate()).isEqualTo(1226379600000L);
- }
-
- @Test
- public void can_use_project_qualifier_in_settings() {
- setupRoot(PROJECT_ROOT);
-
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- settings.setProperty("sonar.timemachine.period4.TRK", "2008-11-22");
- settings.setProperty("sonar.timemachine.period5.TRK", "previous_analysis");
-
- underTest.execute();
- assertThat(periodsHolder.getPeriods()).hasSize(2);
- }
-
- @Test
- public void can_use_views_qualifier_in_settings() {
- setupRoot(VIEW_ROOT);
-
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- settings.setProperty("sonar.timemachine.period4.VW", "2008-11-22");
- settings.setProperty("sonar.timemachine.period5.VW", "previous_analysis");
-
- underTest.execute();
- assertThat(periodsHolder.getPeriods()).hasSize(2);
+ assertThat(periodsHolder.getPeriod()).isNull();
}
}