--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.computation.queue;
+
+import com.google.common.base.Optional;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.sonar.db.ce.CeActivityDto;
+import org.sonar.db.ce.CeTaskTypes;
+import org.sonar.server.computation.queue.report.ReportTaskProcessor;
+import org.sonar.server.computation.log.CeLogging;
+
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+public class CeWorkerRunnableImplTest {
+
+ CeQueue queue = mock(CeQueueImpl.class);
+ ReportTaskProcessor taskProcessor = mock(ReportTaskProcessor.class);
+ CeLogging ceLogging = mock(CeLogging.class);
+ CeWorkerRunnable underTest = new CeWorkerRunnableImpl(queue, taskProcessor, ceLogging);
+
+ @Test
+ public void no_pending_tasks_in_queue() throws Exception {
+ when(queue.peek()).thenReturn(Optional.<CeTask>absent());
+
+ underTest.run();
+
+ verifyZeroInteractions(taskProcessor, ceLogging);
+ }
+
+ @Test
+ public void peek_and_process_task() throws Exception {
+ CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin(null).build();
+ when(queue.peek()).thenReturn(Optional.of(task));
+
+ underTest.run();
+
+ InOrder inOrder = Mockito.inOrder(ceLogging, taskProcessor, queue);
+ inOrder.verify(ceLogging).initForTask(task);
+ inOrder.verify(taskProcessor).process(task);
+ inOrder.verify(queue).remove(task, CeActivityDto.Status.SUCCESS);
+ inOrder.verify(ceLogging).clearForTask();
+ }
+
+ @Test
+ public void fail_to_process_task() throws Exception {
+ CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin(null).build();
+ when(queue.peek()).thenReturn(Optional.of(task));
+ doThrow(new IllegalStateException()).when(taskProcessor).process(task);
+
+ underTest.run();
+
+ InOrder inOrder = Mockito.inOrder(ceLogging, taskProcessor, queue);
+ inOrder.verify(ceLogging).initForTask(task);
+ inOrder.verify(taskProcessor).process(task);
+ inOrder.verify(queue).remove(task, CeActivityDto.Status.FAILED);
+ inOrder.verify(ceLogging).clearForTask();
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.computation.queue;
-
-import com.google.common.base.Optional;
-import org.junit.Test;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
-import org.sonar.db.ce.CeActivityDto;
-import org.sonar.db.ce.CeTaskTypes;
-import org.sonar.server.computation.queue.report.ReportTaskProcessor;
-import org.sonar.server.computation.log.CeLogging;
-
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class CeWorkerRunnableTest {
-
- CeQueue queue = mock(CeQueueImpl.class);
- ReportTaskProcessor taskProcessor = mock(ReportTaskProcessor.class);
- CeLogging ceLogging = mock(CeLogging.class);
- CeWorkerRunnable underTest = new CeWorkerRunnableImpl(queue, taskProcessor, ceLogging);
-
- @Test
- public void no_pending_tasks_in_queue() throws Exception {
- when(queue.peek()).thenReturn(Optional.<CeTask>absent());
-
- underTest.run();
-
- verifyZeroInteractions(taskProcessor, ceLogging);
- }
-
- @Test
- public void peek_and_process_task() throws Exception {
- CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin(null).build();
- when(queue.peek()).thenReturn(Optional.of(task));
-
- underTest.run();
-
- InOrder inOrder = Mockito.inOrder(ceLogging, taskProcessor, queue);
- inOrder.verify(ceLogging).initForTask(task);
- inOrder.verify(taskProcessor).process(task);
- inOrder.verify(queue).remove(task, CeActivityDto.Status.SUCCESS);
- inOrder.verify(ceLogging).clearForTask();
- }
-
- @Test
- public void fail_to_process_task() throws Exception {
- CeTask task = new CeTask.Builder().setUuid("TASK_1").setType(CeTaskTypes.REPORT).setComponentUuid("PROJECT_1").setSubmitterLogin(null).build();
- when(queue.peek()).thenReturn(Optional.of(task));
- doThrow(new IllegalStateException()).when(taskProcessor).process(task);
-
- underTest.run();
-
- InOrder inOrder = Mockito.inOrder(ceLogging, taskProcessor, queue);
- inOrder.verify(ceLogging).initForTask(task);
- inOrder.verify(taskProcessor).process(task);
- inOrder.verify(queue).remove(task, CeActivityDto.Status.FAILED);
- inOrder.verify(ceLogging).clearForTask();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.computation.step;
-
-import java.util.Collection;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.server.computation.debt.Characteristic;
-import org.sonar.server.computation.debt.DebtModelHolderImpl;
-import org.sonar.server.computation.debt.MutableDebtModelHolder;
-import org.sonar.test.DbTests;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class FeedDebtModelStepTest extends BaseStepTest {
-
- @Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
- DbClient dbClient = dbTester.getDbClient();
-
- DbSession dbSession;
-
- MutableDebtModelHolder debtModelHolder = new DebtModelHolderImpl();
-
- LoadDebtModelStep underTest;
-
- @Before
- public void setUp() {
- dbTester.truncateTables();
- dbSession = dbClient.openSession(false);
-
- underTest = new LoadDebtModelStep(dbClient, debtModelHolder);
- }
-
- @After
- public void tearDown() {
- dbSession.close();
- }
-
- @Override
- protected ComputationStep step() {
- return underTest;
- }
-
- @Test
- public void feed_characteristics() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- underTest.execute();
-
- Collection<Characteristic> rootChars = debtModelHolder.getRootCharacteristics();
- assertThat(rootChars).extracting("id").containsOnly(1);
- assertThat(rootChars).extracting("key").containsOnly("PORTABILITY");
-
- Characteristic subChar = debtModelHolder.getCharacteristicById(1);
- assertThat(subChar).isNotNull();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.step;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.ce.measure.MeasureComputer;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.Metrics;
-import org.sonar.server.computation.measure.MeasureComputersHolderImpl;
-import org.sonar.server.computation.measure.api.MeasureComputerWrapper;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.util.Arrays.array;
-import static org.sonar.api.measures.CoreMetrics.CLASSES_KEY;
-import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
-import static org.sonar.api.measures.Metric.ValueType.DATA;
-import static org.sonar.api.measures.Metric.ValueType.FLOAT;
-import static org.sonar.api.measures.Metric.ValueType.INT;
-import static org.sonar.api.measures.Metric.ValueType.MILLISEC;
-
-public class FeedMeasureComputersTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- private static final String NEW_METRIC_1 = "metric1";
- private static final String NEW_METRIC_2 = "metric2";
- private static final String NEW_METRIC_3 = "metric3";
- private static final String NEW_METRIC_4 = "metric4";
-
- MeasureComputersHolderImpl holder = new MeasureComputersHolderImpl();
-
- @Test
- public void support_core_metrics_as_input_metrics() throws Exception {
- MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1))};
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
- underTest.execute();
-
- assertThat(holder.getMeasureComputers()).hasSize(1);
- }
-
- @Test
- public void support_plugin_metrics_as_input_metrics() throws Exception {
- MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_2))};
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
- underTest.execute();
-
- assertThat(holder.getMeasureComputers()).hasSize(1);
- }
-
- @Test
- public void sort_computers() throws Exception {
- // Should be the last to be executed
- MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
- // Should be the first to be executed
- MeasureComputer measureComputer2 = newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_2));
- // Should be the second to be executed
- MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
- MeasureComputer[] computers = new MeasureComputer[] {measureComputer1, measureComputer2, measureComputer3};
-
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
- underTest.execute();
-
- List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
- assertThat(result).hasSize(3);
- assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
- assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
- assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
- }
-
- @Test
- public void sort_computers_when_one_computer_has_no_input_metric() throws Exception {
- // Should be the last to be executed
- MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
- // Should be the first to be executed
- MeasureComputer measureComputer2 = newMeasureComputer(new String[] {}, array(NEW_METRIC_2));
- // Should be the second to be executed
- MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
- MeasureComputer[] computers = new MeasureComputer[] {measureComputer1, measureComputer2, measureComputer3};
-
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
- underTest.execute();
-
- List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
- assertThat(result).hasSize(3);
- assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
- assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
- assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
- }
-
- @Test
- public void fail_with_ISE_when_input_metric_is_unknown() throws Exception {
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Metric 'unknown' cannot be used as an input metric as it's not a core metric and no plugin declare this metric");
-
- MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array("unknown"), array(NEW_METRIC_4))};
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
- underTest.execute();
- }
-
- @Test
- public void fail_with_ISE_when_output_metric_is_not_define_by_plugin() throws Exception {
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Metric 'unknown' cannot be used as an output metric as no plugin declare this metric");
-
- MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_4), array("unknown"))};
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
- underTest.execute();
- }
-
- @Test
- public void fail_with_ISE_when_output_metric_is_a_core_metric() throws Exception {
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Metric 'ncloc' cannot be used as an output metric as it's a core metric");
-
- MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_4), array(NCLOC_KEY))};
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
- underTest.execute();
- }
-
- @Test
- public void not_fail_if_input_metrics_are_same_as_output_metrics() throws Exception {
- MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_1))};
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
- underTest.execute();
-
- assertThat(holder.getMeasureComputers()).hasSize(1);
- }
-
- @Test
- public void return_empty_list_when_no_measure_computers() throws Exception {
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()));
- underTest.execute();
-
- assertThat(holder.getMeasureComputers()).isEmpty();
- }
-
- @Test
- public void return_empty_list_when_no_metrics_neither_measure_computers() throws Exception {
- ComputationStep underTest = new LoadMeasureComputersStep(holder);
- underTest.execute();
-
- assertThat(holder.getMeasureComputers()).isEmpty();
- }
-
- @Test
- public void fail_with_ISE_when_no_metrics_are_defined_by_plugin_but_measure_computer_use_a_new_metric() throws Exception {
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Metric 'metric1' cannot be used as an output metric as no plugin declare this metric");
-
- MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1))};
- ComputationStep underTest = new LoadMeasureComputersStep(holder, computers);
- underTest.execute();
- }
-
- @Test
- public void fail_with_ISE_when_two_measure_computers_generate_the_same_output_metric() throws Exception {
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Output metric 'metric1' is already defined by another measure computer 'TestMeasureComputer'");
-
- MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1)), newMeasureComputer(array(CLASSES_KEY), array(NEW_METRIC_1))};
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
- underTest.execute();
- }
-
- @Test
- public void fail_with_IAE_when_creating_measure_computer_definition_without_using_the_builder_and_with_invalid_output_metrics() throws Exception {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("At least one output metric must be defined");
-
- MeasureComputer measureComputer = new MeasureComputer() {
- @Override
- public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {
- // Create a instance of MeasureComputerDefinition without using the builder
- return new MeasureComputer.MeasureComputerDefinition(){
- @Override
- public Set<String> getInputMetrics() {
- return ImmutableSet.of(NCLOC_KEY);
- }
-
- @Override
- public Set<String> getOutputMetrics() {
- // Empty output metric is not allowed !
- return Collections.emptySet();
- }
- };
- }
-
- @Override
- public void compute(MeasureComputerContext context) {
- // Nothing needs to be done as we're only testing metada
- }
- };
-
- MeasureComputer[] computers = new MeasureComputer[] {measureComputer};
- ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
- underTest.execute();
- }
-
- private static MeasureComputer newMeasureComputer(final String[] inputMetrics, final String[] outputMetrics) {
- return new MeasureComputer() {
- @Override
- public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {
- return defContext.newDefinitionBuilder()
- .setInputMetrics(inputMetrics)
- .setOutputMetrics(outputMetrics)
- .build();
- }
-
- @Override
- public void compute(MeasureComputerContext context) {
- // Nothing needs to be done as we're only testing metada
- }
-
- @Override
- public String toString() {
- return "TestMeasureComputer";
- }
- };
- }
-
- private static class TestMetrics implements Metrics {
- @Override
- public List<Metric> getMetrics() {
- return Lists.<Metric>newArrayList(
- new Metric.Builder(NEW_METRIC_1, "metric1", DATA).create(),
- new Metric.Builder(NEW_METRIC_2, "metric2", MILLISEC).create(),
- new Metric.Builder(NEW_METRIC_3, "metric3", INT).create(),
- new Metric.Builder(NEW_METRIC_4, "metric4", FLOAT).create()
- );
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation.step;
-
-import com.tngtech.java.junit.dataprovider.DataProvider;
-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.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.sonar.api.CoreProperties;
-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 org.sonar.db.DbTester;
-import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolderRule;
-import org.sonar.server.computation.batch.TreeRootHolderRule;
-import org.sonar.server.computation.component.Component;
-import org.sonar.server.computation.component.ReportComponent;
-import org.sonar.server.computation.component.SettingsRepository;
-import org.sonar.server.computation.component.ViewsComponent;
-import org.sonar.server.computation.period.Period;
-import org.sonar.server.computation.period.PeriodsHolderImpl;
-import org.sonar.test.DbTests;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@Category(DbTests.class)
-@RunWith(DataProviderRunner.class)
-public class FeedPeriodsStepTest extends BaseStepTest {
-
- private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
- private static final String ROOT_KEY = "ROOT_KEY";
- private static final ReportComponent PROJECT_ROOT = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(ROOT_KEY).setVersion("1.1").build();
- private static final ViewsComponent VIEW_ROOT = ViewsComponent.builder(Component.Type.VIEW, ROOT_KEY).setUuid("ABCD").build();
-
- @Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @Rule
- public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
- @Rule
- public MutableAnalysisMetadataHolderRule analysisMetadataHolder = new MutableAnalysisMetadataHolderRule();
- @Rule
- public LogTester logTester = new LogTester();
-
- PeriodsHolderImpl periodsHolder = new PeriodsHolderImpl();
- DbClient dbClient = dbTester.getDbClient();
- Settings settings = new Settings();
- SettingsRepository settingsRepository = mock(SettingsRepository.class);
-
- LoadPeriodsStep underTest;
-
- @Override
- protected ComputationStep step() {
- return underTest;
- }
-
- @Before
- public void setUp() throws Exception {
- analysisMetadataHolder.setAnalysisDate(DATE_FORMAT.parse("2008-11-30"));
-
- underTest = new LoadPeriodsStep(dbClient, settingsRepository, treeRootHolder, analysisMetadataHolder, periodsHolder);
- }
-
- private void setupRoot(Component root) {
- treeRootHolder.setRoot(root);
- when(settingsRepository.getSettings(root)).thenReturn(settings);
- }
-
- @DataProvider
- public static Object[][] projectAndViewRoots() {
- return new Object[][] {
- {PROJECT_ROOT},
- {VIEW_ROOT}
- };
- }
-
- @Test
- @UseDataProvider("projectAndViewRoots")
- public void no_period_on_first_analysis(Component root) {
- setupRoot(root);
-
- // No project, no snapshot
-
- underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
- }
-
- @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);
- assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
- assertThat(period.getModeParameter()).isEqualTo(textDate);
- assertThat(period.getSnapshotDate()).isEqualTo(1227358680000L);
- assertThat(period.getSnapshotId()).isEqualTo(1003L);
- }
-
- @Test
- @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();
- }
-
- @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();
- }
-
- @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();
- }
-
- @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
- assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
- assertThat(period.getModeParameter()).isEqualTo(textDate);
- assertThat(period.getSnapshotDate()).isEqualTo(1227358680000L);
- assertThat(period.getSnapshotId()).isEqualTo(1003L);
-
- assertThat(logTester.logs()).hasSize(1);
- assertThat(logTester.logs().get(0)).startsWith("Compare to date 2008-11-22 (analysis of ");
- }
-
- @Test
- @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);
- assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
- assertThat(period.getModeParameter()).isEqualTo(date);
- assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L);
- assertThat(period.getSnapshotId()).isEqualTo(1004L);
- }
-
- @Test
- @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();
- }
-
- @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);
- assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DAYS);
- assertThat(period.getModeParameter()).isEqualTo("10");
- assertThat(period.getSnapshotDate()).isEqualTo(1227157200000L);
- assertThat(period.getSnapshotId()).isEqualTo(1002L);
-
- assertThat(logTester.logs()).hasSize(1);
- assertThat(logTester.logs().get(0)).startsWith("Compare over 10 days (2008-11-20, analysis of ");
- }
-
- @Test
- @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();
- }
-
- @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);
- assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
- assertThat(period.getModeParameter()).isNotNull();
- assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L);
- assertThat(period.getSnapshotId()).isEqualTo(1004L);
-
- assertThat(logTester.logs()).hasSize(1);
- assertThat(logTester.logs().get(0)).startsWith("Compare to previous analysis (");
- }
-
- @Test
- @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();
- }
-
- @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);
- assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
- 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
- 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");
-
- 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);
- assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
- assertThat(period.getModeParameter()).isEqualTo("0.9");
- assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);
- assertThat(period.getSnapshotId()).isEqualTo(1000L);
- }
-
- @Test
- @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();
- }
-
- @Test
- @UseDataProvider("projectAndViewRoots")
- public void no_period_by_previous_version_when_no_event_version(Component root) {
- setupRoot(root);
-
- dbTester.prepareDbUnit(getClass(), "no_previous_version.xml");
-
- settings.setProperty("sonar.timemachine.period1", "previous_version");
-
- underTest.execute();
- assertThat(periodsHolder.getPeriods()).isEmpty();
- }
-
- @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);
- assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION);
- assertThat(period.getModeParameter()).isEqualTo("0.9");
- assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);
- assertThat(period.getSnapshotId()).isEqualTo(1000L);
-
- assertThat(logTester.logs()).hasSize(1);
- assertThat(logTester.logs().get(0)).startsWith("Compare to version (0.9) (");
- }
-
- @Test
- @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(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);
- 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_PREVIOUS_VERSION);
- assertThat(periods.get(3).getIndex()).isEqualTo(4);
- assertThat(periods.get(3).getSnapshotDate()).isEqualTo(1226494680000L);
-
- assertThat(periods.get(4).getMode()).isEqualTo(CoreProperties.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(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);
-
- 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);
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.computation.step;
+
+import java.util.Collection;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.server.computation.debt.Characteristic;
+import org.sonar.server.computation.debt.DebtModelHolderImpl;
+import org.sonar.server.computation.debt.MutableDebtModelHolder;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class LoadDebtModelStepTest extends BaseStepTest {
+
+ @Rule
+ public DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+ DbClient dbClient = dbTester.getDbClient();
+
+ DbSession dbSession;
+
+ MutableDebtModelHolder debtModelHolder = new DebtModelHolderImpl();
+
+ LoadDebtModelStep underTest;
+
+ @Before
+ public void setUp() {
+ dbTester.truncateTables();
+ dbSession = dbClient.openSession(false);
+
+ underTest = new LoadDebtModelStep(dbClient, debtModelHolder);
+ }
+
+ @After
+ public void tearDown() {
+ dbSession.close();
+ }
+
+ @Override
+ protected ComputationStep step() {
+ return underTest;
+ }
+
+ @Test
+ public void feed_characteristics() {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+ underTest.execute();
+
+ Collection<Characteristic> rootChars = debtModelHolder.getRootCharacteristics();
+ assertThat(rootChars).extracting("id").containsOnly(1);
+ assertThat(rootChars).extracting("key").containsOnly("PORTABILITY");
+
+ Characteristic subChar = debtModelHolder.getCharacteristicById(1);
+ assertThat(subChar).isNotNull();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.step;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.ce.measure.MeasureComputer;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.Metrics;
+import org.sonar.server.computation.measure.MeasureComputersHolderImpl;
+import org.sonar.server.computation.measure.api.MeasureComputerWrapper;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.util.Arrays.array;
+import static org.sonar.api.measures.CoreMetrics.CLASSES_KEY;
+import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
+import static org.sonar.api.measures.Metric.ValueType.DATA;
+import static org.sonar.api.measures.Metric.ValueType.FLOAT;
+import static org.sonar.api.measures.Metric.ValueType.INT;
+import static org.sonar.api.measures.Metric.ValueType.MILLISEC;
+
+public class LoadMeasureComputersStepTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private static final String NEW_METRIC_1 = "metric1";
+ private static final String NEW_METRIC_2 = "metric2";
+ private static final String NEW_METRIC_3 = "metric3";
+ private static final String NEW_METRIC_4 = "metric4";
+
+ MeasureComputersHolderImpl holder = new MeasureComputersHolderImpl();
+
+ @Test
+ public void support_core_metrics_as_input_metrics() throws Exception {
+ MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1))};
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
+ underTest.execute();
+
+ assertThat(holder.getMeasureComputers()).hasSize(1);
+ }
+
+ @Test
+ public void support_plugin_metrics_as_input_metrics() throws Exception {
+ MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_2))};
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
+ underTest.execute();
+
+ assertThat(holder.getMeasureComputers()).hasSize(1);
+ }
+
+ @Test
+ public void sort_computers() throws Exception {
+ // Should be the last to be executed
+ MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
+ // Should be the first to be executed
+ MeasureComputer measureComputer2 = newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_2));
+ // Should be the second to be executed
+ MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
+ MeasureComputer[] computers = new MeasureComputer[] {measureComputer1, measureComputer2, measureComputer3};
+
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
+ underTest.execute();
+
+ List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
+ assertThat(result).hasSize(3);
+ assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
+ assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
+ assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
+ }
+
+ @Test
+ public void sort_computers_when_one_computer_has_no_input_metric() throws Exception {
+ // Should be the last to be executed
+ MeasureComputer measureComputer1 = newMeasureComputer(array(NEW_METRIC_3), array(NEW_METRIC_4));
+ // Should be the first to be executed
+ MeasureComputer measureComputer2 = newMeasureComputer(new String[] {}, array(NEW_METRIC_2));
+ // Should be the second to be executed
+ MeasureComputer measureComputer3 = newMeasureComputer(array(NEW_METRIC_2), array(NEW_METRIC_3));
+ MeasureComputer[] computers = new MeasureComputer[] {measureComputer1, measureComputer2, measureComputer3};
+
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
+ underTest.execute();
+
+ List<MeasureComputerWrapper> result = newArrayList(holder.getMeasureComputers());
+ assertThat(result).hasSize(3);
+ assertThat(result.get(0).getComputer()).isEqualTo(measureComputer2);
+ assertThat(result.get(1).getComputer()).isEqualTo(measureComputer3);
+ assertThat(result.get(2).getComputer()).isEqualTo(measureComputer1);
+ }
+
+ @Test
+ public void fail_with_ISE_when_input_metric_is_unknown() throws Exception {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("Metric 'unknown' cannot be used as an input metric as it's not a core metric and no plugin declare this metric");
+
+ MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array("unknown"), array(NEW_METRIC_4))};
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
+ underTest.execute();
+ }
+
+ @Test
+ public void fail_with_ISE_when_output_metric_is_not_define_by_plugin() throws Exception {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("Metric 'unknown' cannot be used as an output metric as no plugin declare this metric");
+
+ MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_4), array("unknown"))};
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
+ underTest.execute();
+ }
+
+ @Test
+ public void fail_with_ISE_when_output_metric_is_a_core_metric() throws Exception {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("Metric 'ncloc' cannot be used as an output metric as it's a core metric");
+
+ MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_4), array(NCLOC_KEY))};
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
+ underTest.execute();
+ }
+
+ @Test
+ public void not_fail_if_input_metrics_are_same_as_output_metrics() throws Exception {
+ MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NEW_METRIC_1), array(NEW_METRIC_1))};
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
+ underTest.execute();
+
+ assertThat(holder.getMeasureComputers()).hasSize(1);
+ }
+
+ @Test
+ public void return_empty_list_when_no_measure_computers() throws Exception {
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()));
+ underTest.execute();
+
+ assertThat(holder.getMeasureComputers()).isEmpty();
+ }
+
+ @Test
+ public void return_empty_list_when_no_metrics_neither_measure_computers() throws Exception {
+ ComputationStep underTest = new LoadMeasureComputersStep(holder);
+ underTest.execute();
+
+ assertThat(holder.getMeasureComputers()).isEmpty();
+ }
+
+ @Test
+ public void fail_with_ISE_when_no_metrics_are_defined_by_plugin_but_measure_computer_use_a_new_metric() throws Exception {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("Metric 'metric1' cannot be used as an output metric as no plugin declare this metric");
+
+ MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1))};
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, computers);
+ underTest.execute();
+ }
+
+ @Test
+ public void fail_with_ISE_when_two_measure_computers_generate_the_same_output_metric() throws Exception {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("Output metric 'metric1' is already defined by another measure computer 'TestMeasureComputer'");
+
+ MeasureComputer[] computers = new MeasureComputer[] {newMeasureComputer(array(NCLOC_KEY), array(NEW_METRIC_1)), newMeasureComputer(array(CLASSES_KEY), array(NEW_METRIC_1))};
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
+ underTest.execute();
+ }
+
+ @Test
+ public void fail_with_IAE_when_creating_measure_computer_definition_without_using_the_builder_and_with_invalid_output_metrics() throws Exception {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("At least one output metric must be defined");
+
+ MeasureComputer measureComputer = new MeasureComputer() {
+ @Override
+ public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {
+ // Create a instance of MeasureComputerDefinition without using the builder
+ return new MeasureComputer.MeasureComputerDefinition(){
+ @Override
+ public Set<String> getInputMetrics() {
+ return ImmutableSet.of(NCLOC_KEY);
+ }
+
+ @Override
+ public Set<String> getOutputMetrics() {
+ // Empty output metric is not allowed !
+ return Collections.emptySet();
+ }
+ };
+ }
+
+ @Override
+ public void compute(MeasureComputerContext context) {
+ // Nothing needs to be done as we're only testing metada
+ }
+ };
+
+ MeasureComputer[] computers = new MeasureComputer[] {measureComputer};
+ ComputationStep underTest = new LoadMeasureComputersStep(holder, array(new TestMetrics()), computers);
+ underTest.execute();
+ }
+
+ private static MeasureComputer newMeasureComputer(final String[] inputMetrics, final String[] outputMetrics) {
+ return new MeasureComputer() {
+ @Override
+ public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {
+ return defContext.newDefinitionBuilder()
+ .setInputMetrics(inputMetrics)
+ .setOutputMetrics(outputMetrics)
+ .build();
+ }
+
+ @Override
+ public void compute(MeasureComputerContext context) {
+ // Nothing needs to be done as we're only testing metada
+ }
+
+ @Override
+ public String toString() {
+ return "TestMeasureComputer";
+ }
+ };
+ }
+
+ private static class TestMetrics implements Metrics {
+ @Override
+ public List<Metric> getMetrics() {
+ return Lists.<Metric>newArrayList(
+ new Metric.Builder(NEW_METRIC_1, "metric1", DATA).create(),
+ new Metric.Builder(NEW_METRIC_2, "metric2", MILLISEC).create(),
+ new Metric.Builder(NEW_METRIC_3, "metric3", INT).create(),
+ new Metric.Builder(NEW_METRIC_4, "metric4", FLOAT).create()
+ );
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.step;
+
+import com.tngtech.java.junit.dataprovider.DataProvider;
+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.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.sonar.api.CoreProperties;
+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 org.sonar.db.DbTester;
+import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolderRule;
+import org.sonar.server.computation.batch.TreeRootHolderRule;
+import org.sonar.server.computation.component.Component;
+import org.sonar.server.computation.component.ReportComponent;
+import org.sonar.server.computation.component.SettingsRepository;
+import org.sonar.server.computation.component.ViewsComponent;
+import org.sonar.server.computation.period.Period;
+import org.sonar.server.computation.period.PeriodsHolderImpl;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@Category(DbTests.class)
+@RunWith(DataProviderRunner.class)
+public class LoadPeriodsStepTest extends BaseStepTest {
+
+ private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
+ private static final String ROOT_KEY = "ROOT_KEY";
+ private static final ReportComponent PROJECT_ROOT = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(ROOT_KEY).setVersion("1.1").build();
+ private static final ViewsComponent VIEW_ROOT = ViewsComponent.builder(Component.Type.VIEW, ROOT_KEY).setUuid("ABCD").build();
+
+ @Rule
+ public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ @Rule
+ public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
+ @Rule
+ public MutableAnalysisMetadataHolderRule analysisMetadataHolder = new MutableAnalysisMetadataHolderRule();
+ @Rule
+ public LogTester logTester = new LogTester();
+
+ PeriodsHolderImpl periodsHolder = new PeriodsHolderImpl();
+ DbClient dbClient = dbTester.getDbClient();
+ Settings settings = new Settings();
+ SettingsRepository settingsRepository = mock(SettingsRepository.class);
+
+ LoadPeriodsStep underTest;
+
+ @Override
+ protected ComputationStep step() {
+ return underTest;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ analysisMetadataHolder.setAnalysisDate(DATE_FORMAT.parse("2008-11-30"));
+
+ underTest = new LoadPeriodsStep(dbClient, settingsRepository, treeRootHolder, analysisMetadataHolder, periodsHolder);
+ }
+
+ private void setupRoot(Component root) {
+ treeRootHolder.setRoot(root);
+ when(settingsRepository.getSettings(root)).thenReturn(settings);
+ }
+
+ @DataProvider
+ public static Object[][] projectAndViewRoots() {
+ return new Object[][] {
+ {PROJECT_ROOT},
+ {VIEW_ROOT}
+ };
+ }
+
+ @Test
+ @UseDataProvider("projectAndViewRoots")
+ public void no_period_on_first_analysis(Component root) {
+ setupRoot(root);
+
+ // No project, no snapshot
+
+ underTest.execute();
+ assertThat(periodsHolder.getPeriods()).isEmpty();
+ }
+
+ @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);
+ assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
+ assertThat(period.getModeParameter()).isEqualTo(textDate);
+ assertThat(period.getSnapshotDate()).isEqualTo(1227358680000L);
+ assertThat(period.getSnapshotId()).isEqualTo(1003L);
+ }
+
+ @Test
+ @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();
+ }
+
+ @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();
+ }
+
+ @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();
+ }
+
+ @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
+ assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
+ assertThat(period.getModeParameter()).isEqualTo(textDate);
+ assertThat(period.getSnapshotDate()).isEqualTo(1227358680000L);
+ assertThat(period.getSnapshotId()).isEqualTo(1003L);
+
+ assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs().get(0)).startsWith("Compare to date 2008-11-22 (analysis of ");
+ }
+
+ @Test
+ @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);
+ assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE);
+ assertThat(period.getModeParameter()).isEqualTo(date);
+ assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L);
+ assertThat(period.getSnapshotId()).isEqualTo(1004L);
+ }
+
+ @Test
+ @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();
+ }
+
+ @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);
+ assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DAYS);
+ assertThat(period.getModeParameter()).isEqualTo("10");
+ assertThat(period.getSnapshotDate()).isEqualTo(1227157200000L);
+ assertThat(period.getSnapshotId()).isEqualTo(1002L);
+
+ assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs().get(0)).startsWith("Compare over 10 days (2008-11-20, analysis of ");
+ }
+
+ @Test
+ @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();
+ }
+
+ @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);
+ assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
+ assertThat(period.getModeParameter()).isNotNull();
+ assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L);
+ assertThat(period.getSnapshotId()).isEqualTo(1004L);
+
+ assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs().get(0)).startsWith("Compare to previous analysis (");
+ }
+
+ @Test
+ @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();
+ }
+
+ @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);
+ assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
+ 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
+ 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");
+
+ 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);
+ assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
+ assertThat(period.getModeParameter()).isEqualTo("0.9");
+ assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);
+ assertThat(period.getSnapshotId()).isEqualTo(1000L);
+ }
+
+ @Test
+ @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();
+ }
+
+ @Test
+ @UseDataProvider("projectAndViewRoots")
+ public void no_period_by_previous_version_when_no_event_version(Component root) {
+ setupRoot(root);
+
+ dbTester.prepareDbUnit(getClass(), "no_previous_version.xml");
+
+ settings.setProperty("sonar.timemachine.period1", "previous_version");
+
+ underTest.execute();
+ assertThat(periodsHolder.getPeriods()).isEmpty();
+ }
+
+ @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);
+ assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION);
+ assertThat(period.getModeParameter()).isEqualTo("0.9");
+ assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L);
+ assertThat(period.getSnapshotId()).isEqualTo(1000L);
+
+ assertThat(logTester.logs()).hasSize(1);
+ assertThat(logTester.logs().get(0)).startsWith("Compare to version (0.9) (");
+ }
+
+ @Test
+ @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(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);
+ 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_PREVIOUS_VERSION);
+ assertThat(periods.get(3).getIndex()).isEqualTo(4);
+ assertThat(periods.get(3).getSnapshotDate()).isEqualTo(1226494680000L);
+
+ assertThat(periods.get(4).getMode()).isEqualTo(CoreProperties.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(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);
+
+ 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);
+ }
+
+}
+++ /dev/null
-<dataset>
-
- <!-- Root characteristic -->
- <characteristics id="1" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="1"
- enabled="[true]"
- created_at="2013-11-20" updated_at="2013-11-22"/>
-
- <!-- Sub characteristics of root characteristic -->
- <characteristics id="2" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="1" characteristic_order="[null]"
- enabled="[true]"
- created_at="2013-11-20" updated_at="2013-11-22"/>
- <characteristics id="3" kee="HARDWARE_RELATED_PORTABILITY" name="Hardware related portability " parent_id="1" characteristic_order="[null]"
- enabled="[true]"
- created_at="2013-11-20" updated_at="2013-11-22"/>
-</dataset>
+++ /dev/null
-<dataset>
-
- <projects id="1" root_id="[null]" kee="ROOT_KEY" uuid="ABCD"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <projects id="1" kee="ROOT_KEY" name="project" uuid="ABCD"/>
-
- <!-- 2008-11-11 -->
- <!-- Version 0.9 -->
- <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- 2008-11-12 -->
- <!-- Version 1.0 -->
- <snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1226494680000" build_date="1226494680000" version="1.0" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- 2008-11-20 -->
- <!-- First version 1.1 -->
- <snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1227157200000" build_date="1227157200000" version="1.1" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- 2008-11-22 -->
- <snapshots id="1003" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1227358680000" build_date="1227358680000" version="1.1" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- 2008-11-29 -->
- <!-- Last version 1.1 -->
- <snapshots id="1004" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1227934800000" build_date="1227934800000" version="1.1" path=""
- status="P" islast="[true]" depth="0"/>
-
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <projects id="1" root_id="[null]" kee="ROOT_KEY" uuid="ABCD"/>
-
- <!-- 2008-11-11 -->
- <!-- Version 0.9 -->
- <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- 2008-11-12 -->
- <!-- Version 1.0 -->
- <snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1226494680000" build_date="1226494680000" version="1.0" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- 2008-11-20 -->
- <!-- version 1.1 -->
- <snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1227157200000" build_date="1227157200000" version="1.1" path=""
- status="P" islast="[false]" depth="0"/>
-
-
- <events id="1" name="0.9" component_uuid="ABCD" snapshot_id="1000" category="Version" event_date="1226379600000" created_at="1226379600000" description="" event_data="[null]"/>
- <!-- The "1.0" version was deleted from the history : -->
- <!--<events id="2" name="1.0" component_uuid="ABCD" snapshot_id="1001" category="Version" event_date="1226494680000" created_at="1226494680000" description="" event_data="[null]"/>-->
- <events id="3" name="1.1" component_uuid="ABCD" snapshot_id="1004" category="Version" event_date="1227934800000" created_at="1227934800000" description="" event_data="[null]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <projects id="1" kee="ROOT_KEY" name="project" uuid="ABCD"/>
-
- <!-- 2008-11-11 -->
- <!-- Version 0.9 -->
- <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- 2008-11-12 -->
- <!-- Version 1.0 -->
- <snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1226494680000" build_date="1226494680000" version="1.0" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- 2008-11-20 -->
- <!-- First version 1.1 -->
- <snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1227157200000" build_date="1227157200000" version="1.1" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- 2008-11-22 -->
- <snapshots id="1003" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1227358680000" build_date="1227358680000" version="1.1" path=""
- status="P" islast="[false]" depth="0"/>
-
- <!-- 2008-11-29 -->
- <!-- Last version 1.1 -->
- <snapshots id="1004" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1227934800000" build_date="1227934800000" version="1.1" path=""
- status="P" islast="[true]" depth="0"/>
-
-
- <events id="1" name="0.9" component_uuid="ABCD" snapshot_id="1000" category="Version" event_date="1226379600000" created_at="1226379600000" description="" event_data="[null]"/>
- <events id="2" name="1.0" component_uuid="ABCD" snapshot_id="1001" category="Version" event_date="1226494680000" created_at="1226494680000" description="" event_data="[null]"/>
- <events id="3" name="1.1" component_uuid="ABCD" snapshot_id="1004" category="Version" event_date="1227934800000" created_at="1227934800000" description="" event_data="[null]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="PROJECT_KEY" name="project" long_name="[null]" description="[null]"
- uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
- enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
-
- <!-- Unprocessed snapshot -->
- <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
- period5_param="[null]" period5_date="[null]"
- project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path=""
- status="U" islast="[false]" depth="0"/>
-
-</dataset>
--- /dev/null
+<dataset>
+
+ <!-- Root characteristic -->
+ <characteristics id="1" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="1"
+ enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- Sub characteristics of root characteristic -->
+ <characteristics id="2" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="1" characteristic_order="[null]"
+ enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+ <characteristics id="3" kee="HARDWARE_RELATED_PORTABILITY" name="Hardware related portability " parent_id="1" characteristic_order="[null]"
+ enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+</dataset>
--- /dev/null
+<dataset>
+
+ <projects id="1" root_id="[null]" kee="ROOT_KEY" uuid="ABCD"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <projects id="1" kee="ROOT_KEY" name="project" uuid="ABCD"/>
+
+ <!-- 2008-11-11 -->
+ <!-- Version 0.9 -->
+ <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- 2008-11-12 -->
+ <!-- Version 1.0 -->
+ <snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1226494680000" build_date="1226494680000" version="1.0" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- 2008-11-20 -->
+ <!-- First version 1.1 -->
+ <snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1227157200000" build_date="1227157200000" version="1.1" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- 2008-11-22 -->
+ <snapshots id="1003" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1227358680000" build_date="1227358680000" version="1.1" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- 2008-11-29 -->
+ <!-- Last version 1.1 -->
+ <snapshots id="1004" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1227934800000" build_date="1227934800000" version="1.1" path=""
+ status="P" islast="[true]" depth="0"/>
+
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <projects id="1" root_id="[null]" kee="ROOT_KEY" uuid="ABCD"/>
+
+ <!-- 2008-11-11 -->
+ <!-- Version 0.9 -->
+ <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- 2008-11-12 -->
+ <!-- Version 1.0 -->
+ <snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1226494680000" build_date="1226494680000" version="1.0" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- 2008-11-20 -->
+ <!-- version 1.1 -->
+ <snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1227157200000" build_date="1227157200000" version="1.1" path=""
+ status="P" islast="[false]" depth="0"/>
+
+
+ <events id="1" name="0.9" component_uuid="ABCD" snapshot_id="1000" category="Version" event_date="1226379600000" created_at="1226379600000" description="" event_data="[null]"/>
+ <!-- The "1.0" version was deleted from the history : -->
+ <!--<events id="2" name="1.0" component_uuid="ABCD" snapshot_id="1001" category="Version" event_date="1226494680000" created_at="1226494680000" description="" event_data="[null]"/>-->
+ <events id="3" name="1.1" component_uuid="ABCD" snapshot_id="1004" category="Version" event_date="1227934800000" created_at="1227934800000" description="" event_data="[null]"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <projects id="1" kee="ROOT_KEY" name="project" uuid="ABCD"/>
+
+ <!-- 2008-11-11 -->
+ <!-- Version 0.9 -->
+ <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- 2008-11-12 -->
+ <!-- Version 1.0 -->
+ <snapshots id="1001" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1226494680000" build_date="1226494680000" version="1.0" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- 2008-11-20 -->
+ <!-- First version 1.1 -->
+ <snapshots id="1002" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1227157200000" build_date="1227157200000" version="1.1" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- 2008-11-22 -->
+ <snapshots id="1003" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1227358680000" build_date="1227358680000" version="1.1" path=""
+ status="P" islast="[false]" depth="0"/>
+
+ <!-- 2008-11-29 -->
+ <!-- Last version 1.1 -->
+ <snapshots id="1004" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1227934800000" build_date="1227934800000" version="1.1" path=""
+ status="P" islast="[true]" depth="0"/>
+
+
+ <events id="1" name="0.9" component_uuid="ABCD" snapshot_id="1000" category="Version" event_date="1226379600000" created_at="1226379600000" description="" event_data="[null]"/>
+ <events id="2" name="1.0" component_uuid="ABCD" snapshot_id="1001" category="Version" event_date="1226494680000" created_at="1226494680000" description="" event_data="[null]"/>
+ <events id="3" name="1.1" component_uuid="ABCD" snapshot_id="1004" category="Version" event_date="1227934800000" created_at="1227934800000" description="" event_data="[null]"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="PROJECT_KEY" name="project" long_name="[null]" description="[null]"
+ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD."
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+ <!-- Unprocessed snapshot -->
+ <snapshots id="1000" purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]"
+ period5_param="[null]" period5_date="[null]"
+ project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path=""
+ status="U" islast="[false]" depth="0"/>
+
+</dataset>