Search in sources :

Example 6 with SearchHistoryResponse

use of org.sonarqube.ws.Measures.SearchHistoryResponse in project sonarqube by SonarSource.

the class SearchHistoryActionTest method do_not_return_unprocessed_analyses.

@Test
public void do_not_return_unprocessed_analyses() {
    dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setStatus(STATUS_UNPROCESSED));
    db.commit();
    SearchHistoryRequest request = SearchHistoryRequest.builder().setComponent(project.getDbKey()).setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey())).build();
    SearchHistoryResponse result = call(request);
    // one analysis in setUp method
    assertThat(result.getPaging().getTotal()).isOne();
}
Also used : SearchHistoryResponse(org.sonarqube.ws.Measures.SearchHistoryResponse) SearchHistoryRequest(org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest) Test(org.junit.Test)

Example 7 with SearchHistoryResponse

use of org.sonarqube.ws.Measures.SearchHistoryResponse in project sonarqube by SonarSource.

the class SearchHistoryActionTest method return_metrics.

@Test
public void return_metrics() {
    dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, analysis).setValue(42.0d));
    db.commit();
    SearchHistoryRequest request = SearchHistoryRequest.builder().setComponent(project.getDbKey()).setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey())).build();
    SearchHistoryResponse result = call(request);
    assertThat(result.getMeasuresList()).hasSize(3).extracting(HistoryMeasure::getMetric).containsExactly(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey());
}
Also used : SearchHistoryResponse(org.sonarqube.ws.Measures.SearchHistoryResponse) SearchHistoryRequest(org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest) Test(org.junit.Test)

Example 8 with SearchHistoryResponse

use of org.sonarqube.ws.Measures.SearchHistoryResponse in project sonarqube by SonarSource.

the class SearchHistoryActionTest method empty_response.

@Test
public void empty_response() {
    project = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, project);
    SearchHistoryRequest request = SearchHistoryRequest.builder().setComponent(project.getDbKey()).setMetrics(singletonList(complexityMetric.getKey())).build();
    SearchHistoryResponse result = call(request);
    assertThat(result.getMeasuresList()).hasSize(1);
    assertThat(result.getMeasures(0).getHistoryCount()).isZero();
    assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(1, 100, 0);
}
Also used : SearchHistoryResponse(org.sonarqube.ws.Measures.SearchHistoryResponse) SearchHistoryRequest(org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest) Test(org.junit.Test)

Example 9 with SearchHistoryResponse

use of org.sonarqube.ws.Measures.SearchHistoryResponse in project sonarqube by SonarSource.

the class SearchHistoryActionTest method pull_request.

@Test
public void pull_request() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, project);
    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
    ComponentDto file = db.components().insertComponent(newFileDto(branch));
    SnapshotDto analysis = db.components().insertSnapshot(branch);
    MeasureDto measure = db.measures().insertMeasure(file, analysis, nclocMetric, m -> m.setValue(2d));
    SearchHistoryResponse result = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr-123").setParam(PARAM_METRICS, "ncloc").executeProtobuf(SearchHistoryResponse.class);
    assertThat(result.getMeasuresList()).extracting(HistoryMeasure::getMetric).hasSize(1);
    HistoryMeasure historyMeasure = result.getMeasures(0);
    assertThat(historyMeasure.getMetric()).isEqualTo(nclocMetric.getKey());
    assertThat(historyMeasure.getHistoryList()).extracting(m -> parseDouble(m.getValue())).containsExactlyInAnyOrder(measure.getValue());
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) MeasureTesting.newMeasureDto(org.sonar.db.measure.MeasureTesting.newMeasureDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DbSession(org.sonar.db.DbSession) MeasureDto(org.sonar.db.measure.MeasureDto) PULL_REQUEST(org.sonar.db.component.BranchType.PULL_REQUEST) Collections.singletonList(java.util.Collections.singletonList) MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) Arrays.asList(java.util.Arrays.asList) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) Double.parseDouble(java.lang.Double.parseDouble) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) HistoryMeasure(org.sonarqube.ws.Measures.SearchHistoryResponse.HistoryMeasure) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) PARAM_TO(org.sonar.server.component.ws.MeasuresWsParameters.PARAM_TO) HistoryValue(org.sonarqube.ws.Measures.SearchHistoryResponse.HistoryValue) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) SearchHistoryRequest(org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest) PARAM_FROM(org.sonar.server.component.ws.MeasuresWsParameters.PARAM_FROM) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) MeasureTesting.newMeasureDto(org.sonar.db.measure.MeasureTesting.newMeasureDto) TestComponentFinder(org.sonar.server.component.TestComponentFinder) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) LongStream(java.util.stream.LongStream) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Optional.ofNullable(java.util.Optional.ofNullable) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Paging(org.sonarqube.ws.Common.Paging) Test(org.junit.Test) STATUS_UNPROCESSED(org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED) PARAM_COMPONENT(org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT) WsActionTester(org.sonar.server.ws.WsActionTester) PARAM_PULL_REQUEST(org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PULL_REQUEST) ValueType(org.sonar.api.measures.Metric.ValueType) PARAM_METRICS(org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRICS) ComponentTesting.newPrivateProjectDto(org.sonar.db.component.ComponentTesting.newPrivateProjectDto) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) MetricDto(org.sonar.db.metric.MetricDto) SearchHistoryResponse(org.sonarqube.ws.Measures.SearchHistoryResponse) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ComponentDbTester.toProjectDto(org.sonar.db.component.ComponentDbTester.toProjectDto) SnapshotDto(org.sonar.db.component.SnapshotDto) PARAM_BRANCH(org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH) SnapshotDto(org.sonar.db.component.SnapshotDto) SearchHistoryResponse(org.sonarqube.ws.Measures.SearchHistoryResponse) ComponentDto(org.sonar.db.component.ComponentDto) HistoryMeasure(org.sonarqube.ws.Measures.SearchHistoryResponse.HistoryMeasure) Test(org.junit.Test)

Example 10 with SearchHistoryResponse

use of org.sonarqube.ws.Measures.SearchHistoryResponse in project sonarqube by SonarSource.

the class SearchHistoryActionTest method measure_without_values.

@Test
public void measure_without_values() {
    dbClient.measureDao().insert(dbSession, newMeasureDto(stringMetric, project, analysis).setValue(null).setData(null));
    db.commit();
    SearchHistoryRequest request = SearchHistoryRequest.builder().setComponent(project.getDbKey()).setMetrics(singletonList(stringMetric.getKey())).build();
    SearchHistoryResponse result = call(request);
    HistoryMeasure measure = result.getMeasuresList().stream().filter(m -> m.getMetric().equals(stringMetric.getKey())).findFirst().get();
    assertThat(measure.getHistoryList()).hasSize(1);
    assertThat(measure.getHistory(0).hasValue()).isFalse();
}
Also used : SearchHistoryResponse(org.sonarqube.ws.Measures.SearchHistoryResponse) HistoryMeasure(org.sonarqube.ws.Measures.SearchHistoryResponse.HistoryMeasure) SearchHistoryRequest(org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest) Test(org.junit.Test)

Aggregations

SearchHistoryResponse (org.sonarqube.ws.Measures.SearchHistoryResponse)12 Test (org.junit.Test)11 SearchHistoryRequest (org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest)11 ComponentDto (org.sonar.db.component.ComponentDto)7 SnapshotDto (org.sonar.db.component.SnapshotDto)6 HistoryMeasure (org.sonarqube.ws.Measures.SearchHistoryResponse.HistoryMeasure)6 String.format (java.lang.String.format)5 List (java.util.List)5 Optional.ofNullable (java.util.Optional.ofNullable)5 WebService (org.sonar.api.server.ws.WebService)5 Param (org.sonar.api.server.ws.WebService.Param)5 UserRole (org.sonar.api.web.UserRole)5 MoreCollectors (org.sonar.core.util.stream.MoreCollectors)5 DbClient (org.sonar.db.DbClient)5 DbSession (org.sonar.db.DbSession)5 MeasureDto (org.sonar.db.measure.MeasureDto)5 MetricDto (org.sonar.db.metric.MetricDto)5 Double.parseDouble (java.lang.Double.parseDouble)4 Arrays.asList (java.util.Arrays.asList)4 Collections.singletonList (java.util.Collections.singletonList)4