Search in sources :

Example 1 with Measure

use of org.sonarqube.ws.WsMeasures.Measure in project sonarqube by SonarSource.

the class SincePreviousVersionHistoryTest method test_since_previous_version_period.

/**
   * SONAR-2496
   */
@Test
public void test_since_previous_version_period() {
    analyzeProjectWithExclusions("0.9", "**/*2.xoo");
    analyzeProject("1.0-SNAPSHOT");
    analyzeProject("1.0-SNAPSHOT");
    Measure measure = getMeasureWithVariation(orchestrator, PROJECT, "files");
    // There are 4 files
    assertThat(parseInt(measure.getValue())).isEqualTo(4);
    // 2 files were added since the first analysis which was version 0.9
    assertThat(measure.getPeriods().getPeriodsValueList()).extracting(PeriodValue::getValue).contains("2");
}
Also used : Measure(org.sonarqube.ws.WsMeasures.Measure) Test(org.junit.Test)

Example 2 with Measure

use of org.sonarqube.ws.WsMeasures.Measure in project sonarqube by SonarSource.

the class SearchActionTest method return_measures_on_leak_period.

@Test
public void return_measures_on_leak_period() throws Exception {
    ComponentDto project = newProjectDto(db.organizations().insert());
    SnapshotDto projectSnapshot = db.components().insertProjectAndSnapshot(project);
    setBrowsePermissionOnUser(project);
    MetricDto coverage = insertCoverageMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, project, projectSnapshot).setValue(15.5d).setVariation(10d));
    db.commit();
    SearchWsResponse result = call(singletonList(project.key()), singletonList("coverage"));
    List<Measure> measures = result.getMeasuresList();
    assertThat(measures).hasSize(1);
    Measure measure = measures.get(0);
    assertThat(measure.getMetric()).isEqualTo("coverage");
    assertThat(measure.getValue()).isEqualTo("15.5");
    assertThat(measure.getPeriods().getPeriodsValueList()).extracting(WsMeasures.PeriodValue::getIndex, WsMeasures.PeriodValue::getValue).containsOnly(tuple(1, "10.0"));
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) WsMeasures(org.sonarqube.ws.WsMeasures) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Measure(org.sonarqube.ws.WsMeasures.Measure) SearchWsResponse(org.sonarqube.ws.WsMeasures.SearchWsResponse) Test(org.junit.Test)

Example 3 with Measure

use of org.sonarqube.ws.WsMeasures.Measure in project sonar-java by SonarSource.

the class UnitTestsTest method tests_without_main_code.

@Test
public void tests_without_main_code() {
    MavenBuild build = MavenBuild.create().setPom(TestUtils.projectPom("tests-without-main-code")).setGoals("clean test-compile surefire:test", "sonar:sonar");
    orchestrator.executeBuild(build);
    Map<String, Measure> measures = getMeasures("com.sonarsource.it.samples:tests-without-main-code", "tests", "test_errors", "test_failures", "skipped_tests", "test_execution_time", "test_success_density");
    assertThat(parseInt(measures.get("tests").getValue())).isEqualTo(1);
    assertThat(parseInt(measures.get("test_errors").getValue())).isEqualTo(0);
    assertThat(parseInt(measures.get("test_failures").getValue())).isEqualTo(0);
    assertThat(parseInt(measures.get("skipped_tests").getValue())).isEqualTo(1);
    assertThat(parseInt(measures.get("test_execution_time").getValue())).isGreaterThan(0);
    assertThat(parseDouble(measures.get("test_success_density").getValue())).isEqualTo(100.0);
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) Measure(org.sonarqube.ws.WsMeasures.Measure) Test(org.junit.Test)

Example 4 with Measure

use of org.sonarqube.ws.WsMeasures.Measure in project sonar-java by SonarSource.

the class UnitTestsTest method tests_with_report_name_suffix.

@Test
public void tests_with_report_name_suffix() {
    MavenBuild build = MavenBuild.create().setPom(TestUtils.projectPom("tests-surefire-suffix")).setGoals("clean test-compile surefire:test -Dsurefire.reportNameSuffix=Run1", "test-compile surefire:test -Dsurefire.reportNameSuffix=Run2", "sonar:sonar");
    orchestrator.executeBuild(build);
    Map<String, Measure> measures = getMeasures("com.sonarsource.it.samples:tests-surefire-suffix", "tests", "test_errors", "test_failures", "skipped_tests", "test_execution_time", "test_success_density");
    assertThat(parseInt(measures.get("tests").getValue())).isEqualTo(2);
    assertThat(parseInt(measures.get("test_errors").getValue())).isEqualTo(0);
    assertThat(parseInt(measures.get("test_failures").getValue())).isEqualTo(0);
    assertThat(parseInt(measures.get("skipped_tests").getValue())).isEqualTo(2);
    assertThat(parseInt(measures.get("test_execution_time").getValue())).isGreaterThan(0);
    assertThat(parseDouble(measures.get("test_success_density").getValue())).isEqualTo(100.0);
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) Measure(org.sonarqube.ws.WsMeasures.Measure) Test(org.junit.Test)

Example 5 with Measure

use of org.sonarqube.ws.WsMeasures.Measure in project sonarqube by SonarSource.

the class TimeMachineTest method measure_variations_are_only_meaningful_when_additional_fields_contains_periods.

/**
   * SONAR-4962
   */
@Test
public void measure_variations_are_only_meaningful_when_additional_fields_contains_periods() {
    Map<String, Measure> measures = getMeasuresWithVariationsByMetricKey(orchestrator, PROJECT, "violations", "new_violations");
    assertThat(measures.get("violations")).isNotNull();
    assertThat(measures.get("new_violations")).isNotNull();
    SearchHistoryResponse response = searchHistory("new_violations");
    assertThat(response.getMeasures(0).getHistoryCount()).isGreaterThan(0);
    measures = getMeasuresByMetricKey(orchestrator, PROJECT, "violations", "new_violations");
    assertThat(measures.get("violations")).isNotNull();
    assertThat(measures.get("new_violations")).isNull();
}
Also used : SearchHistoryResponse(org.sonarqube.ws.WsMeasures.SearchHistoryResponse) Measure(org.sonarqube.ws.WsMeasures.Measure) Test(org.junit.Test)

Aggregations

Measure (org.sonarqube.ws.WsMeasures.Measure)11 Test (org.junit.Test)8 WsMeasures (org.sonarqube.ws.WsMeasures)5 CheckForNull (javax.annotation.CheckForNull)3 ComponentWsRequest (org.sonarqube.ws.client.measure.ComponentWsRequest)3 MavenBuild (com.sonar.orchestrator.build.MavenBuild)2 SonarScanner (com.sonar.orchestrator.build.SonarScanner)2 JavaTestSuite.getMeasure (com.sonar.it.java.suite.JavaTestSuite.getMeasure)1 BuildResult (com.sonar.orchestrator.build.BuildResult)1 FileLocation (com.sonar.orchestrator.locator.FileLocation)1 Integer.parseInt (java.lang.Integer.parseInt)1 Map (java.util.Map)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 AfterClass (org.junit.AfterClass)1 Before (org.junit.Before)1 ComponentDto (org.sonar.db.component.ComponentDto)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 MetricDto (org.sonar.db.metric.MetricDto)1 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)1 IssueQuery (org.sonar.wsclient.issue.IssueQuery)1