use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_of_specified_project_assigned_to_current_user_if_only_mine_is_set.
@Test
@UseDataProvider("onlyMineParamValues")
public void returns_hotspots_of_specified_project_assigned_to_current_user_if_only_mine_is_set(String onlyMineParameter, boolean shouldFilter) {
ComponentDto project1 = dbTester.components().insertPublicProject();
String assigneeUuid = this.userSessionRule.logIn().registerComponents(project1).getUuid();
indexPermissions();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
IssueDto[] assigneeHotspots = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
insertHotspot(rule, project1, file1, randomAlphabetic(5));
return insertHotspot(rule, project1, file1, assigneeUuid);
}).toArray(IssueDto[]::new);
indexIssues();
SearchWsResponse allHotspots = newRequest(project1).executeProtobuf(SearchWsResponse.class);
SearchWsResponse userHotspots = newRequest(project1, r -> r.setParam("onlyMine", onlyMineParameter)).executeProtobuf(SearchWsResponse.class);
assertThat(allHotspots.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).contains(Arrays.stream(assigneeHotspots).map(IssueDto::getKey).toArray(String[]::new)).hasSizeGreaterThan(assigneeHotspots.length);
if (shouldFilter) {
assertThat(userHotspots.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(Arrays.stream(assigneeHotspots).map(IssueDto::getKey).toArray(String[]::new));
} else {
assertThat(userHotspots.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(allHotspots.getHotspotsList().stream().map(SearchWsResponse.Hotspot::getKey).toArray(String[]::new));
}
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method succeeds_on_public_project.
@Test
public void succeeds_on_public_project() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).isEmpty();
assertThat(response.getComponentsList()).isEmpty();
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse 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.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_of_specified_project.
@Test
public void returns_hotspots_of_specified_project() {
ComponentDto project1 = dbTester.components().insertPublicProject();
ComponentDto project2 = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project1, project2);
indexPermissions();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2));
IssueDto[] hotspots2 = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
insertHotspot(project1, file1, rule);
return insertHotspot(project2, file2, rule);
}).toArray(IssueDto[]::new);
indexIssues();
SearchWsResponse responseProject1 = newRequest(project1).executeProtobuf(SearchWsResponse.class);
assertThat(responseProject1.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).doesNotContainAnyElementsOf(Arrays.stream(hotspots2).map(IssueDto::getKey).collect(toList()));
assertThat(responseProject1.getComponentsList()).extracting(Component::getKey).containsOnly(project1.getKey(), file1.getKey());
SearchWsResponse responseProject2 = newRequest(project2).executeProtobuf(SearchWsResponse.class);
assertThat(responseProject2.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(Arrays.stream(hotspots2).map(IssueDto::getKey).toArray(String[]::new));
assertThat(responseProject2.getComponentsList()).extracting(Component::getKey).containsOnly(project2.getKey(), file2.getKey());
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse 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);
}
Aggregations