use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_of_specified_application_branch.
@Test
public void returns_hotspots_of_specified_application_branch() {
ComponentDto application = dbTester.components().insertPublicApplication();
ComponentDto applicationBranch = dbTester.components().insertProjectBranch(application);
ComponentDto project1 = dbTester.components().insertPublicProject();
ComponentDto project2 = dbTester.components().insertPublicProject();
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project1, application));
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project2, applicationBranch));
indexViews();
userSessionRule.registerApplication(application, applicationBranch, 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 responseApplication = newRequest(application).executeProtobuf(SearchWsResponse.class);
assertThat(responseApplication.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).doesNotContainAnyElementsOf(Arrays.stream(hotspots2).map(IssueDto::getKey).collect(toList()));
assertThat(responseApplication.getComponentsList()).extracting(Component::getKey).containsOnly(project1.getKey(), file1.getKey());
SearchWsResponse responseApplicationBranch = newRequest(applicationBranch).executeProtobuf(SearchWsResponse.class);
assertThat(responseApplicationBranch.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(Arrays.stream(hotspots2).map(IssueDto::getKey).toArray(String[]::new));
assertThat(responseApplicationBranch.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_hotpots_reviewed_as_safe_if_status_is_REVIEWED_and_resolution_is_SAFE.
@Test
public void returns_hotpots_reviewed_as_safe_if_status_is_REVIEWED_and_resolution_is_SAFE() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
List<IssueDto> safeHotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file).filter(t -> STATUS_REVIEWED.equals(t.getStatus()) && RESOLUTION_SAFE.equals(t.getResolution())).collect(toList());
indexIssues();
SearchWsResponse response = newRequest(project, STATUS_REVIEWED, RESOLUTION_SAFE).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(safeHotspots.stream().map(IssueDto::getKey).toArray(String[]::new));
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotpots_reviewed_as_safe_and_fixed_if_status_is_REVIEWED_and_resolution_is_not_set.
@Test
public void returns_hotpots_reviewed_as_safe_and_fixed_if_status_is_REVIEWED_and_resolution_is_not_set() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
List<IssueDto> reviewedHotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file).filter(t -> STATUS_REVIEWED.equals(t.getStatus())).collect(toList());
indexIssues();
SearchWsResponse response = newRequest(project, STATUS_REVIEWED, null).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(reviewedHotspots.stream().map(IssueDto::getKey).toArray(String[]::new));
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse 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.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspot_with_secondary_locations.
@Test
public void returns_hotspot_with_secondary_locations() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
ComponentDto anotherFile = dbTester.components().insertComponent(newFileDto(project));
List<DbIssues.Location> hotspotLocations = Stream.of(newHotspotLocation(file.uuid(), "security hotspot flow message 0", 1, 1, 0, 12), newHotspotLocation(file.uuid(), "security hotspot flow message 1", 3, 3, 0, 10), newHotspotLocation(anotherFile.uuid(), "security hotspot flow message 2", 5, 5, 0, 15), newHotspotLocation(anotherFile.uuid(), "security hotspot flow message 3", 7, 7, 0, 18), newHotspotLocation(null, "security hotspot flow message 4", 12, 12, 2, 8)).collect(toList());
DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder().addFlow(DbIssues.Flow.newBuilder().addAllLocation(hotspotLocations));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
dbTester.issues().insertHotspot(rule, project, file, h -> h.setLocations(locations.build()));
indexIssues();
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsCount()).isOne();
assertThat(response.getHotspotsList().stream().findFirst().get().getFlowsCount()).isEqualTo(1);
assertThat(response.getHotspotsList().stream().findFirst().get().getFlowsList().stream().findFirst().get().getLocationsCount()).isEqualTo(5);
assertThat(response.getHotspotsList().stream().findFirst().get().getFlowsList().stream().findFirst().get().getLocationsList()).extracting(Common.Location::getComponent, Common.Location::getMsg, l -> l.getTextRange().getStartLine(), l -> l.getTextRange().getEndLine(), l -> l.getTextRange().getStartOffset(), l -> l.getTextRange().getEndOffset()).containsExactlyInAnyOrder(tuple(file.getKey(), "security hotspot flow message 0", 1, 1, 0, 12), tuple(file.getKey(), "security hotspot flow message 1", 3, 3, 0, 10), tuple(anotherFile.getKey(), "security hotspot flow message 2", 5, 5, 0, 15), tuple(anotherFile.getKey(), "security hotspot flow message 3", 7, 7, 0, 18), tuple(file.getKey(), "security hotspot flow message 4", 12, 12, 2, 8));
}
Aggregations