Search in sources :

Example 1 with HistoryValue

use of org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryValue in project sonarqube by SonarSource.

the class SearchHistoryActionTest method inclusive_from_and_to_dates.

@Test
public void inclusive_from_and_to_dates() {
    project = db.components().insertProject();
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    List<String> analysisDates = LongStream.rangeClosed(1, 9).mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(System2.INSTANCE.now() + i * 1_000_000_000L))).peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, a).setValue(Double.valueOf(a.getCreatedAt())))).map(a -> formatDateTime(a.getCreatedAt())).collect(Collectors.toList());
    db.commit();
    wsRequest.setComponent(project.getKey()).setFrom(analysisDates.get(1)).setTo(analysisDates.get(3));
    SearchHistoryResponse result = call();
    assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(1, 100, 3);
    assertThat(result.getMeasures(0).getHistoryList()).extracting(HistoryValue::getDate).containsExactly(analysisDates.get(1), analysisDates.get(2), analysisDates.get(3));
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) Protobuf.setNullable(org.sonar.core.util.Protobuf.setNullable) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DbSession(org.sonar.db.DbSession) Collections.singletonList(java.util.Collections.singletonList) PARAM_COMPONENT(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT) 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) HistoryValue(org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryValue) HistoryMeasure(org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryMeasure) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Collectors(org.sonar.core.util.stream.Collectors) NotFoundException(org.sonar.server.exceptions.NotFoundException) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) PARAM_TO(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_TO) ComponentTesting.newProjectDto(org.sonar.db.component.ComponentTesting.newProjectDto) MeasureTesting.newMeasureDto(org.sonar.db.measure.MeasureTesting.newMeasureDto) MediaTypes(org.sonarqube.ws.MediaTypes) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) PARAM_METRICS(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRICS) UserSessionRule(org.sonar.server.tester.UserSessionRule) SearchHistoryResponse(org.sonarqube.ws.WsMeasures.SearchHistoryResponse) PARAM_FROM(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM) LongStream(java.util.stream.LongStream) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Throwables(com.google.common.base.Throwables) Paging(org.sonarqube.ws.Common.Paging) IOException(java.io.IOException) Test(org.junit.Test) STATUS_UNPROCESSED(org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED) WsActionTester(org.sonar.server.ws.WsActionTester) ValueType(org.sonar.api.measures.Metric.ValueType) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) MetricDto(org.sonar.db.metric.MetricDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) SearchHistoryRequest(org.sonarqube.ws.client.measure.SearchHistoryRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) SearchHistoryResponse(org.sonarqube.ws.WsMeasures.SearchHistoryResponse) Test(org.junit.Test)

Example 2 with HistoryValue

use of org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryValue in project sonarqube by SonarSource.

the class SearchHistoryActionTest method pagination_applies_to_analyses.

@Test
public void pagination_applies_to_analyses() {
    project = db.components().insertProject();
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    List<String> analysisDates = LongStream.rangeClosed(1, 9).mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(i * 1_000_000_000))).peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, a).setValue(101d))).map(a -> formatDateTime(a.getCreatedAt())).collect(Collectors.toList());
    db.commit();
    wsRequest.setComponent(project.getKey()).setPage(2).setPageSize(3);
    SearchHistoryResponse result = call();
    assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(2, 3, 9);
    assertThat(result.getMeasures(0).getHistoryList()).extracting(HistoryValue::getDate).containsExactly(analysisDates.get(3), analysisDates.get(4), analysisDates.get(5));
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) Protobuf.setNullable(org.sonar.core.util.Protobuf.setNullable) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DbSession(org.sonar.db.DbSession) Collections.singletonList(java.util.Collections.singletonList) PARAM_COMPONENT(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT) 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) HistoryValue(org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryValue) HistoryMeasure(org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryMeasure) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Collectors(org.sonar.core.util.stream.Collectors) NotFoundException(org.sonar.server.exceptions.NotFoundException) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) PARAM_TO(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_TO) ComponentTesting.newProjectDto(org.sonar.db.component.ComponentTesting.newProjectDto) MeasureTesting.newMeasureDto(org.sonar.db.measure.MeasureTesting.newMeasureDto) MediaTypes(org.sonarqube.ws.MediaTypes) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) PARAM_METRICS(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRICS) UserSessionRule(org.sonar.server.tester.UserSessionRule) SearchHistoryResponse(org.sonarqube.ws.WsMeasures.SearchHistoryResponse) PARAM_FROM(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM) LongStream(java.util.stream.LongStream) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Throwables(com.google.common.base.Throwables) Paging(org.sonarqube.ws.Common.Paging) IOException(java.io.IOException) Test(org.junit.Test) STATUS_UNPROCESSED(org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED) WsActionTester(org.sonar.server.ws.WsActionTester) ValueType(org.sonar.api.measures.Metric.ValueType) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) MetricDto(org.sonar.db.metric.MetricDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) SearchHistoryRequest(org.sonarqube.ws.client.measure.SearchHistoryRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) SearchHistoryResponse(org.sonarqube.ws.WsMeasures.SearchHistoryResponse) Test(org.junit.Test)

Aggregations

Throwables (com.google.common.base.Throwables)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 LongStream (java.util.stream.LongStream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.tuple (org.assertj.core.api.Assertions.tuple)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 ExpectedException (org.junit.rules.ExpectedException)2 ValueType (org.sonar.api.measures.Metric.ValueType)2 WebService (org.sonar.api.server.ws.WebService)2 Param (org.sonar.api.server.ws.WebService.Param)2 DateUtils.formatDateTime (org.sonar.api.utils.DateUtils.formatDateTime)2 DateUtils.parseDateTime (org.sonar.api.utils.DateUtils.parseDateTime)2 System2 (org.sonar.api.utils.System2)2 UserRole (org.sonar.api.web.UserRole)2