use of org.sonar.ce.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.
the class LiveMeasureDtoToMeasureTest method toMeasure_should_not_loose_decimals_of_float_values.
@Test
public void toMeasure_should_not_loose_decimals_of_float_values() {
MetricImpl metric = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
LiveMeasureDto LiveMeasureDto = new LiveMeasureDto().setValue(0.12345);
Optional<Measure> measure = underTest.toMeasure(LiveMeasureDto, metric);
assertThat(measure.get().getDoubleValue()).isEqualTo(0.12345, Offset.offset(0.000001));
}
use of org.sonar.ce.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.
the class MapBasedRawMeasureRepositoryTest method update_throws_IAE_if_valueType_of_Measure_is_not_the_same_as_the_Metric_valueType_unless_NO_VALUE.
@Test
@UseDataProvider("measures")
public void update_throws_IAE_if_valueType_of_Measure_is_not_the_same_as_the_Metric_valueType_unless_NO_VALUE(Measure measure) {
for (Metric.MetricType metricType : Metric.MetricType.values()) {
if (metricType.getValueType() == measure.getValueType() || measure.getValueType() == Measure.ValueType.NO_VALUE) {
continue;
}
try {
final MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
underTest.update(FILE_COMPONENT, metric, measure);
fail("An IllegalArgumentException should have been raised");
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(format("Measure's ValueType (%s) is not consistent with the Metric's ValueType (%s)", measure.getValueType(), metricType.getValueType()));
}
}
}
use of org.sonar.ce.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.
the class LoadQualityGateStepTest method filter_conditions_on_pull_request.
@Test
public void filter_conditions_on_pull_request() {
Metric newMetric = new MetricImpl("1", "new_key", "name", Metric.MetricType.INT);
Metric metric = new MetricImpl("2", "key", "name", Metric.MetricType.INT);
Condition variation = new Condition(newMetric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0");
Condition condition = new Condition(metric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0");
when(analysisMetadataHolder.isPullRequest()).thenReturn(true);
QualityGate defaultGate = new QualityGate("1", "qg", Arrays.asList(variation, condition));
when(qualityGateService.findDefaultQualityGate()).thenReturn(defaultGate);
underTest.execute(new TestComputationStepContext());
assertThat(mutableQualityGateHolder.getQualityGate().get().getConditions()).containsExactly(variation);
}
use of org.sonar.ce.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.
the class QualityGateDetailsDataTest method verify_json_for_each_type_of_condition.
@Test
public void verify_json_for_each_type_of_condition() {
String value = "actualValue";
Condition condition = new Condition(new MetricImpl("1", "key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(new EvaluatedCondition(condition, Measure.Level.OK, value), new EvaluatedCondition(condition, Measure.Level.ERROR, value));
String actualJson = new QualityGateDetailsData(Measure.Level.OK, evaluatedConditions, false).toJson();
JsonAssert.assertJson(actualJson).isSimilarTo("{" + "\"level\":\"OK\"," + "\"conditions\":[" + " {" + " \"metric\":\"key1\"," + " \"op\":\"GT\"," + " \"error\":\"errorTh\"," + " \"actual\":\"actualValue\"," + " \"level\":\"OK\"" + " }," + " {" + " \"metric\":\"key1\"," + " \"op\":\"GT\"," + " \"error\":\"errorTh\"," + " \"actual\":\"actualValue\"," + " \"level\":\"ERROR\"" + " }" + "]" + "}");
}
use of org.sonar.ce.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.
the class QualityGateDetailsDataTest method verify_json_for_condition_on_leak_metric.
@Test
public void verify_json_for_condition_on_leak_metric() {
String value = "actualValue";
Condition condition = new Condition(new MetricImpl("1", "new_key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(new EvaluatedCondition(condition, Measure.Level.OK, value), new EvaluatedCondition(condition, Measure.Level.ERROR, value));
String actualJson = new QualityGateDetailsData(Measure.Level.OK, evaluatedConditions, false).toJson();
JsonAssert.assertJson(actualJson).isSimilarTo("{" + "\"level\":\"OK\"," + "\"conditions\":[" + " {" + " \"metric\":\"new_key1\"," + " \"op\":\"GT\"," + " \"error\":\"errorTh\"," + " \"actual\":\"actualValue\"," + " \"period\":1," + " \"level\":\"OK\"" + " }," + " {" + " \"metric\":\"new_key1\"," + " \"op\":\"GT\"," + " \"error\":\"errorTh\"," + " \"actual\":\"actualValue\"," + " \"period\":1," + " \"level\":\"ERROR\"" + " }" + "]" + "}");
}
Aggregations