aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-core-plugin
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-03 17:51:58 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-03 17:51:58 +0000
commit46124a16b74a5e20b25a87e804ecce9baf135f16 (patch)
tree6f827f7b45fec2b0af43f702285a0bf60d7ca0c3 /plugins/sonar-core-plugin
parente0c44a1486144da97f75279b0f30c7110de94e96 (diff)
downloadsonarqube-46124a16b74a5e20b25a87e804ecce9baf135f16.tar.gz
sonarqube-46124a16b74a5e20b25a87e804ecce9baf135f16.zip
SONAR-249 add the select-box to display variation periods
Diffstat (limited to 'plugins/sonar-core-plugin')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java3
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java2
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshot.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationSnapshot.java)10
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinder.java89
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersion.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationSnapshotFinder.java)39
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java9
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfiguration.java12
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java16
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java8
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest.java51
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationSnapshotFinderTest.java)14
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java8
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java6
-rw-r--r--plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest/shared.xml42
14 files changed, 248 insertions, 61 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
index bb61a9004a1..59e25fcd896 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
@@ -212,8 +212,9 @@ public class CorePlugin implements Plugin {
// time machine
extensions.add(TendencyDecorator.class);
extensions.add(PastSnapshotFinderByDays.class);
+ extensions.add(PastSnapshotFinderByVersion.class);
extensions.add(PastMeasuresLoader.class);
- extensions.add(VariationSnapshotFinder.class);
+ extensions.add(PastSnapshotFinder.class);
extensions.add(TimeMachineConfiguration.class);
extensions.add(VariationDecorator.class);
extensions.add(PastViolationsLoader.class);
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java
index d7a27736296..7a134d83bd3 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java
@@ -53,7 +53,7 @@ public class NewViolationsDecorator implements Decorator {
public void decorate(Resource resource, DecoratorContext context) {
Measure measure = new Measure(CoreMetrics.NEW_VIOLATIONS);
- for (VariationSnapshot variationSnapshot : timeMachineConfiguration.getVariationSnapshots()) {
+ for (PastSnapshot variationSnapshot : timeMachineConfiguration.getVariationSnapshots()) {
Date date = variationSnapshot.getDate();
double value = countViolationsAfterDate(context.getViolations(), date) + sumChildren(context, variationSnapshot.getIndex());
measure.setVariation(variationSnapshot.getIndex(), value);
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationSnapshot.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshot.java
index 25fddf3f66b..3da2517f606 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationSnapshot.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshot.java
@@ -23,13 +23,13 @@ import org.sonar.api.database.model.Snapshot;
import java.util.Date;
-public final class VariationSnapshot {
+public final class PastSnapshot {
private int index;
private String mode, modeParameter;
private Snapshot projectSnapshot;
- public VariationSnapshot(int index, String mode, Snapshot projectSnapshot) {
+ public PastSnapshot(int index, String mode, Snapshot projectSnapshot) {
this.index = index;
this.mode = mode;
this.projectSnapshot = projectSnapshot;
@@ -47,15 +47,15 @@ public final class VariationSnapshot {
return projectSnapshot.getCreatedAt();
}
- public String getMode() {
+ public String getConfigurationMode() {
return mode;
}
- public String getModeParameter() {
+ public String getConfigurationModeParameter() {
return modeParameter;
}
- public VariationSnapshot setModeParameter(String s) {
+ public PastSnapshot setConfigurationModeParameter(String s) {
this.modeParameter = s;
return this;
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinder.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinder.java
new file mode 100644
index 00000000000..11b931c3cd3
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinder.java
@@ -0,0 +1,89 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.core.timemachine;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.database.model.Snapshot;
+
+public class PastSnapshotFinder implements BatchExtension {
+
+ private PastSnapshotFinderByDays finderByDays;
+ private PastSnapshotFinderByVersion finderByVersion;
+
+ public PastSnapshotFinder(PastSnapshotFinderByDays finderByDays, PastSnapshotFinderByVersion finderByVersion) {
+ this.finderByDays = finderByDays;
+ this.finderByVersion = finderByVersion;
+ }
+
+ public PastSnapshot find(Configuration conf, int index) {
+ return find(index, conf.getString("sonar.timemachine.variation" + index));
+ }
+
+ public PastSnapshot find(int index, String property) {
+ if (StringUtils.isBlank(property)) {
+ return null;
+ }
+
+ PastSnapshot result = null;
+ Integer days = getValueInDays(property);
+ if (days != null) {
+ result = findSnapshotInDays(index, days);
+ } else {
+ String version = getValueVersion(property);
+ if (StringUtils.isNotBlank(version)) {
+ result = findSnapshotByVersion(index, version);
+ }
+ }
+
+ return result;
+ }
+
+ private PastSnapshot findSnapshotByVersion(int index, String version) {
+ Snapshot projectSnapshot = finderByVersion.findVersion(version);
+ if (projectSnapshot != null) {
+ return new PastSnapshot(index, "version", projectSnapshot).setConfigurationModeParameter(version);
+ }
+ return null;
+ }
+
+ private String getValueVersion(String property) {
+ // todo check if it's a version with a regexp
+ return null;
+ }
+
+ private PastSnapshot findSnapshotInDays(int index, Integer days) {
+ Snapshot projectSnapshot = finderByDays.findInDays(days);
+ if (projectSnapshot != null) {
+ return new PastSnapshot(index, "days", projectSnapshot).setConfigurationModeParameter(String.valueOf(days));
+ }
+ return null;
+ }
+
+ private Integer getValueInDays(String property) {
+ try {
+ return Integer.parseInt(property);
+
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationSnapshotFinder.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersion.java
index e8d290f9d04..fc2ec93bf27 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationSnapshotFinder.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersion.java
@@ -19,32 +19,31 @@
*/
package org.sonar.plugins.core.timemachine;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchExtension;
+import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-public class VariationSnapshotFinder implements BatchExtension {
+import java.util.List;
- private PastSnapshotFinderByDays finderInDays;
+public class PastSnapshotFinderByVersion implements BatchExtension {
+ private Snapshot projectSnapshot; // TODO replace by PersistenceManager
+ private DatabaseSession session;
- public VariationSnapshotFinder(PastSnapshotFinderByDays finderInDays) {
- this.finderInDays = finderInDays;
+ public PastSnapshotFinderByVersion(Snapshot projectSnapshot, DatabaseSession session) {
+ this.projectSnapshot = projectSnapshot;
+ this.session = session;
}
- public VariationSnapshot find(Configuration conf, int index) {
- return find(index, conf.getString("sonar.timemachine.variation" + index));
- }
-
- public VariationSnapshot find(int index, String property) {
- if (StringUtils.isNotBlank(property)) {
- // todo manage non-integer values
- int days = Integer.parseInt(property);
- Snapshot projectSnapshot = finderInDays.findInDays(days);
- if (projectSnapshot != null) {
- return new VariationSnapshot(index, "days", projectSnapshot).setModeParameter(String.valueOf(days));
- }
- }
- return null;
+ Snapshot findVersion(String version) {
+ String hql = "from " + Snapshot.class.getSimpleName() + " where version=:version AND resourceId=:resourceId AND status=:status order by createdAt desc";
+ List<Snapshot> snapshots = session.createQuery(hql)
+ .setParameter("version", version)
+ .setParameter("resourceId", projectSnapshot.getResourceId())
+ .setParameter("status", Snapshot.STATUS_PROCESSED)
+ .setMaxResults(1)
+ .getResultList();
+
+ return snapshots.isEmpty() ? null : snapshots.get(0);
}
+
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java
index 30810cef199..d8b064fbee0 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java
@@ -6,6 +6,7 @@ import org.sonar.api.database.model.RuleFailureModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.database.model.SnapshotSource;
import org.sonar.api.resources.Resource;
+import org.sonar.api.utils.SonarException;
import org.sonar.batch.index.ResourcePersister;
import java.util.Collections;
@@ -22,10 +23,14 @@ public class PastViolationsLoader implements BatchExtension {
}
public List<RuleFailureModel> getPastViolations(Resource resource) {
- Snapshot snapshot = resourcePersister.getSnapshot(resource);
- if (snapshot == null) { // TODO Godin: Prevent NPE with Natural and VB plugins
+ if (resource == null) {
return Collections.emptyList();
}
+
+ Snapshot snapshot = resourcePersister.getSnapshot(resource);
+ if (snapshot == null) {
+ throw new SonarException("This resource has no snapshot ???" + resource);
+ }
Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(snapshot, true);
if (previousLastSnapshot == null) {
return Collections.emptyList();
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfiguration.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfiguration.java
index 8e990ad2d74..1f0894fd085 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfiguration.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfiguration.java
@@ -32,17 +32,17 @@ public class TimeMachineConfiguration implements BatchExtension {
private static final int NUMBER_OF_VARIATION_SNAPSHOTS = 3;
private final Configuration configuration;
- private List<VariationSnapshot> variationSnapshots;
+ private List<PastSnapshot> variationSnapshots;
- public TimeMachineConfiguration(Configuration configuration, VariationSnapshotFinder variationSnapshotFinder) {
+ public TimeMachineConfiguration(Configuration configuration, PastSnapshotFinder variationSnapshotFinder) {
this.configuration = configuration;
initVariationSnapshots(variationSnapshotFinder);
}
- private void initVariationSnapshots(VariationSnapshotFinder variationSnapshotFinder) {
+ private void initVariationSnapshots(PastSnapshotFinder variationSnapshotFinder) {
variationSnapshots = Lists.newLinkedList();
for (int index = 1; index <= NUMBER_OF_VARIATION_SNAPSHOTS; index++) {
- VariationSnapshot variationSnapshot = variationSnapshotFinder.find(configuration, index);
+ PastSnapshot variationSnapshot = variationSnapshotFinder.find(configuration, index);
if (variationSnapshot != null) {
variationSnapshots.add(variationSnapshot);
}
@@ -52,7 +52,7 @@ public class TimeMachineConfiguration implements BatchExtension {
/**
* for unit tests
*/
- TimeMachineConfiguration(Configuration configuration, List<VariationSnapshot> variationSnapshots) {
+ TimeMachineConfiguration(Configuration configuration, List<PastSnapshot> variationSnapshots) {
this.configuration = configuration;
this.variationSnapshots = variationSnapshots;
}
@@ -74,7 +74,7 @@ public class TimeMachineConfiguration implements BatchExtension {
return configuration.getInt(CoreProperties.CORE_TENDENCY_DEPTH_PROPERTY, CoreProperties.CORE_TENDENCY_DEPTH_DEFAULT_VALUE);
}
- public List<VariationSnapshot> getVariationSnapshots() {
+ public List<PastSnapshot> getVariationSnapshots() {
return variationSnapshots;
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
index df731278b5e..b587d2707c5 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
@@ -38,20 +38,20 @@ public final class TimeMachineConfigurationPersister implements BatchExtension {
}
public void start() {
- List<VariationSnapshot> variationSnapshots = configuration.getVariationSnapshots();
- for (VariationSnapshot variationSnapshot : variationSnapshots) {
+ List<PastSnapshot> variationSnapshots = configuration.getVariationSnapshots();
+ for (PastSnapshot variationSnapshot : variationSnapshots) {
switch (variationSnapshot.getIndex()) {
case 1:
- projectSnapshot.setVarMode1(variationSnapshot.getMode());
- projectSnapshot.setVarLabel1(variationSnapshot.getModeParameter());
+ projectSnapshot.setVarMode1(variationSnapshot.getConfigurationMode());
+ projectSnapshot.setVarLabel1(variationSnapshot.getConfigurationModeParameter());
break;
case 2:
- projectSnapshot.setVarMode2(variationSnapshot.getMode());
- projectSnapshot.setVarLabel2(variationSnapshot.getModeParameter());
+ projectSnapshot.setVarMode2(variationSnapshot.getConfigurationMode());
+ projectSnapshot.setVarLabel2(variationSnapshot.getConfigurationModeParameter());
break;
case 3:
- projectSnapshot.setVarMode3(variationSnapshot.getMode());
- projectSnapshot.setVarLabel3(variationSnapshot.getModeParameter());
+ projectSnapshot.setVarMode3(variationSnapshot.getConfigurationMode());
+ projectSnapshot.setVarLabel3(variationSnapshot.getConfigurationModeParameter());
break;
}
session.save(projectSnapshot);
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
index 423971fdf9f..03b594c36bf 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
@@ -39,14 +39,14 @@ import java.util.Map;
@DependedUpon(DecoratorBarriers.END_OF_TIME_MACHINE)
public class VariationDecorator implements Decorator {
- private List<VariationSnapshot> targets;
+ private List<PastSnapshot> targets;
private PastMeasuresLoader pastMeasuresLoader;
public VariationDecorator(PastMeasuresLoader pastMeasuresLoader, TimeMachineConfiguration configuration) {
this(pastMeasuresLoader, configuration.getVariationSnapshots());
}
- VariationDecorator(PastMeasuresLoader pastMeasuresLoader, List<VariationSnapshot> targets) {
+ VariationDecorator(PastMeasuresLoader pastMeasuresLoader, List<PastSnapshot> targets) {
this.pastMeasuresLoader = pastMeasuresLoader;
this.targets = targets;
}
@@ -67,13 +67,13 @@ public class VariationDecorator implements Decorator {
public void decorate(Resource resource, DecoratorContext context) {
if (shouldCalculateVariations(resource)) {
- for (VariationSnapshot target : targets) {
+ for (PastSnapshot target : targets) {
calculateVariation(resource, context, target);
}
}
}
- private void calculateVariation(Resource resource, DecoratorContext context, VariationSnapshot target) {
+ private void calculateVariation(Resource resource, DecoratorContext context, PastSnapshot target) {
List<MeasureModel> pastMeasures = pastMeasuresLoader.getPastMeasures(resource, target.getProjectSnapshot());
compareWithPastMeasures(context, target.getIndex(), pastMeasures);
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest.java
new file mode 100644
index 00000000000..8e6d40ef1ea
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest.java
@@ -0,0 +1,51 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.core.timemachine;
+
+import org.junit.Test;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase {
+
+ @Test
+ public void shouldFindByVersion() {
+ setupData("shared");
+
+ Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
+ PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(currentProjectSnapshot, getSession());
+
+ assertThat(finder.findVersion("1.1").getId(), is(1009));
+ }
+
+ @Test
+ public void shouldNotFindVersion() {
+ setupData("shared");
+
+ Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
+ PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(currentProjectSnapshot, getSession());
+
+ assertThat(finder.findVersion("1.0"), nullValue());
+ }
+}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationSnapshotFinderTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderTest.java
index d4a01501142..535913efbbe 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationSnapshotFinderTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderTest.java
@@ -29,29 +29,29 @@ import static org.mockito.Mockito.*;
import static org.hamcrest.core.Is.is;
-public class VariationSnapshotFinderTest {
+public class PastSnapshotFinderTest {
@Test
public void shouldFindByNumberOfDays() {
PastSnapshotFinderByDays finderByDays = mock(PastSnapshotFinderByDays.class);
when(finderByDays.findInDays(30)).thenReturn(new Snapshot());
- VariationSnapshotFinder finder = new VariationSnapshotFinder(finderByDays);
- VariationSnapshot variationSnapshot = finder.find(1, "30");
+ PastSnapshotFinder finder = new PastSnapshotFinder(finderByDays, null);
+ PastSnapshot variationSnapshot = finder.find(1, "30");
verify(finderByDays).findInDays(30);
assertNotNull(variationSnapshot);
assertThat(variationSnapshot.getIndex(), is(1));
- assertThat(variationSnapshot.getMode(), is("days"));
- assertThat(variationSnapshot.getModeParameter(), is("30"));
+ assertThat(variationSnapshot.getConfigurationMode(), is("days"));
+ assertThat(variationSnapshot.getConfigurationModeParameter(), is("30"));
}
@Test
public void shouldNotFindByNumberOfDays() {
PastSnapshotFinderByDays finderByDays = mock(PastSnapshotFinderByDays.class);
- VariationSnapshotFinder finder = new VariationSnapshotFinder(finderByDays);
- VariationSnapshot variationSnapshot = finder.find(1, "30");
+ PastSnapshotFinder finder = new PastSnapshotFinder(finderByDays, null);
+ PastSnapshot variationSnapshot = finder.find(1, "30");
verify(finderByDays).findInDays(30);
assertNull(variationSnapshot);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
index d1f21db252d..900f8c45711 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
@@ -35,10 +35,10 @@ public class TimeMachineConfigurationPersisterTest extends AbstractDbUnitTestCas
setupData("shared");
TimeMachineConfiguration conf = mock(TimeMachineConfiguration.class);
- VariationSnapshot vs1 = new VariationSnapshot(1, "days", getSession().getSingleResult(Snapshot.class, "id", 100))
- .setModeParameter("30");
- VariationSnapshot vs3 = new VariationSnapshot(3, "version", getSession().getSingleResult(Snapshot.class, "id", 300))
- .setModeParameter("1.2.3");
+ PastSnapshot vs1 = new PastSnapshot(1, "days", getSession().getSingleResult(Snapshot.class, "id", 100))
+ .setConfigurationModeParameter("30");
+ PastSnapshot vs3 = new PastSnapshot(3, "version", getSession().getSingleResult(Snapshot.class, "id", 300))
+ .setConfigurationModeParameter("1.2.3");
when(conf.getVariationSnapshots()).thenReturn(Arrays.asList(vs1, vs3));
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java
index 87d7d9f4235..4a3d89ba489 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java
@@ -46,9 +46,9 @@ public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
@Test
public void shouldInitSnapshotReferences() {
PropertiesConfiguration conf = new PropertiesConfiguration();
- VariationSnapshotFinder snapshotReferenceFinder = mock(VariationSnapshotFinder.class);
- when(snapshotReferenceFinder.find(conf, 1)).thenReturn(new VariationSnapshot(1, "days", null));
- when(snapshotReferenceFinder.find(conf, 3)).thenReturn(new VariationSnapshot(3, "days", null));
+ PastSnapshotFinder snapshotReferenceFinder = mock(PastSnapshotFinder.class);
+ when(snapshotReferenceFinder.find(conf, 1)).thenReturn(new PastSnapshot(1, "days", null));
+ when(snapshotReferenceFinder.find(conf, 3)).thenReturn(new PastSnapshot(3, "days", null));
TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(conf, snapshotReferenceFinder);
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest/shared.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest/shared.xml
new file mode 100644
index 00000000000..34d04755d1a
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest/shared.xml
@@ -0,0 +1,42 @@
+<dataset>
+
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+ root_id="[null]"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+
+
+ <!-- version 1.1-SNAPSHOT -->
+ <snapshots var_mode_1="[null]" var_label_1="[null]" var_mode_2="[null]" var_label_2="[null]" var_mode_3="[null]" var_label_3="[null]" id="1000"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="1.1-SNAPSHOT" path=""
+ status="P" islast="false" depth="0" />
+
+
+ <!-- version 1.1-SNAPSHOT -->
+ <snapshots var_mode_1="[null]" var_label_1="[null]" var_mode_2="[null]" var_label_2="[null]" var_mode_3="[null]" var_label_3="[null]" id="1003"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="2008-11-02 13:58:00.00" version="1.1-SNAPSHOT" path=""
+ status="P" islast="true" depth="0" />
+
+
+ <!-- unprocessed version 1.1 (to ignore) -->
+ <snapshots var_mode_1="[null]" var_label_1="[null]" var_mode_2="[null]" var_label_2="[null]" var_mode_3="[null]" var_label_3="[null]" id="1006"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="2008-11-03 13:58:00.00" version="1.1" path=""
+ status="U" islast="false" depth="0" />
+
+
+ <!-- version 1.1 -->
+ <snapshots var_mode_1="[null]" var_label_1="[null]" var_mode_2="[null]" var_label_2="[null]" var_mode_3="[null]" var_label_3="[null]" id="1009"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="2008-11-04 13:58:00.00" version="1.1" path=""
+ status="P" islast="false" depth="0" />
+
+ <!-- current analysis -->
+ <snapshots var_mode_1="[null]" var_label_1="[null]" var_mode_2="[null]" var_label_2="[null]" var_mode_3="[null]" var_label_3="[null]" id="1010"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="2008-11-05 13:58:00.00" version="1.2-SNAPSHOT" path=""
+ status="U" islast="false" depth="0" />
+
+</dataset> \ No newline at end of file