use of org.sonar.server.computation.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class NewMaintainabilityMeasuresVisitorTest method leaf_components_always_have_a_measure_when_at_least_one_period_exist_and_ratio_is_computed_from_current_level_new_debt.
@Test
public void leaf_components_always_have_a_measure_when_at_least_one_period_exist_and_ratio_is_computed_from_current_level_new_debt() {
setPeriod();
when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(MODULE, 11).addChildren(builder(DIRECTORY, 111).addChildren(builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()).build()).build()).build());
Measure newDebtMeasure = createNewDebtMeasure(50);
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150));
measureRepository.addRawMeasure(11, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200));
measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250));
// 4 lines file, only first one is not ncloc
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
// first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date
scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_SNAPSHOT_DATE - 100, 2, PERIOD_SNAPSHOT_DATE + 100, 2));
underTest.visit(treeRootHolder.getRoot());
assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 83.33);
assertNewDebtRatioValues(111, 83.33);
assertNewDebtRatioValues(11, 83.33);
assertNewDebtRatioValues(ROOT_REF, 83.33);
}
use of org.sonar.server.computation.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class QualityGateMeasuresStepTest method new_measures_have_WARNING_level_if_no_updated_measure_has_ERROR_level.
@Test
public void new_measures_have_WARNING_level_if_no_updated_measure_has_ERROR_level() {
int rawValue = 1;
Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2", null);
Condition equals1WarningCondition = createEqualsCondition(INT_METRIC_2, null, "1");
Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition, equals1WarningCondition)));
measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure);
underTest.execute();
Optional<Measure> rawMeasure1 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_1_KEY);
Optional<Measure> rawMeasure2 = measureRepository.getAddedRawMeasure(PROJECT_REF, INT_METRIC_2_KEY);
assertThat(rawMeasure1.get()).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue));
assertThat(rawMeasure2.get()).hasQualityGateLevel(WARN).hasQualityGateText(dumbResultTextAnswer(equals1WarningCondition, WARN, rawValue));
assertThat(getAlertStatusMeasure()).hasQualityGateLevel(WARN).hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue) + ", " + dumbResultTextAnswer(equals1WarningCondition, WARN, rawValue));
assertThat(getQGDetailsMeasure()).hasValue(new QualityGateDetailsData(WARN, of(new EvaluatedCondition(equals2Condition, OK, rawValue), new EvaluatedCondition(equals1WarningCondition, WARN, rawValue))).toJson());
QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.WARN).hasConditionCount(2).hasCondition(equals2Condition, ConditionStatus.EvaluationStatus.OK, String.valueOf(rawValue)).hasCondition(equals1WarningCondition, ConditionStatus.EvaluationStatus.WARN, String.valueOf(rawValue));
}
use of org.sonar.server.computation.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class QualityGateMeasuresStepTest method new_measures_are_created_even_if_there_is_no_rawMeasure_for_metric_of_condition.
@Test
public void new_measures_are_created_even_if_there_is_no_rawMeasure_for_metric_of_condition() {
Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2", null);
qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition)));
underTest.execute();
Optional<Measure> addedRawMeasure = measureRepository.getAddedRawMeasure(PROJECT_COMPONENT, INT_METRIC_1_KEY);
assertThat(addedRawMeasure).isAbsent();
assertThat(getAlertStatusMeasure()).hasQualityGateLevel(OK).hasQualityGateText("");
assertThat(getQGDetailsMeasure()).hasValue(new QualityGateDetailsData(OK, Collections.<EvaluatedCondition>emptyList()).toJson());
QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.OK).hasConditionCount(1).hasCondition(equals2Condition, ConditionStatus.EvaluationStatus.NO_VALUE, null);
}
use of org.sonar.server.computation.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class QualityGateMeasuresStepTest method rawMeasure_is_updated_if_present_and_new_measures_are_created_if_project_has_measure_for_metric_of_condition.
@Test
public void rawMeasure_is_updated_if_present_and_new_measures_are_created_if_project_has_measure_for_metric_of_condition() {
int rawValue = 1;
Condition equals2Condition = createEqualsCondition(INT_METRIC_1, "2", null);
Measure rawMeasure = newMeasureBuilder().create(rawValue, null);
qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition)));
measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure);
underTest.execute();
Optional<Measure> addedRawMeasure = measureRepository.getAddedRawMeasure(PROJECT_COMPONENT, INT_METRIC_1_KEY);
assertThat(addedRawMeasure).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue));
assertThat(getAlertStatusMeasure()).hasQualityGateLevel(OK).hasQualityGateText(dumbResultTextAnswer(equals2Condition, OK, rawValue));
assertThat(getQGDetailsMeasure().get()).hasValue(new QualityGateDetailsData(OK, of(new EvaluatedCondition(equals2Condition, OK, rawValue))).toJson());
QualityGateStatusHolderAssertions.assertThat(qualityGateStatusHolder).hasStatus(QualityGateStatus.OK).hasConditionCount(1).hasCondition(equals2Condition, ConditionStatus.EvaluationStatus.OK, String.valueOf(rawValue));
}
use of org.sonar.server.computation.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class QualityGateEventsStep method checkQualityGateStatusChange.
private void checkQualityGateStatusChange(Component project, Metric metric, QualityGateStatus rawStatus) {
Optional<Measure> baseMeasure = measureRepository.getBaseMeasure(project, metric);
if (!baseMeasure.isPresent()) {
checkNewQualityGate(project, rawStatus);
return;
}
if (!baseMeasure.get().hasQualityGateStatus()) {
LOGGER.warn(String.format("Previous alterStatus for project %s is not a supported value. Can not compute Quality Gate event", project.getKey()));
checkNewQualityGate(project, rawStatus);
return;
}
QualityGateStatus baseStatus = baseMeasure.get().getQualityGateStatus();
if (baseStatus.getStatus() != rawStatus.getStatus()) {
// The QualityGate status has changed
String label = String.format("%s (was %s)", rawStatus.getStatus().getColorName(), baseStatus.getStatus().getColorName());
createEvent(project, label, rawStatus.getText());
boolean isNewKo = rawStatus.getStatus() == Measure.Level.OK;
notifyUsers(project, label, rawStatus, isNewKo);
}
}
Aggregations