*/
package org.sonar.server.computation.task.projectanalysis.step;
-import com.google.common.base.Function;
import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.stream.Collectors;
+import java.util.function.Predicate;
import java.util.stream.StreamSupport;
import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.sonar.core.util.stream.Collectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.measure.PastMeasureDto;
import org.sonar.server.computation.task.projectanalysis.measure.Measure;
import org.sonar.server.computation.task.projectanalysis.measure.MeasureKey;
import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
import org.sonar.server.computation.task.projectanalysis.metric.Metric;
import org.sonar.server.computation.task.projectanalysis.metric.MetricRepository;
import org.sonar.server.computation.task.projectanalysis.period.Period;
private final MeasureRepository measureRepository;
public ComputeMeasureVariationsStep(DbClient dbClient, TreeRootHolder treeRootHolder, PeriodsHolder periodsHolder, MetricRepository metricRepository,
- MeasureRepository measureRepository) {
+ MeasureRepository measureRepository) {
this.dbClient = dbClient;
this.treeRootHolder = treeRootHolder;
this.periodsHolder = periodsHolder;
public void execute() {
DbSession dbSession = dbClient.openSession(false);
try {
- List<Metric> metrics = StreamSupport.stream(metricRepository.getAll().spliterator(), false).filter(NumericMetric.INSTANCE::apply).collect(Collectors.toList());
+ List<Metric> metrics = StreamSupport.stream(metricRepository.getAll().spliterator(), false).filter(isNumeric()).collect(Collectors.toList());
new DepthTraversalTypeAwareCrawler(new VariationMeasuresVisitor(dbSession, metrics))
.visit(treeRootHolder.getRoot());
} finally {
// measures on files are currently purged, so past measures are not available on files
super(CrawlerDepthLimit.reportMaxDepth(DIRECTORY).withViewsMaxDepth(SUBVIEW), PRE_ORDER);
this.session = session;
- this.metricIds = metrics.stream().map(MetricDtoToMetricId.INSTANCE::apply).collect(Collectors.toSet());
+ this.metricIds = metrics.stream().map(Metric::getId).collect(Collectors.toSet());
this.metrics = metrics;
}
private MeasuresWithVariationRepository computeMeasuresWithVariations(Component component) {
MeasuresWithVariationRepository measuresWithVariationRepository = new MeasuresWithVariationRepository();
- for (Period period : periodsHolder.getPeriods()) {
+ if (periodsHolder.hasPeriod()) {
+ Period period = periodsHolder.getPeriod();
List<PastMeasureDto> pastMeasures = dbClient.measureDao()
.selectPastMeasures(session, component.getUuid(), period.getAnalysisUuid(), metricIds);
- setVariationMeasures(component, pastMeasures, period.getIndex(), measuresWithVariationRepository);
+ setVariationMeasures(component, pastMeasures, measuresWithVariationRepository);
}
return measuresWithVariationRepository;
}
- private void setVariationMeasures(Component component, List<PastMeasureDto> pastMeasures, int period, MeasuresWithVariationRepository measuresWithVariationRepository) {
+ private void setVariationMeasures(Component component, List<PastMeasureDto> pastMeasures, MeasuresWithVariationRepository measuresWithVariationRepository) {
Map<MeasureKey, PastMeasureDto> pastMeasuresByMeasureKey = pastMeasures
.stream()
.collect(uniqueIndex(m -> new MeasureKey(metricRepository.getById((long) m.getMetricId()).getKey(), null), identity()));
for (Metric metric : metrics) {
Optional<Measure> measure = measureRepository.getRawMeasure(component, metric);
- if (measure.isPresent() && !measure.get().hasVariations()) {
+ if (measure.isPresent() && !measure.get().hasVariation()) {
PastMeasureDto pastMeasure = pastMeasuresByMeasureKey.get(new MeasureKey(metric.getKey(), null));
double pastValue = (pastMeasure != null && pastMeasure.hasValue()) ? pastMeasure.getValue() : 0d;
- measuresWithVariationRepository.add(metric, measure.get(), period, computeVariation(measure.get(), pastValue));
+ measuresWithVariationRepository.add(metric, measure.get(), computeVariation(measure.get(), pastValue));
}
}
}
}
private void processMeasuresWithVariation(Component component, MeasuresWithVariationRepository measuresWithVariationRepository) {
- for (MeasureWithVariations measureWithVariations : measuresWithVariationRepository.measures()) {
- Metric metric = measureWithVariations.getMetric();
- Measure measure = Measure.updatedMeasureBuilder(measureWithVariations.getMeasure())
- .setVariations(new MeasureVariations(
- measureWithVariations.getVariation(1),
- measureWithVariations.getVariation(2),
- measureWithVariations.getVariation(3),
- measureWithVariations.getVariation(4),
- measureWithVariations.getVariation(5)))
+ for (MeasureWithVariation measureWithVariation : measuresWithVariationRepository.measures()) {
+ Metric metric = measureWithVariation.getMetric();
+ Measure measure = Measure.updatedMeasureBuilder(measureWithVariation.getMeasure())
+ .setVariation(measureWithVariation.getVariation())
.create();
measureRepository.update(component, metric, measure);
}
private static final class MeasuresWithVariationRepository {
- private final Map<MeasureKey, MeasureWithVariations> measuresWithVariations = new HashMap<>();
+ private final Map<MeasureKey, MeasureWithVariation> measuresWithVariations = new HashMap<>();
- public void add(Metric metric, final Measure measure, int variationIndex, double variationValue) {
+ public void add(Metric metric, final Measure measure, double variationValue) {
checkArgument(measure.getDeveloper() == null, "%s does not support computing variations of Measures for Developer", getClass().getSimpleName());
MeasureKey measureKey = new MeasureKey(metric.getKey(), null);
- MeasureWithVariations measureWithVariations = measuresWithVariations.get(measureKey);
- if (measureWithVariations == null) {
- measureWithVariations = new MeasureWithVariations(metric, measure);
- measuresWithVariations.put(measureKey, measureWithVariations);
- }
- measureWithVariations.setVariation(variationIndex, variationValue);
+ MeasureWithVariation measureWithVariation = measuresWithVariations.computeIfAbsent(measureKey, k -> new MeasureWithVariation(metric, measure));
+ measureWithVariation.setVariation(variationValue);
}
- public Collection<MeasureWithVariations> measures() {
+ public Collection<MeasureWithVariation> measures() {
return measuresWithVariations.values();
}
}
- private static final class MeasureWithVariations {
+ private static final class MeasureWithVariation {
private final Metric metric;
private final Measure measure;
- private final Double[] variations = new Double[5];
+ private Double variation;
- MeasureWithVariations(Metric metric, Measure measure) {
+ MeasureWithVariation(Metric metric, Measure measure) {
this.metric = metric;
this.measure = measure;
}
return metric;
}
- public void setVariation(int index, @Nullable Double value) {
- variations[index - 1] = value;
+ public void setVariation(@Nullable Double value) {
+ this.variation = value;
}
@CheckForNull
- public Double getVariation(int index) {
- return variations[index - 1];
+ public Double getVariation() {
+ return variation;
}
}
- private enum MetricDtoToMetricId implements Function<Metric, Integer> {
- INSTANCE;
-
- @Nullable
- @Override
- public Integer apply(@Nonnull Metric metric) {
- return metric.getId();
- }
- }
-
- private enum NumericMetric implements Predicate<Metric> {
- INSTANCE;
-
- @Override
- public boolean apply(@Nonnull Metric metric) {
+ private static Predicate<Metric> isNumeric() {
+ return metric -> {
Measure.ValueType valueType = metric.getType().getValueType();
return Measure.ValueType.INT.equals(valueType)
|| Measure.ValueType.LONG.equals(valueType)
|| Measure.ValueType.DOUBLE.equals(valueType)
|| Measure.ValueType.BOOLEAN.equals(valueType);
- }
+ };
}
@Override
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.server.computation.task.projectanalysis.measure.Measure;
import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
import org.sonar.server.computation.task.projectanalysis.metric.Metric;
import org.sonar.server.computation.task.projectanalysis.metric.MetricImpl;
import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule;
private static final int PROJECT_REF = 1;
private static final Component PROJECT = ReportComponent.builder(Component.Type.PROJECT, PROJECT_REF).setUuid(PROJECT_UUID).build();
-
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
@Rule
private ComponentDto project;
- DbSession session = dbTester.getSession();
+ private DbSession session = dbTester.getSession();
- DbClient dbClient = dbTester.getDbClient();
+ private DbClient dbClient = dbTester.getDbClient();
- ComputeMeasureVariationsStep underTest;
+ private ComputeMeasureVariationsStep underTest = new ComputeMeasureVariationsStep(dbClient, treeRootHolder, periodsHolder, metricRepository, measureRepository);
@Before
public void setUp() {
project = dbTester.components().insertProject(dbTester.organizations().insert(), PROJECT_UUID);
-
- underTest = new ComputeMeasureVariationsStep(dbClient, treeRootHolder, periodsHolder, metricRepository, measureRepository);
}
@Test
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d));
session.commit();
- periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));
+ periodsHolder.setPeriod(newPeriod(1, period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
public void do_nothing_when_no_period() {
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).build();
treeRootHolder.setRoot(project);
- periodsHolder.setPeriods();
+ periodsHolder.setPeriod(null);
underTest.execute();
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1Snapshot.getUuid(), 10d));
session.commit();
- periodsHolder.setPeriods(newPeriod(1, period1Snapshot));
+ periodsHolder.setPeriod(newPeriod(1, period1Snapshot));
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid(directoryDto.uuid()).build();
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build();
underTest.execute();
- assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariations().getVariation1()).isEqualTo(20d);
- assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariations().getVariation1()).isEqualTo(10d);
+ assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariation()).isEqualTo(20d);
+ assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariation()).isEqualTo(10d);
}
@Test
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1Snapshot.getUuid(), 10d));
session.commit();
- periodsHolder.setPeriods(newPeriod(1, period1Snapshot));
+ periodsHolder.setPeriod(newPeriod(1, period1Snapshot));
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid(directoryDto.uuid()).build();
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build();
underTest.execute();
- assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariations().getVariation1()).isEqualTo(0d);
- assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariations().getVariation1()).isEqualTo(0d);
+ assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariation()).isEqualTo(0d);
+ assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariation()).isEqualTo(0d);
}
@Test
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, currentProjectSnapshot.getUuid(), 60d));
session.commit();
- periodsHolder.setPeriods(newPeriod(1, past1ProjectSnapshot));
+ periodsHolder.setPeriod(newPeriod(1, past1ProjectSnapshot));
// Directory has just been added => no snapshot
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("DIRECTORY").build();
underTest.execute();
- assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariations().getVariation1()).isEqualTo(30d);
+ assertThat(measureRepository.getRawMeasure(project, ISSUES_METRIC).get().getVariation()).isEqualTo(30d);
// Variation should be the raw value
- assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariations().getVariation1()).isEqualTo(10d);
- }
-
- @Test
- public void set_variations_on_all_periods() {
- SnapshotDto period1ProjectSnapshot = newAnalysis(project).setLast(false);
- SnapshotDto period2ProjectSnapshot = newAnalysis(project).setLast(false);
- SnapshotDto period3ProjectSnapshot = newAnalysis(project).setLast(false);
- SnapshotDto period4ProjectSnapshot = newAnalysis(project).setLast(false);
- SnapshotDto period5ProjectSnapshot = newAnalysis(project).setLast(false);
- dbClient.snapshotDao().insert(session, period1ProjectSnapshot, period2ProjectSnapshot, period3ProjectSnapshot, period4ProjectSnapshot, period5ProjectSnapshot);
-
- dbClient.measureDao().insert(session,
- newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 0d),
- newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period2ProjectSnapshot.getUuid(), 20d),
- newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period3ProjectSnapshot.getUuid(), 40d),
- newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period4ProjectSnapshot.getUuid(), 80d),
- newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period5ProjectSnapshot.getUuid(), 100d));
- session.commit();
-
- periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot),
- newPeriod(2, period2ProjectSnapshot),
- newPeriod(3, period3ProjectSnapshot),
- newPeriod(4, period4ProjectSnapshot),
- newPeriod(5, period5ProjectSnapshot));
-
- treeRootHolder.setRoot(PROJECT);
-
- addRawMeasure(PROJECT, ISSUES_METRIC, newMeasureBuilder().create(80, null));
-
- underTest.execute();
-
- assertThat(measureRepository.getRawMeasures(PROJECT).keys()).hasSize(1);
-
- Measure measure = measureRepository.getRawMeasure(PROJECT, ISSUES_METRIC).get();
- assertThat(measure.hasVariations()).isTrue();
- assertThat(measure.getVariations().getVariation1()).isEqualTo(80d);
- assertThat(measure.getVariations().getVariation2()).isEqualTo(60d);
- assertThat(measure.getVariations().getVariation3()).isEqualTo(40d);
- assertThat(measure.getVariations().getVariation4()).isEqualTo(0d);
- assertThat(measure.getVariations().getVariation5()).isEqualTo(-20d);
+ assertThat(measureRepository.getRawMeasure(directory, ISSUES_METRIC).get().getVariation()).isEqualTo(10d);
}
@Test
newMeasureDto(BUILD_BREAKER_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 1d));
session.commit();
- periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));
+ periodsHolder.setPeriod(newPeriod(1, period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
assertThat(measureRepository.getRawMeasures(PROJECT).keys()).hasSize(4);
- assertThat(measureRepository.getRawMeasure(PROJECT, ISSUES_METRIC).get().getVariations().getVariation1()).isEqualTo(20d);
- assertThat(measureRepository.getRawMeasure(PROJECT, DEBT_METRIC).get().getVariations().getVariation1()).isEqualTo(-5d);
- assertThat(measureRepository.getRawMeasure(PROJECT, FILE_COMPLEXITY_METRIC).get().getVariations().getVariation1()).isEqualTo(1d);
- assertThat(measureRepository.getRawMeasure(PROJECT, BUILD_BREAKER_METRIC).get().getVariations().getVariation1()).isEqualTo(-1d);
+ assertThat(measureRepository.getRawMeasure(PROJECT, ISSUES_METRIC).get().getVariation()).isEqualTo(20d);
+ assertThat(measureRepository.getRawMeasure(PROJECT, DEBT_METRIC).get().getVariation()).isEqualTo(-5d);
+ assertThat(measureRepository.getRawMeasure(PROJECT, FILE_COMPLEXITY_METRIC).get().getVariation()).isEqualTo(1d);
+ assertThat(measureRepository.getRawMeasure(PROJECT, BUILD_BREAKER_METRIC).get().getVariation()).isEqualTo(-1d);
}
@Test
- public void do_not_set_variations_on_numeric_metric_for_developer() {
+ public void do_not_set_variation_on_numeric_metric_for_developer() {
SnapshotDto period1ProjectSnapshot = newAnalysis(project);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session,
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d));
session.commit();
- periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));
+ periodsHolder.setPeriod(newPeriod(1, period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
assertThat(measureRepository.getRawMeasures(PROJECT).keys()).hasSize(1);
- assertThat(measureRepository.getRawMeasure(PROJECT, ISSUES_METRIC, developer).get().hasVariations()).isFalse();
+ assertThat(measureRepository.getRawMeasure(PROJECT, ISSUES_METRIC, developer).get().hasVariation()).isFalse();
}
@Test
- public void does_not_update_existing_variations() throws Exception {
+ public void does_not_update_existing_variation() throws Exception {
SnapshotDto period1ProjectSnapshot = newAnalysis(project);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(NEW_DEBT.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d));
session.commit();
- periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));
+ periodsHolder.setPeriod(newPeriod(1, period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
- addRawMeasure(PROJECT, NEW_DEBT, newMeasureBuilder().setVariations(new MeasureVariations(10d)).createNoValue());
+ addRawMeasure(PROJECT, NEW_DEBT, newMeasureBuilder().setVariation(10d).createNoValue());
underTest.execute();
// As the measure has already variations it has been ignored, then variations will be the same
- assertThat(measureRepository.getRawMeasure(PROJECT, NEW_DEBT).get().getVariations().getVariation1()).isEqualTo(10d);
+ assertThat(measureRepository.getRawMeasure(PROJECT, NEW_DEBT).get().getVariation()).isEqualTo(10d);
}
private static MeasureDto newMeasureDto(int metricId, String componentUuid, String analysisUuid, double value) {
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.MeasureDto;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
-import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.server.computation.task.projectanalysis.component.Component;
+import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent;
import org.sonar.server.computation.task.projectanalysis.measure.Measure;
import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule;
@Rule
public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
- DbSession session = dbTester.getSession();
+ private DbSession session = dbTester.getSession();
- DbClient dbClient = dbTester.getDbClient();
+ private DbClient dbClient = dbTester.getDbClient();
private ComponentDto view;
- ComputeMeasureVariationsStep underTest;
+ private ComputeMeasureVariationsStep underTest = new ComputeMeasureVariationsStep(dbClient, treeRootHolder, periodsHolder, metricRepository, measureRepository);
@Before
public void setUp() {
view = dbTester.components().insertView(dbTester.organizations().insert(), VIEW_UUID);
-
- underTest = new ComputeMeasureVariationsStep(dbClient, treeRootHolder, periodsHolder, metricRepository, measureRepository);
}
@Test
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 60d));
session.commit();
- periodsHolder.setPeriods(newPeriod(1, period1ViewSnapshot));
+ periodsHolder.setPeriod(newPeriod(1, period1ViewSnapshot));
treeRootHolder.setRoot(VIEW);
public void do_nothing_when_no_period() {
Component view = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_UUID).build();
treeRootHolder.setRoot(view);
- periodsHolder.setPeriods();
+ periodsHolder.setPeriod(null);
underTest.execute();
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), subviewDto.uuid(), period1Snapshot.getUuid(), 10d));
session.commit();
- periodsHolder.setPeriods(newPeriod(1, period1Snapshot));
+ periodsHolder.setPeriod(newPeriod(1, period1Snapshot));
Component subview = ViewsComponent.builder(Component.Type.SUBVIEW, 2).setUuid(subviewDto.uuid()).build();
Component view = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_UUID).addChildren(subview).build();
underTest.execute();
- assertThat(measureRepository.getRawMeasure(view, ISSUES_METRIC).get().getVariations().getVariation1()).isEqualTo(20d);
- assertThat(measureRepository.getRawMeasure(subview, ISSUES_METRIC).get().getVariations().getVariation1()).isEqualTo(10d);
- }
-
- @Test
- public void set_variations_on_all_periods() {
- SnapshotDto period1ViewSnapshot = newAnalysis(view).setLast(false);
- SnapshotDto period2ViewSnapshot = newAnalysis(view).setLast(false);
- SnapshotDto period3ViewSnapshot = newAnalysis(view).setLast(false);
- SnapshotDto period4ViewSnapshot = newAnalysis(view).setLast(false);
- SnapshotDto period5ViewSnapshot = newAnalysis(view).setLast(false);
- dbClient.snapshotDao().insert(session, period1ViewSnapshot, period2ViewSnapshot, period3ViewSnapshot, period4ViewSnapshot, period5ViewSnapshot);
-
- dbClient.measureDao().insert(session,
- newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 0d),
- newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period2ViewSnapshot.getUuid(), 20d),
- newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period3ViewSnapshot.getUuid(), 40d),
- newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period4ViewSnapshot.getUuid(), 80d),
- newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period5ViewSnapshot.getUuid(), 100d));
- session.commit();
-
- periodsHolder.setPeriods(newPeriod(1, period1ViewSnapshot),
- newPeriod(2, period2ViewSnapshot),
- newPeriod(3, period3ViewSnapshot),
- newPeriod(4, period4ViewSnapshot),
- newPeriod(5, period5ViewSnapshot));
-
- treeRootHolder.setRoot(VIEW);
-
- addRawMeasure(VIEW, ISSUES_METRIC, Measure.newMeasureBuilder().create(80, null));
-
- underTest.execute();
-
- assertThat(measureRepository.getRawMeasures(VIEW).keys()).hasSize(1);
-
- Measure measure = measureRepository.getRawMeasure(VIEW, ISSUES_METRIC).get();
- assertThat(measure.hasVariations()).isTrue();
- assertThat(measure.getVariations().getVariation1()).isEqualTo(80d);
- assertThat(measure.getVariations().getVariation2()).isEqualTo(60d);
- assertThat(measure.getVariations().getVariation3()).isEqualTo(40d);
- assertThat(measure.getVariations().getVariation4()).isEqualTo(0d);
- assertThat(measure.getVariations().getVariation5()).isEqualTo(-20d);
+ assertThat(measureRepository.getRawMeasure(view, ISSUES_METRIC).get().getVariation()).isEqualTo(20d);
+ assertThat(measureRepository.getRawMeasure(subview, ISSUES_METRIC).get().getVariation()).isEqualTo(10d);
}
@Test
newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 60d),
newMeasureDto(DEBT_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 10d),
newMeasureDto(FILE_COMPLEXITY_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 2d),
- newMeasureDto(BUILD_BREAKER_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 1d)
- );
+ newMeasureDto(BUILD_BREAKER_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 1d));
session.commit();
- periodsHolder.setPeriods(newPeriod(1, period1ViewSnapshot));
+ periodsHolder.setPeriod(newPeriod(1, period1ViewSnapshot));
treeRootHolder.setRoot(VIEW);
assertThat(measureRepository.getRawMeasures(VIEW).keys()).hasSize(4);
- assertThat(measureRepository.getRawMeasure(VIEW, ISSUES_METRIC).get().getVariations().getVariation1()).isEqualTo(20d);
- assertThat(measureRepository.getRawMeasure(VIEW, DEBT_METRIC).get().getVariations().getVariation1()).isEqualTo(-5d);
- assertThat(measureRepository.getRawMeasure(VIEW, FILE_COMPLEXITY_METRIC).get().getVariations().getVariation1()).isEqualTo(1d);
- assertThat(measureRepository.getRawMeasure(VIEW, BUILD_BREAKER_METRIC).get().getVariations().getVariation1()).isEqualTo(-1d);
+ assertThat(measureRepository.getRawMeasure(VIEW, ISSUES_METRIC).get().getVariation()).isEqualTo(20d);
+ assertThat(measureRepository.getRawMeasure(VIEW, DEBT_METRIC).get().getVariation()).isEqualTo(-5d);
+ assertThat(measureRepository.getRawMeasure(VIEW, FILE_COMPLEXITY_METRIC).get().getVariation()).isEqualTo(1d);
+ assertThat(measureRepository.getRawMeasure(VIEW, BUILD_BREAKER_METRIC).get().getVariation()).isEqualTo(-1d);
}
private static MeasureDto newMeasureDto(int metricId, String componentUuid, String analysisUuid, double value) {