Search in sources :

Example 1 with Analysis

use of org.sonarqube.ws.ProjectAnalyses.Analysis in project sonarqube by SonarSource.

the class SearchActionTest method return_analyses_ordered_by_analysis_date.

@Test
public void return_analyses_ordered_by_analysis_date() {
    ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1"));
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(1_000_000L));
    db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(2_000_000L));
    db.components().insertSnapshot(newAnalysis(project).setUuid("A3").setCreatedAt(3_000_000L));
    List<Analysis> result = call("P1").getAnalysesList();
    assertThat(result).hasSize(3);
    assertThat(result).extracting(Analysis::getKey, a -> parseDateTime(a.getDate()).getTime()).containsExactly(tuple("A3", 3_000_000L), tuple("A2", 2_000_000L), tuple("A1", 1_000_000L));
}
Also used : IntStream(java.util.stream.IntStream) ComponentFinder(org.sonar.server.component.ComponentFinder) Protobuf.setNullable(org.sonar.core.util.Protobuf.setNullable) QUALITY_GATE(org.sonarqube.ws.client.projectanalysis.EventCategory.QUALITY_GATE) PARAM_CATEGORY(org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_CATEGORY) EventTesting.newEvent(org.sonar.db.event.EventTesting.newEvent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_PROJECT(org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_PROJECT) SearchRequest(org.sonarqube.ws.client.projectanalysis.SearchRequest) Function(java.util.function.Function) ComponentTesting.newProjectDto(org.sonar.db.component.ComponentTesting.newProjectDto) SearchResponse(org.sonarqube.ws.ProjectAnalyses.SearchResponse) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) OrganizationDto(org.sonar.db.organization.OrganizationDto) ExpectedException(org.junit.rules.ExpectedException) Nullable(javax.annotation.Nullable) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Analysis(org.sonarqube.ws.ProjectAnalyses.Analysis) 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) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) PROTOBUF(org.sonarqube.ws.MediaTypes.PROTOBUF) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) POST(org.sonarqube.ws.client.WsRequest.Method.POST) EventCategory(org.sonarqube.ws.client.projectanalysis.EventCategory) SnapshotDto(org.sonar.db.component.SnapshotDto) OTHER(org.sonarqube.ws.client.projectanalysis.EventCategory.OTHER) VERSION(org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION) EventDto(org.sonar.db.event.EventDto) Event(org.sonarqube.ws.ProjectAnalyses.Event) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) Analysis(org.sonarqube.ws.ProjectAnalyses.Analysis) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 2 with Analysis

use of org.sonarqube.ws.ProjectAnalyses.Analysis in project sonarqube by SonarSource.

the class SearchActionTest method return_events.

@Test
public void return_events() {
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setKey("P1"));
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
    SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(newProjectDto(organizationDto)).setUuid("A42"));
    EventDto e1 = db.events().insertEvent(newEvent(a1).setUuid("E1").setName("N1").setCategory(EventCategory.QUALITY_GATE.getLabel()).setDescription("D1"));
    EventDto e2 = db.events().insertEvent(newEvent(a1).setUuid("E2").setName("N2").setCategory(VERSION.getLabel()).setDescription("D2"));
    db.events().insertEvent(newEvent(a42));
    List<Analysis> result = call("P1").getAnalysesList();
    assertThat(result).hasSize(1);
    List<Event> events = result.get(0).getEventsList();
    assertThat(events).hasSize(2);
    assertThat(events).extracting(Event::getKey, wsToDbCategory(), Event::getName, Event::getDescription).containsOnly(tuple(e1.getUuid(), e1.getCategory(), e1.getName(), e1.getDescription()), tuple(e2.getUuid(), e2.getCategory(), e2.getName(), e2.getDescription()));
}
Also used : SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) Analysis(org.sonarqube.ws.ProjectAnalyses.Analysis) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) EventTesting.newEvent(org.sonar.db.event.EventTesting.newEvent) Event(org.sonarqube.ws.ProjectAnalyses.Event) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 3 with Analysis

use of org.sonarqube.ws.ProjectAnalyses.Analysis in project sonarqube by SonarSource.

the class SearchActionTest method return_only_processed_analyses.

@Test
public void return_only_processed_analyses() {
    ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("P1"));
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
    db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setStatus(SnapshotDto.STATUS_UNPROCESSED));
    List<Analysis> result = call("P1").getAnalysesList();
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getKey()).isEqualTo("A1");
}
Also used : SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) Analysis(org.sonarqube.ws.ProjectAnalyses.Analysis) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 4 with Analysis

use of org.sonarqube.ws.ProjectAnalyses.Analysis in project sonarqube by SonarSource.

the class SearchActionTest method filter_by_category.

@Test
public void filter_by_category() {
    ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1"));
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
    SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2"));
    SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(project).setUuid("A42"));
    db.events().insertEvent(newEvent(a1).setUuid("E11").setCategory(VERSION.getLabel()));
    db.events().insertEvent(newEvent(a1).setUuid("E12").setCategory(QUALITY_GATE.getLabel()));
    db.events().insertEvent(newEvent(a2).setUuid("E21").setCategory(QUALITY_GATE.getLabel()));
    // Analysis A42 doesn't have a quality gate event
    db.events().insertEvent(newEvent(a42).setCategory(OTHER.getLabel()));
    List<Analysis> result = call(SearchRequest.builder().setProject("P1").setCategory(QUALITY_GATE).build()).getAnalysesList();
    assertThat(result).extracting(Analysis::getKey).containsOnly("A1", "A2");
}
Also used : SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) Analysis(org.sonarqube.ws.ProjectAnalyses.Analysis) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 ComponentDto (org.sonar.db.component.ComponentDto)4 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)4 Analysis (org.sonarqube.ws.ProjectAnalyses.Analysis)4 SnapshotDto (org.sonar.db.component.SnapshotDto)3 EventDto (org.sonar.db.event.EventDto)2 EventTesting.newEvent (org.sonar.db.event.EventTesting.newEvent)2 OrganizationDto (org.sonar.db.organization.OrganizationDto)2 Event (org.sonarqube.ws.ProjectAnalyses.Event)2 Throwables (com.google.common.base.Throwables)1 IOException (java.io.IOException)1 List (java.util.List)1 Function (java.util.function.Function)1 IntStream (java.util.stream.IntStream)1 Nullable (javax.annotation.Nullable)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Rule (org.junit.Rule)1 ExpectedException (org.junit.rules.ExpectedException)1 WebService (org.sonar.api.server.ws.WebService)1