use of org.sonar.server.issue.index.IssueQuery in project sonarqube by SonarSource.
the class IssuesFinderSortTest method should_sort_by_status.
@Test
public void should_sort_by_status() {
IssueDto issue1 = new IssueDto().setKee("A").setStatus("CLOSED");
IssueDto issue2 = new IssueDto().setKee("B").setStatus("REOPENED");
IssueDto issue3 = new IssueDto().setKee("C").setStatus("OPEN");
List<IssueDto> dtoList = newArrayList(issue1, issue2, issue3);
IssueQuery query = IssueQuery.builder().sort(IssueQuery.SORT_BY_STATUS).asc(false).build();
IssuesFinderSort issuesFinderSort = new IssuesFinderSort(dtoList, query);
List<IssueDto> result = newArrayList(issuesFinderSort.sort());
assertThat(result).hasSize(3);
assertThat(result.get(0).getStatus()).isEqualTo("REOPENED");
assertThat(result.get(1).getStatus()).isEqualTo("OPEN");
assertThat(result.get(2).getStatus()).isEqualTo("CLOSED");
}
use of org.sonar.server.issue.index.IssueQuery in project sonarqube by SonarSource.
the class SearchAction method doIndexSearch.
private SearchResponse doIndexSearch(WsRequest wsRequest, DbSession dbSession, @Nullable ComponentDto project) {
var builder = IssueQuery.builder().types(singleton(RuleType.SECURITY_HOTSPOT.name())).sort(IssueQuery.SORT_HOTSPOTS).asc(true).statuses(wsRequest.getStatus().map(Collections::singletonList).orElse(STATUSES));
if (project != null) {
String projectUuid = firstNonNull(project.getMainBranchProjectUuid(), project.uuid());
if (Qualifiers.APP.equals(project.qualifier())) {
builder.viewUuids(singletonList(projectUuid));
if (wsRequest.isSinceLeakPeriod() && wsRequest.getPullRequest().isEmpty()) {
addSinceLeakPeriodFilterByProjects(builder, dbSession, project);
}
} else {
builder.projectUuids(singletonList(projectUuid));
if (wsRequest.isSinceLeakPeriod() && wsRequest.getPullRequest().isEmpty()) {
addSinceLeakPeriodFilter(dbSession, project, builder);
}
}
addMainBranchFilter(project, builder);
}
if (!wsRequest.getHotspotKeys().isEmpty()) {
builder.issueKeys(wsRequest.getHotspotKeys());
}
if (!wsRequest.getFiles().isEmpty()) {
builder.files(wsRequest.getFiles());
}
if (wsRequest.isOnlyMine()) {
userSession.checkLoggedIn();
builder.assigneeUuids(Collections.singletonList(userSession.getUuid()));
}
wsRequest.getStatus().ifPresent(status -> builder.resolved(STATUS_REVIEWED.equals(status)));
wsRequest.getResolution().ifPresent(resolution -> builder.resolutions(singleton(resolution)));
addSecurityStandardFilters(wsRequest, builder);
IssueQuery query = builder.build();
SearchOptions searchOptions = new SearchOptions().setPage(wsRequest.page, wsRequest.index);
return issueIndex.search(query, searchOptions);
}
use of org.sonar.server.issue.index.IssueQuery in project sonarqube by SonarSource.
the class IssuesFinderSortTest method should_sort_by_close_date.
@Test
public void should_sort_by_close_date() {
Date date = new Date();
Date date1 = DateUtils.addDays(date, -3);
Date date2 = DateUtils.addDays(date, -2);
Date date3 = DateUtils.addDays(date, -1);
IssueDto issue1 = new IssueDto().setKee("A").setIssueCloseDate(date1);
IssueDto issue2 = new IssueDto().setKee("B").setIssueCloseDate(date3);
IssueDto issue3 = new IssueDto().setKee("C").setIssueCloseDate(date2);
List<IssueDto> dtoList = newArrayList(issue1, issue2, issue3);
IssueQuery query = IssueQuery.builder().sort(IssueQuery.SORT_BY_CLOSE_DATE).asc(false).build();
IssuesFinderSort issuesFinderSort = new IssuesFinderSort(dtoList, query);
List<IssueDto> result = newArrayList(issuesFinderSort.sort());
assertThat(result).hasSize(3);
assertThat(result.get(0).getIssueCloseDate()).isEqualTo(date3);
assertThat(result.get(1).getIssueCloseDate()).isEqualTo(date2);
assertThat(result.get(2).getIssueCloseDate()).isEqualTo(date1);
}
use of org.sonar.server.issue.index.IssueQuery in project sonarqube by SonarSource.
the class IssuesFinderSortTest method should_sort_by_creation_date.
@Test
public void should_sort_by_creation_date() {
Date date = new Date();
Date date1 = DateUtils.addDays(date, -3);
Date date2 = DateUtils.addDays(date, -2);
Date date3 = DateUtils.addDays(date, -1);
IssueDto issue1 = new IssueDto().setKee("A").setIssueCreationDate(date1);
IssueDto issue2 = new IssueDto().setKee("B").setIssueCreationDate(date3);
IssueDto issue3 = new IssueDto().setKee("C").setIssueCreationDate(date2);
List<IssueDto> dtoList = newArrayList(issue1, issue2, issue3);
IssueQuery query = IssueQuery.builder().sort(IssueQuery.SORT_BY_CREATION_DATE).asc(false).build();
IssuesFinderSort issuesFinderSort = new IssuesFinderSort(dtoList, query);
List<IssueDto> result = newArrayList(issuesFinderSort.sort());
assertThat(result).hasSize(3);
assertThat(result.get(0).getIssueCreationDate()).isEqualTo(date3);
assertThat(result.get(1).getIssueCreationDate()).isEqualTo(date2);
assertThat(result.get(2).getIssueCreationDate()).isEqualTo(date1);
}
use of org.sonar.server.issue.index.IssueQuery in project sonarqube by SonarSource.
the class IssuesFinderSortTest method should_fail_to_sort_with_unknown_sort.
@Test
public void should_fail_to_sort_with_unknown_sort() {
IssueQuery query = mock(IssueQuery.class);
when(query.sort()).thenReturn("unknown");
IssuesFinderSort issuesFinderSort = new IssuesFinderSort(null, query);
try {
issuesFinderSort.sort();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Cannot sort on field : unknown");
}
}
Aggregations