use of org.sonarqube.ws.Hotspots in project sonarqube by SonarSource.
the class SearchActionTest method verifyPaging.
private void verifyPaging(ComponentDto project, ComponentDto file, RuleDefinitionDto rule, int total, int pageSize) {
List<IssueDto> hotspots = IntStream.range(0, total).mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i).setKee("issue_" + i))).collect(toList());
indexIssues();
SearchWsResponse response = newRequest(project).setParam("p", "3").setParam("ps", String.valueOf(pageSize)).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactly(hotspots.stream().skip(2 * pageSize).limit(pageSize).map(IssueDto::getKey).toArray(String[]::new));
assertThat(response.getPaging().getTotal()).isEqualTo(hotspots.size());
assertThat(response.getPaging().getPageIndex()).isEqualTo(3);
assertThat(response.getPaging().getPageSize()).isEqualTo(pageSize);
response = newRequest(project).setParam("p", "4").setParam("ps", String.valueOf(pageSize)).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactly(hotspots.stream().skip(3 * pageSize).limit(pageSize).map(IssueDto::getKey).toArray(String[]::new));
assertThat(response.getPaging().getTotal()).isEqualTo(hotspots.size());
assertThat(response.getPaging().getPageIndex()).isEqualTo(4);
assertThat(response.getPaging().getPageSize()).isEqualTo(pageSize);
int emptyPage = (hotspots.size() / pageSize) + 10;
response = newRequest(project).setParam("p", String.valueOf(emptyPage)).setParam("ps", String.valueOf(pageSize)).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).isEmpty();
assertThat(response.getPaging().getTotal()).isEqualTo(hotspots.size());
assertThat(response.getPaging().getPageIndex()).isEqualTo(emptyPage);
assertThat(response.getPaging().getPageSize()).isEqualTo(pageSize);
}
use of org.sonarqube.ws.Hotspots in project sonarqube by SonarSource.
the class SearchActionTest method returns_only_hotspots_to_review_or_reviewed_of_project.
@Test
public void returns_only_hotspots_to_review_or_reviewed_of_project() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto[] hotspots = STATUSES.stream().map(status -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(rule, project, file, t -> t.setStatus(status));
}).toArray(IssueDto[]::new);
indexIssues();
String[] expectedKeys = Arrays.stream(hotspots).filter(t -> STATUS_REVIEWED.equals(t.getStatus()) || STATUS_TO_REVIEW.equals(t.getStatus())).map(IssueDto::getKey).toArray(String[]::new);
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(expectedKeys);
}
use of org.sonarqube.ws.Hotspots in project sonarqube by SonarSource.
the class SearchActionTest method returns_single_component_when_all_hotspots_are_on_project.
@Test
public void returns_single_component_when_all_hotspots_are_on_project() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
IssueDto[] hotspots = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(project, project, rule);
}).toArray(IssueDto[]::new);
indexIssues();
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(Hotspots.SearchWsResponse.Hotspot::getKey).containsOnly(Arrays.stream(hotspots).map(IssueDto::getKey).toArray(String[]::new));
assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project.getKey());
}
use of org.sonarqube.ws.Hotspots in project sonarqube by SonarSource.
the class SearchActionTest method returns_specified_hotspots.
@Test
public void returns_specified_hotspots() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
int total = 1 + RANDOM.nextInt(20);
List<IssueDto> hotspots = IntStream.range(0, total).mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))).collect(toList());
Collections.shuffle(hotspots);
List<IssueDto> selectedHotspots = hotspots.stream().limit(total == 1 ? 1 : 1 + RANDOM.nextInt(total - 1)).collect(toList());
indexIssues();
SearchWsResponse response = newRequest(selectedHotspots.stream().map(IssueDto::getKey).collect(toList())).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(selectedHotspots.stream().map(IssueDto::getKey).toArray(String[]::new));
}
use of org.sonarqube.ws.Hotspots in project sonarqube by SonarSource.
the class SearchActionTest method returns_empty_if_none_of_hotspot_keys_exist.
@Test
public void returns_empty_if_none_of_hotspot_keys_exist() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
List<IssueDto> hotspots = IntStream.range(0, 1 + RANDOM.nextInt(15)).mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))).collect(toList());
indexIssues();
SearchWsResponse response = newRequest(IntStream.range(0, 1 + RANDOM.nextInt(30)).mapToObj(i -> "key_" + i).collect(toList())).executeProtobuf(SearchWsResponse.class);
verify(issueIndexSyncProgressChecker).checkIfIssueSyncInProgress(any());
assertThat(response.getHotspotsList()).isEmpty();
}
Aggregations