Search in sources :

Example 6 with SearchHistoryRequest

use of org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest 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 SearchHistoryRequest

use of org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest 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 SearchHistoryRequest

use of org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest 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 SearchHistoryRequest

use of org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest 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)

Example 10 with SearchHistoryRequest

use of org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest in project sonarqube by SonarSource.

the class SearchHistoryActionTest method fail_if_unknown_component.

@Test
public void fail_if_unknown_component() {
    SearchHistoryRequest request = SearchHistoryRequest.builder().setComponent("__UNKNOWN__").setMetrics(singletonList(complexityMetric.getKey())).build();
    assertThatThrownBy(() -> call(request)).isInstanceOf(NotFoundException.class);
}
Also used : SearchHistoryRequest(org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 SearchHistoryRequest (org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest)13 SearchHistoryResponse (org.sonarqube.ws.Measures.SearchHistoryResponse)9 ComponentDto (org.sonar.db.component.ComponentDto)5 HistoryMeasure (org.sonarqube.ws.Measures.SearchHistoryResponse.HistoryMeasure)4 SnapshotDto (org.sonar.db.component.SnapshotDto)3 Double.parseDouble (java.lang.Double.parseDouble)2 String.format (java.lang.String.format)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Optional.ofNullable (java.util.Optional.ofNullable)2 LongStream (java.util.stream.LongStream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Assertions.tuple (org.assertj.core.api.Assertions.tuple)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 ValueType (org.sonar.api.measures.Metric.ValueType)2 WebService (org.sonar.api.server.ws.WebService)2