Search in sources :

Example 1 with MetricImpl

use of org.sonar.server.computation.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.

the class MeasureRepositoryImplTest 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()));
        }
    }
}
Also used : MetricImpl(org.sonar.server.computation.task.projectanalysis.metric.MetricImpl) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 2 with MetricImpl

use of org.sonar.server.computation.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.

the class MapBasedRawMeasureRepositoryTest method update_accepts_NO_VALUE_as_measure_arg.

@Test
public void update_accepts_NO_VALUE_as_measure_arg() {
    for (Metric.MetricType metricType : Metric.MetricType.values()) {
        MetricImpl metric = new MetricImpl(1, "key" + metricType, "name" + metricType, metricType);
        underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
        underTest.update(FILE_COMPONENT, metric, Measure.newMeasureBuilder().createNoValue());
    }
}
Also used : MetricImpl(org.sonar.server.computation.task.projectanalysis.metric.MetricImpl) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric) Test(org.junit.Test)

Example 3 with MetricImpl

use of org.sonar.server.computation.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.

the class CustomMeasuresCopyStepTest method test_int_value_type.

@Test
public void test_int_value_type() throws Exception {
    CustomMeasureDto dto = new CustomMeasureDto();
    dto.setValue(10.0);
    assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.INT)).getIntValue()).isEqualTo(10);
}
Also used : MetricImpl(org.sonar.server.computation.task.projectanalysis.metric.MetricImpl) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 4 with MetricImpl

use of org.sonar.server.computation.task.projectanalysis.metric.MetricImpl in project sonarqube by SonarSource.

the class CustomMeasuresCopyStepTest method test_LEVEL_value_type.

@Test
public void test_LEVEL_value_type() throws Exception {
    CustomMeasureDto dto = new CustomMeasureDto();
    dto.setTextValue("OK");
    assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.LEVEL)).getLevelValue()).isEqualTo(Measure.Level.OK);
}
Also used : MetricImpl(org.sonar.server.computation.task.projectanalysis.metric.MetricImpl) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 5 with MetricImpl

use of org.sonar.server.computation.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", "warnTh", true);
    ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(new EvaluatedCondition(condition, Measure.Level.OK, value), new EvaluatedCondition(condition, Measure.Level.WARN, value), new EvaluatedCondition(condition, Measure.Level.ERROR, value));
    String actualJson = new QualityGateDetailsData(Measure.Level.OK, evaluatedConditions).toJson();
    JsonAssert.assertJson(actualJson).isSimilarTo("{" + "\"level\":\"OK\"," + "\"conditions\":[" + "  {" + "    \"metric\":\"key1\"," + "    \"op\":\"GT\"," + "    \"period\":1," + "    \"warning\":\"warnTh\"," + "    \"error\":\"errorTh\"," + "    \"actual\":\"actualValue\"," + "    \"level\":\"OK\"" + "  }," + "  {" + "    \"metric\":\"key1\"," + "    \"op\":\"GT\"," + "    \"period\":1," + "    \"warning\":\"warnTh\"," + "    \"error\":\"errorTh\"," + "    \"actual\":\"actualValue\"," + "    \"level\":\"WARN\"" + "  }," + "  {" + "    \"metric\":\"key1\"," + "    \"op\":\"GT\"," + "    \"period\":1," + "    \"warning\":\"warnTh\"," + "    \"error\":\"errorTh\"," + "    \"actual\":\"actualValue\"," + "    \"level\":\"ERROR\"" + "  }" + "]" + "}");
}
Also used : Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) MetricImpl(org.sonar.server.computation.task.projectanalysis.metric.MetricImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 MetricImpl (org.sonar.server.computation.task.projectanalysis.metric.MetricImpl)13 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)7 Metric (org.sonar.server.computation.task.projectanalysis.metric.Metric)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 MeasureDto (org.sonar.db.measure.MeasureDto)1 Condition (org.sonar.server.computation.task.projectanalysis.qualitygate.Condition)1