),
@Property(
key = "sonar.timemachine.variation4",
- name = "Variation 4, only for projects",
+ name = "Variation 4",
description = "To be defined. For the moment the number of days",
project = true,
global = false
extensions.add(TendencyDecorator.class);
extensions.add(PastSnapshotFinderByDate.class);
extensions.add(PastSnapshotFinderByDays.class);
- extensions.add(PastSnapshotFinderByLastAnalysis.class);
+ extensions.add(PastSnapshotFinderByPreviousAnalysis.class);
extensions.add(PastSnapshotFinderByVersion.class);
extensions.add(PastMeasuresLoader.class);
extensions.add(PastSnapshotFinder.class);
package org.sonar.plugins.core.timemachine;
import com.google.common.collect.*;
+import org.apache.commons.lang.time.DateUtils;
import org.sonar.api.batch.Decorator;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependedUpon;
private void saveNewViolations(DecoratorContext context) {
Measure measure = new Measure(CoreMetrics.NEW_VIOLATIONS);
- for (PastSnapshot variationSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
- int variationIndex = variationSnapshot.getIndex();
+ for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
+ int variationIndex = pastSnapshot.getIndex();
Collection<Measure> children = context.getChildrenMeasures(CoreMetrics.NEW_VIOLATIONS);
- int count = countViolations(context.getViolations(), variationSnapshot.getDate());
+ int count = countViolations(context.getViolations(), pastSnapshot.getTargetDate());
double sum = sumChildren(variationIndex, children) + count;
measure.setVariation(variationIndex, sum);
}
for (RulePriority priority : RulePriority.values()) {
Metric metric = getMetricForSeverity(priority);
Measure measure = new Measure(metric);
- for (PastSnapshot variationSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
- int variationIndex = variationSnapshot.getIndex();
- int count = countViolations(violationsBySeverity.get(priority), variationSnapshot.getDate());
+ for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
+ int variationIndex = pastSnapshot.getIndex();
+ int count = countViolations(violationsBySeverity.get(priority), pastSnapshot.getTargetDate());
Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.metric(metric));
double sum = sumChildren(variationIndex, children) + count;
measure.setVariation(variationIndex, sum);
for (Rule rule : rules) {
RuleMeasure measure = RuleMeasure.createForRule(CoreMetrics.NEW_VIOLATIONS, rule, null);
measure.setRulePriority(ruleToLevel.get(rule));
- for (PastSnapshot variationSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
- int variationIndex = variationSnapshot.getIndex();
- int count = countViolations(violationsByRule.get(rule), variationSnapshot.getDate());
+ for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
+ int variationIndex = pastSnapshot.getIndex();
+ int count = countViolations(violationsByRule.get(rule), pastSnapshot.getTargetDate());
double sum = sumChildren(variationIndex, childrenByRule.get(rule)) + count;
measure.setVariation(variationIndex, sum);
}
private int index;
private String mode, modeParameter;
private Snapshot projectSnapshot;
+ private Date targetDate;
- public PastSnapshot(int index, String mode, Snapshot projectSnapshot) {
- this.index = index;
+ public PastSnapshot(String mode, Date targetDate, Snapshot projectSnapshot) {
this.mode = mode;
+ this.targetDate = targetDate;
this.projectSnapshot = projectSnapshot;
}
+ public PastSnapshot(String mode, Snapshot projectSnapshot) {
+ this.mode = mode;
+ this.projectSnapshot = projectSnapshot;
+ }
+
+ public PastSnapshot setIndex(int index) {
+ this.index = index;
+ return this;
+ }
+
public int getIndex() {
return index;
}
return this;
}
+ public Integer getProjectSnapshotId() {
+ return (projectSnapshot!=null ? projectSnapshot.getId() : null);
+ }
+
+ public Date getTargetDate() {
+ return targetDate;
+ }
+
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchExtension;
-import org.sonar.api.database.model.Snapshot;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class PastSnapshotFinder implements BatchExtension {
-
- public static final String LAST__ANALYSIS_MODE = "last_analysis";
- public static final String DATE_MODE = "date";
- public static final String VERSION_MODE = "version";
- public static final String DAYS_MODE = "days";
-
private PastSnapshotFinderByDays finderByDays;
private PastSnapshotFinderByVersion finderByVersion;
private PastSnapshotFinderByDate finderByDate;
- private PastSnapshotFinderByLastAnalysis finderByLastAnalysis;
+ private PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis;
public PastSnapshotFinder(PastSnapshotFinderByDays finderByDays, PastSnapshotFinderByVersion finderByVersion,
- PastSnapshotFinderByDate finderByDate, PastSnapshotFinderByLastAnalysis finderByLastAnalysis) {
+ PastSnapshotFinderByDate finderByDate, PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis) {
this.finderByDays = finderByDays;
this.finderByVersion = finderByVersion;
this.finderByDate = finderByDate;
- this.finderByLastAnalysis = finderByLastAnalysis;
+ this.finderByPreviousAnalysis = finderByPreviousAnalysis;
}
public PastSnapshot find(Configuration conf, int index) {
return null;
}
- PastSnapshot result = findByDays(index, property);
+ PastSnapshot result = findByDays(property);
if (result == null) {
- result = findByDate(index, property);
+ result = findByDate(property);
if (result == null) {
- result = findByLastAnalysis(index, property);
+ result = findByPreviousAnalysis(property);
if (result == null) {
- result = findByVersion(index, property);
+ result = findByVersion(property);
}
}
}
+
+ if (result != null) {
+ result.setIndex(index);
+ }
+
return result;
}
- private PastSnapshot findByLastAnalysis(int index, String property) {
- if (StringUtils.equals(LAST__ANALYSIS_MODE, property)) {
- Snapshot projectSnapshot = finderByLastAnalysis.findLastAnalysis();
- if (projectSnapshot != null) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- String date = format.format(projectSnapshot.getCreatedAt());
- return new PastSnapshot(index, LAST__ANALYSIS_MODE, projectSnapshot).setModeParameter(date);
- }
+ private PastSnapshot findByPreviousAnalysis(String property) {
+ PastSnapshot pastSnapshot = null;
+ if (StringUtils.equals(PastSnapshotFinderByPreviousAnalysis.MODE, property)) {
+ pastSnapshot = finderByPreviousAnalysis.findByPreviousAnalysis();
}
- return null;
+ return pastSnapshot;
}
- private PastSnapshot findByDate(int index, String property) {
+ private PastSnapshot findByDate(String property) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date = format.parse(property);
- Snapshot projectSnapshot = finderByDate.findByDate(date);
- if (projectSnapshot != null) {
- return new PastSnapshot(index, DATE_MODE, projectSnapshot).setModeParameter(property);
- }
- return null;
+ return finderByDate.findByDate(date);
} catch (ParseException e) {
return null;
}
}
- private PastSnapshot findByVersion(int index, String property) {
- Snapshot projectSnapshot = finderByVersion.findVersion(property);
- if (projectSnapshot != null) {
- return new PastSnapshot(index, VERSION_MODE, projectSnapshot).setModeParameter(property);
- }
- return null;
+ private PastSnapshot findByVersion(String property) {
+ return finderByVersion.findByVersion(property);
}
- private PastSnapshot findByDays(int index, String property) {
+ private PastSnapshot findByDays(String property) {
try {
int days = Integer.parseInt(property);
- Snapshot projectSnapshot = finderByDays.findInDays(days);
- if (projectSnapshot != null) {
- return new PastSnapshot(index, DAYS_MODE, projectSnapshot).setModeParameter(String.valueOf(days));
- }
- return null;
+ return finderByDays.findFromDays(days);
} catch (NumberFormatException e) {
return null;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
+import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
public class PastSnapshotFinderByDate implements BatchExtension{
+
+ public static final String MODE = "date";
+
+
private Snapshot projectSnapshot; // TODO replace by PersistenceManager
private DatabaseSession session;
this.session = session;
}
- Snapshot findByDate(Date date) {
+ PastSnapshot findByDate(Date date) {
String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt>=:date AND resourceId=:resourceId AND status=:status order by createdAt asc";
List<Snapshot> snapshots = session.createQuery(hql)
.setParameter("date", date)
.setParameter("status", Snapshot.STATUS_PROCESSED)
.setMaxResults(1)
.getResultList();
- return snapshots.isEmpty() ? null : snapshots.get(0);
+ if (snapshots.isEmpty()) {
+ return null;
+ }
+
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+ return new PastSnapshot(MODE, date, snapshots.get(0)).setModeParameter(format.format(date));
}
}
import java.util.List;
public class PastSnapshotFinderByDays implements BatchExtension {
+
+ public static final String MODE = "days";
+
private Snapshot projectSnapshot; // TODO replace by PersistenceManager
private DatabaseSession session;
this.session = session;
}
- Snapshot findInDays(int days) {
+ PastSnapshot findFromDays(int days) {
Date targetDate = DateUtils.addDays(projectSnapshot.getCreatedAt(), -days);
String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt>=:from AND createdAt<:to order by createdAt asc";
List<Snapshot> snapshots = session.createQuery(hql)
.setMaxResults(1)
.getResultList();
- return snapshots.isEmpty() ? null : snapshots.get(0);
+ if (snapshots.isEmpty()) {
+ return null;
+ }
+ return new PastSnapshot(MODE, targetDate, snapshots.get(0)).setModeParameter(String.valueOf(days));
}
}
+++ /dev/null
-/*
- * 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.sonar.api.BatchExtension;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-
-import java.util.List;
-
-public class PastSnapshotFinderByLastAnalysis implements BatchExtension {
- private Snapshot projectSnapshot; // TODO replace by PersistenceManager
- private DatabaseSession session;
-
- public PastSnapshotFinderByLastAnalysis(Snapshot projectSnapshot, DatabaseSession session) {
- this.projectSnapshot = projectSnapshot;
- this.session = session;
- }
-
- Snapshot findLastAnalysis() {
- String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=true order by createdAt desc";
- List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("date", projectSnapshot.getCreatedAt())
- .setParameter("resourceId", projectSnapshot.getResourceId())
- .setParameter("status", Snapshot.STATUS_PROCESSED)
- .setMaxResults(1)
- .getResultList();
-
- return snapshots.isEmpty() ? null : snapshots.get(0);
- }
-
-}
--- /dev/null
+/*
+ * 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.sonar.api.BatchExtension;
+import org.sonar.api.database.DatabaseSession;
+import org.sonar.api.database.model.Snapshot;
+
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension {
+ public static final String MODE = "previous_analysis";
+
+ private Snapshot projectSnapshot; // TODO replace by PersistenceManager
+ private DatabaseSession session;
+
+ public PastSnapshotFinderByPreviousAnalysis(Snapshot projectSnapshot, DatabaseSession session) {
+ this.projectSnapshot = projectSnapshot;
+ this.session = session;
+ }
+
+ PastSnapshot findByPreviousAnalysis() {
+ String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=true order by createdAt desc";
+ List<Snapshot> snapshots = session.createQuery(hql)
+ .setParameter("date", projectSnapshot.getCreatedAt())
+ .setParameter("resourceId", projectSnapshot.getResourceId())
+ .setParameter("status", Snapshot.STATUS_PROCESSED)
+ .setMaxResults(1)
+ .getResultList();
+
+ if (snapshots.isEmpty()) {
+ return null;
+ }
+ Snapshot snapshot = snapshots.get(0);
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+ return new PastSnapshot(MODE, snapshot.getCreatedAt(), snapshot).setModeParameter(format.format(snapshot.getCreatedAt()));
+ }
+
+}
import java.util.List;
public class PastSnapshotFinderByVersion implements BatchExtension {
+
+ public static final String MODE = "version";
+
private Snapshot projectSnapshot; // TODO replace by PersistenceManager
private DatabaseSession session;
this.session = session;
}
- Snapshot findVersion(String version) {
+ PastSnapshot findByVersion(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)
.setMaxResults(1)
.getResultList();
- return snapshots.isEmpty() ? null : snapshots.get(0);
+ if (snapshots.isEmpty()) {
+ return null;
+ }
+ Snapshot snapshot = snapshots.get(0);
+ return new PastSnapshot(MODE, snapshot.getCreatedAt(), snapshot).setModeParameter(snapshot.getVersion());
}
}
PastSnapshot pastSnapshot = mock(PastSnapshot.class);
when(pastSnapshot.getIndex()).thenReturn(1);
- when(pastSnapshot.getDate()).thenReturn(fiveDaysAgo);
+ when(pastSnapshot.getTargetDate()).thenReturn(fiveDaysAgo);
PastSnapshot pastSnapshot2 = mock(PastSnapshot.class);
when(pastSnapshot2.getIndex()).thenReturn(2);
- when(pastSnapshot2.getDate()).thenReturn(tenDaysAgo);
+ when(pastSnapshot2.getTargetDate()).thenReturn(tenDaysAgo);
TimeMachineConfiguration timeMachineConfiguration = mock(TimeMachineConfiguration.class);
when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(Arrays.asList(pastSnapshot, pastSnapshot2));
Date date = DATE_FORMAT.parse("2008-11-22");
- Snapshot snapshot = finder.findByDate(date);
- assertThat(snapshot.getId(), is(1006));
+ PastSnapshot pastSnapshot = finder.findByDate(date);
+ assertThat(pastSnapshot.getProjectSnapshotId(), is(1006));
}
@Test
Date date = DATE_FORMAT.parse("2008-11-24");
- Snapshot snapshot = finder.findByDate(date);
- assertThat(snapshot.getId(), is(1009));
+ PastSnapshot pastSnapshot = finder.findByDate(date);
+ assertThat(pastSnapshot.getProjectSnapshotId(), is(1009));
}
}
import java.text.ParseException;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(projectSnapshot, getSession());
- assertThat(finder.findInDays(50).getId(), is(1000));
+ assertThat(finder.findFromDays(50).getProjectSnapshotId(), is(1000));
}
@Test
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(projectSnapshot, getSession());
- assertThat(finder.findInDays(7).getId(), is(1006));
+ assertThat(finder.findFromDays(7).getProjectSnapshotId(), is(1006));
}
@Test
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(projectSnapshot, getSession());
- assertThat(finder.findInDays(1), IsNull.<Object>nullValue());
+ assertThat(finder.findFromDays(1), nullValue());
}
}
+++ /dev/null
-/*
- * 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 java.text.ParseException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-
-public class PastSnapshotFinderByLastAnalysisTest extends AbstractDbUnitTestCase {
-
- @Test
- public void shouldFindLastAnalysis() throws ParseException {
- setupData("shouldFindLastAnalysis");
-
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
- PastSnapshotFinderByLastAnalysis finder = new PastSnapshotFinderByLastAnalysis(projectSnapshot, getSession());
-
- Snapshot snapshot = finder.findLastAnalysis();
- assertThat(snapshot.getId(), is(1009));
- }
-
- @Test
- public void shouldNotFindLastAnalysis() throws ParseException {
- setupData("shouldNotFindLastAnalysis");
-
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
- PastSnapshotFinderByLastAnalysis finder = new PastSnapshotFinderByLastAnalysis(projectSnapshot, getSession());
-
- assertNull(finder.findLastAnalysis());
- }
-}
--- /dev/null
+/*
+ * 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 java.text.ParseException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+public class PastSnapshotFinderByPreviousAnalysisTest extends AbstractDbUnitTestCase {
+
+ @Test
+ public void shouldFindPreviousAnalysis() throws ParseException {
+ setupData("shouldFindPreviousAnalysis");
+
+ Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
+ PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(projectSnapshot, getSession());
+
+ PastSnapshot pastSnapshot = finder.findByPreviousAnalysis();
+ assertThat(pastSnapshot.getProjectSnapshotId(), is(1009));
+ }
+
+ @Test
+ public void shouldNotFindPreviousAnalysis() throws ParseException {
+ setupData("shouldNotFindPreviousAnalysis");
+
+ Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
+ PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(projectSnapshot, getSession());
+
+ assertNull(finder.findByPreviousAnalysis());
+ }
+}
Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(currentProjectSnapshot, getSession());
- assertThat(finder.findVersion("1.1").getId(), is(1009));
+ assertThat(finder.findByVersion("1.1").getProjectSnapshotId(), is(1009));
}
@Test
Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(currentProjectSnapshot, getSession());
- assertThat(finder.findVersion("1.0"), nullValue());
+ assertThat(finder.findByVersion("1.0"), nullValue());
}
}
import java.util.Date;
import static junit.framework.Assert.assertNull;
+import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
private PastSnapshotFinderByDays finderByDays;
private PastSnapshotFinderByDate finderByDate;
private PastSnapshotFinderByVersion finderByVersion;
- private PastSnapshotFinderByLastAnalysis finderByLastAnalysis;
+ private PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis;
private PastSnapshotFinder finder;
@Before
finderByDays = mock(PastSnapshotFinderByDays.class);
finderByDate = mock(PastSnapshotFinderByDate.class);
finderByVersion = mock(PastSnapshotFinderByVersion.class);
- finderByLastAnalysis = mock(PastSnapshotFinderByLastAnalysis.class);
- finder = new PastSnapshotFinder(finderByDays, finderByVersion, finderByDate, finderByLastAnalysis);
+ finderByPreviousAnalysis = mock(PastSnapshotFinderByPreviousAnalysis.class);
+ finder = new PastSnapshotFinder(finderByDays, finderByVersion, finderByDate, finderByPreviousAnalysis);
}
@Test
public void shouldFindByNumberOfDays() {
- when(finderByDays.findInDays(30)).thenReturn(new Snapshot());
+ when(finderByDays.findFromDays(30)).thenReturn(new PastSnapshot("days", null).setModeParameter("30"));
PastSnapshot variationSnapshot = finder.find(1, "30");
- verify(finderByDays).findInDays(30);
+ verify(finderByDays).findFromDays(30);
assertNotNull(variationSnapshot);
assertThat(variationSnapshot.getIndex(), is(1));
assertThat(variationSnapshot.getMode(), is("days"));
public void shouldNotFindByNumberOfDays() {
PastSnapshot variationSnapshot = finder.find(1, "30");
- verify(finderByDays).findInDays(30);
+ verify(finderByDays).findFromDays(30);
assertNull(variationSnapshot);
}
public void shouldFindByDate() throws ParseException {
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
final Date date = format.parse("2010-05-18");
- when(finderByDate.findByDate(date)).thenReturn(new Snapshot());
+ when(finderByDate.findByDate(date)).thenReturn(new PastSnapshot("date", new Snapshot()));
PastSnapshot variationSnapshot = finder.find(2, "2010-05-18");
}));
assertThat(variationSnapshot.getIndex(), is(2));
assertThat(variationSnapshot.getMode(), is("date"));
- assertThat(variationSnapshot.getModeParameter(), is("2010-05-18"));
+ assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
}
@Test
}
@Test
- public void shouldFindLastAnalysis() throws ParseException {
+ public void shouldFindByPreviousAnalysis() throws ParseException {
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
final Date date = format.parse("2010-05-18");
Snapshot snapshot = new Snapshot();
snapshot.setCreatedAt(date);
- when(finderByLastAnalysis.findLastAnalysis()).thenReturn(snapshot);
+ when(finderByPreviousAnalysis.findByPreviousAnalysis()).thenReturn(new PastSnapshot(PastSnapshotFinderByPreviousAnalysis.MODE, snapshot));
- PastSnapshot variationSnapshot = finder.find(2, "last_analysis");
+ PastSnapshot variationSnapshot = finder.find(2, PastSnapshotFinderByPreviousAnalysis.MODE);
- verify(finderByLastAnalysis).findLastAnalysis();
+ verify(finderByPreviousAnalysis).findByPreviousAnalysis();
assertThat(variationSnapshot.getIndex(), is(2));
- assertThat(variationSnapshot.getMode(), is("last_analysis"));
- assertThat(variationSnapshot.getModeParameter(), is("2010-05-18"));
+ assertThat(variationSnapshot.getMode(), is(PastSnapshotFinderByPreviousAnalysis.MODE));
+ assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
}
@Test
- public void shouldNotFindLastAnalysis() {
- when(finderByLastAnalysis.findLastAnalysis()).thenReturn(null);
+ public void shouldNotFindPreviousAnalysis() {
+ when(finderByPreviousAnalysis.findByPreviousAnalysis()).thenReturn(null);
- PastSnapshot variationSnapshot = finder.find(2, "last_analysis");
+ PastSnapshot variationSnapshot = finder.find(2, PastSnapshotFinderByPreviousAnalysis.MODE);
- verify(finderByLastAnalysis).findLastAnalysis();
+ verify(finderByPreviousAnalysis).findByPreviousAnalysis();
assertNull(variationSnapshot);
}
@Test
public void shouldFindByVersion() {
- when(finderByVersion.findVersion("1.2")).thenReturn(new Snapshot());
+ when(finderByVersion.findByVersion("1.2")).thenReturn(new PastSnapshot("version", new Snapshot()));
PastSnapshot variationSnapshot = finder.find(2, "1.2");
- verify(finderByVersion).findVersion("1.2");
+ verify(finderByVersion).findByVersion("1.2");
assertThat(variationSnapshot.getIndex(), is(2));
assertThat(variationSnapshot.getMode(), is("version"));
- assertThat(variationSnapshot.getModeParameter(), is("1.2"));
+ assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
}
@Test
public void shouldNotFindVersion() {
- when(finderByVersion.findVersion("1.2")).thenReturn(null);
+ when(finderByVersion.findByVersion("1.2")).thenReturn(null);
PastSnapshot variationSnapshot = finder.find(2, "1.2");
- verify(finderByVersion).findVersion("1.2");
+ verify(finderByVersion).findByVersion("1.2");
assertNull(variationSnapshot);
}
@Test
public void shouldNotFailIfUnknownFormat() {
- when(finderByLastAnalysis.findLastAnalysis()).thenReturn(new Snapshot()); // should not be called
+ when(finderByPreviousAnalysis.findByPreviousAnalysis()).thenReturn(new PastSnapshot(PastSnapshotFinderByPreviousAnalysis.MODE, new Snapshot())); // should not be called
assertNull(finder.find(2, "foooo"));
}
}
setupData("shared");
TimeMachineConfiguration conf = mock(TimeMachineConfiguration.class);
- PastSnapshot vs1 = new PastSnapshot(1, "days", getSession().getSingleResult(Snapshot.class, "id", 100))
- .setModeParameter("30");
- PastSnapshot vs3 = new PastSnapshot(3, "version", getSession().getSingleResult(Snapshot.class, "id", 300))
- .setModeParameter("1.2.3");
+ PastSnapshot vs1 = new PastSnapshot("days", getSession().getSingleResult(Snapshot.class, "id", 100))
+ .setModeParameter("30").setIndex(1);
+ PastSnapshot vs3 = new PastSnapshot("version", getSession().getSingleResult(Snapshot.class, "id", 300))
+ .setModeParameter("1.2.3").setIndex(3);
when(conf.getProjectPastSnapshots()).thenReturn(Arrays.asList(vs1, vs3));
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
public void shouldInitVariationSnapshots() throws ParseException {
PropertiesConfiguration conf = new PropertiesConfiguration();
PastSnapshotFinder snapshotReferenceFinder = mock(PastSnapshotFinder.class);
- when(snapshotReferenceFinder.find(conf, 1)).thenReturn(new PastSnapshot(1, "days", newSnapshot("2010-10-15")));
- when(snapshotReferenceFinder.find(conf, 3)).thenReturn(new PastSnapshot(3, "days", newSnapshot("2010-10-13")));
+ when(snapshotReferenceFinder.find(conf, 1)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-15")));
+ when(snapshotReferenceFinder.find(conf, 3)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-13")));
TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(conf, snapshotReferenceFinder);
Resource javaPackage = new JavaPackage("org.foo");
PastMeasuresLoader pastMeasuresLoader = mock(PastMeasuresLoader.class);
- PastSnapshot pastSnapshot1 = new PastSnapshot(1, "days", new Snapshot());
- PastSnapshot pastSnapshot3 = new PastSnapshot(3, "days", new Snapshot());
+ PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Snapshot()).setIndex(1);
+ PastSnapshot pastSnapshot3 = new PastSnapshot("days", new Snapshot()).setIndex(3);
// first past analysis
when(pastMeasuresLoader.getPastMeasures(javaPackage, pastSnapshot1)).thenReturn(Arrays.asList(
+++ /dev/null
-<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]"/>
-
- <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[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-22 13:58:00.00" version="1.1" path=""
- status="P" islast="false" depth="0" />
-
-
- <!-- last analysis -->
- <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[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-25 13:58:00.00" version="1.1" path=""
- status="P" islast="true" depth="0" />
-
- <!-- current analysis -->
- <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[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-27 13:58:00.00" version="1.2-SNAPSHOT" path=""
- status="U" islast="false" depth="0" />
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-<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]"/>
-
-
- <!-- unprocessed analysis -->
- <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[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-25 13:58:00.00" version="1.1" path=""
- status="U" islast="false" depth="0" />
-
- <!-- current analysis -->
- <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[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-27 13:58:00.00" version="1.2-SNAPSHOT" path=""
- status="U" islast="false" depth="0" />
-
-</dataset>
\ No newline at end of file
--- /dev/null
+<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]"/>
+
+ <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[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-22 13:58:00.00" version="1.1" path=""
+ status="P" islast="false" depth="0" />
+
+
+ <!-- last analysis -->
+ <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[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-25 13:58:00.00" version="1.1" path=""
+ status="P" islast="true" depth="0" />
+
+ <!-- current analysis -->
+ <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[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-27 13:58:00.00" version="1.2-SNAPSHOT" path=""
+ status="U" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file
--- /dev/null
+<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]"/>
+
+
+ <!-- unprocessed analysis -->
+ <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[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-25 13:58:00.00" version="1.1" path=""
+ status="U" islast="false" depth="0" />
+
+ <!-- current analysis -->
+ <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[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-27 13:58:00.00" version="1.2-SNAPSHOT" path=""
+ status="U" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file
label = "Last %s days" % mode_param
elsif mode=='version'
label = "Version %s" % mode_param
- elsif mode=='last_analysis'
- label = "Last analysis (%s)" % localize(Date.parse(mode_param))
+ elsif mode=='previous_analysis'
+ label = "Previous analysis (%s)" % localize(Date.parse(mode_param))
elsif mode=='date'
label = localize(Date.parse(mode_param))
end