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));
}
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()));
}
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");
}
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");
}
Aggregations