aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-08-25 10:40:50 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-08-25 10:41:19 +0200
commitfb829915b701a95f051cab02fcc14bb6c247ba2c (patch)
treeb614d0e7d0cc3ced51a1b29105f6ec99ebc2f932 /server
parentfc18addf344d869f92a0cd8a019d1374baca7ddf (diff)
downloadsonarqube-fb829915b701a95f051cab02fcc14bb6c247ba2c.tar.gz
sonarqube-fb829915b701a95f051cab02fcc14bb6c247ba2c.zip
previous_version period is not supported by Views
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/FeedPeriodsStep.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java83
2 files changed, 65 insertions, 25 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/FeedPeriodsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/FeedPeriodsStep.java
index 382656f0189..1da2605ff8d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/FeedPeriodsStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/FeedPeriodsStep.java
@@ -20,7 +20,6 @@
package org.sonar.server.computation.step;
-import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import java.util.ArrayList;
@@ -219,8 +218,10 @@ public class FeedPeriodsStep implements ComputationStep {
@CheckForNull
private Period findByPreviousVersion(int index) {
- String version = Objects.firstNonNull(currentVersion, "");
- List<SnapshotDto> snapshotDtos = dbClient.snapshotDao().selectPreviousVersionSnapshots(session, projectId, version);
+ if (currentVersion == null) {
+ return null;
+ }
+ List<SnapshotDto> snapshotDtos = dbClient.snapshotDao().selectPreviousVersionSnapshots(session, projectId, currentVersion);
if (snapshotDtos.isEmpty()) {
return null;
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java
index 868faa640e3..83a23649c7b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedPeriodsStepTest.java
@@ -307,9 +307,8 @@ public class FeedPeriodsStepTest extends BaseStepTest {
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void feed_period_by_previous_version(Component root) {
- setupRoot(root);
+ public void feed_period_by_previous_version() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
@@ -322,24 +321,30 @@ public class FeedPeriodsStepTest extends BaseStepTest {
// Analysis form 2008-11-12
Period period = periods.get(0);
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
- if (root.getType().isViewsType()) {
- assertThat(period.getModeParameter()).isEqualTo("1.1");
- assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L);
- assertThat(period.getSnapshotId()).isEqualTo(1004L);
- } else {
- assertThat(period.getModeParameter()).isEqualTo("1.0");
- assertThat(period.getSnapshotDate()).isEqualTo(1226494680000L);
- assertThat(period.getSnapshotId()).isEqualTo(1001L);
- }
+ assertThat(period.getModeParameter()).isEqualTo("1.0");
+ assertThat(period.getSnapshotDate()).isEqualTo(1226494680000L);
+ assertThat(period.getSnapshotId()).isEqualTo(1001L);
assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs().get(0)).startsWith("Compare to previous version (");
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void feed_period_by_previous_version_wit_previous_version_deleted(Component root) {
- setupRoot(root);
+ 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);
+ }
+
+ @Test
+ public void feed_period_by_previous_version_wit_previous_version_deleted() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "previous_version_deleted.xml");
@@ -421,9 +426,8 @@ public class FeedPeriodsStepTest extends BaseStepTest {
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void feed_five_different_periods(Component root) {
- setupRoot(root);
+ public void all_five_types_of_periods_are_supported_for_PROJECT_component_tree() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
@@ -436,9 +440,9 @@ public class FeedPeriodsStepTest extends BaseStepTest {
underTest.execute();
List<Period> periods = periodsHolder.getPeriods();
- assertThat(periods).extracting("mode").containsExactly(
- CoreProperties.TIMEMACHINE_MODE_DATE, CoreProperties.TIMEMACHINE_MODE_DAYS, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS,
- CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, CoreProperties.TIMEMACHINE_MODE_VERSION);
+ assertThat(periods).extracting("mode").containsExactly(CoreProperties.TIMEMACHINE_MODE_DATE, CoreProperties.TIMEMACHINE_MODE_DAYS,
+ CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION,
+ CoreProperties.TIMEMACHINE_MODE_VERSION);
assertThat(periods.get(0).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
assertThat(periods.get(0).getIndex()).isEqualTo(1);
@@ -454,7 +458,7 @@ public class FeedPeriodsStepTest extends BaseStepTest {
assertThat(periods.get(3).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
assertThat(periods.get(3).getIndex()).isEqualTo(4);
- assertThat(periods.get(3).getSnapshotDate()).isEqualTo(root.getType().isReportType() ? 1226494680000L : 1227934800000L);
+ assertThat(periods.get(3).getSnapshotDate()).isEqualTo(1226494680000L);
assertThat(periods.get(4).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION);
assertThat(periods.get(4).getIndex()).isEqualTo(5);
@@ -462,6 +466,41 @@ public class FeedPeriodsStepTest extends BaseStepTest {
}
@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(CoreProperties.TIMEMACHINE_MODE_DATE, CoreProperties.TIMEMACHINE_MODE_DAYS,
+ CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, CoreProperties.TIMEMACHINE_MODE_VERSION);
+
+ assertThat(periods.get(0).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
+ assertThat(periods.get(0).getIndex()).isEqualTo(1);
+ assertThat(periods.get(0).getSnapshotDate()).isEqualTo(1227358680000L);
+
+ assertThat(periods.get(1).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DAYS);
+ assertThat(periods.get(1).getIndex()).isEqualTo(2);
+ assertThat(periods.get(1).getSnapshotDate()).isEqualTo(1227157200000L);
+
+ assertThat(periods.get(2).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
+ assertThat(periods.get(2).getIndex()).isEqualTo(3);
+ assertThat(periods.get(2).getSnapshotDate()).isEqualTo(1227934800000L);
+
+ assertThat(periods.get(3).getMode()).isEqualTo(CoreProperties.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);