use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_with_specified_files.
@Test
public void returns_hotspots_with_specified_files() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
final IssueDto hotspot = insertHotspot(project, file1, rule);
insertHotspot(project, file2, rule);
indexIssues();
SearchWsResponse response = newRequest(project).setParam("files", file1.path()).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactly(hotspot.getKey());
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method does_not_fail_when_hotspot_has_none_of_the_nullable_fields.
@Test
public void does_not_fail_when_hotspot_has_none_of_the_nullable_fields() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
insertHotspot(rule, project, file, t -> t.setResolution(null).setLine(null).setMessage(null).setAssigneeUuid(null).setAuthorLogin(null));
indexIssues();
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).hasSize(1);
SearchWsResponse.Hotspot actual = response.getHotspots(0);
assertThat(actual.hasResolution()).isFalse();
assertThat(actual.hasLine()).isFalse();
assertThat(actual.getMessage()).isEmpty();
assertThat(actual.hasAssignee()).isFalse();
assertThat(actual.getAuthor()).isEmpty();
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspot_components_when_project_has_hotspots.
@Test
public void returns_hotspot_components_when_project_has_hotspots() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
ComponentDto fileWithHotspot = dbTester.components().insertComponent(newFileDto(project));
Arrays.stream(RuleType.values()).filter(t -> t != SECURITY_HOTSPOT).forEach(ruleType -> {
RuleDefinitionDto rule = newRule(ruleType);
dbTester.issues().insert(rule, project, file, t -> t.setType(ruleType));
});
IssueDto[] hotspots = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(project, fileWithHotspot, rule);
}).toArray(IssueDto[]::new);
indexIssues();
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(Arrays.stream(hotspots).map(IssueDto::getKey).toArray(String[]::new));
assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project.getKey(), fileWithHotspot.getKey());
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_of_specified_application.
@Test
public void returns_hotspots_of_specified_application() {
ComponentDto application1 = dbTester.components().insertPublicApplication();
ComponentDto application2 = dbTester.components().insertPublicApplication();
ComponentDto project1 = dbTester.components().insertPublicProject();
ComponentDto project2 = dbTester.components().insertPublicProject();
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project1, application1));
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project2, application2));
indexViews();
userSessionRule.registerApplication(application1, project1).registerApplication(application2, 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 responseApplication1 = newRequest(application1).executeProtobuf(SearchWsResponse.class);
assertThat(responseApplication1.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).doesNotContainAnyElementsOf(Arrays.stream(hotspots2).map(IssueDto::getKey).collect(toList()));
assertThat(responseApplication1.getComponentsList()).extracting(Component::getKey).containsOnly(project1.getKey(), file1.getKey());
SearchWsResponse responseApplication2 = newRequest(application2).executeProtobuf(SearchWsResponse.class);
assertThat(responseApplication2.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(Arrays.stream(hotspots2).map(IssueDto::getKey).toArray(String[]::new));
assertThat(responseApplication2.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_fixed_if_status_is_REVIEWED_and_resolution_is_FIXED.
@Test
public void returns_hotpots_reviewed_as_fixed_if_status_is_REVIEWED_and_resolution_is_FIXED() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
List<IssueDto> fixedHotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file).filter(t -> STATUS_REVIEWED.equals(t.getStatus()) && RESOLUTION_FIXED.equals(t.getResolution())).collect(toList());
indexIssues();
SearchWsResponse response = newRequest(project, STATUS_REVIEWED, RESOLUTION_FIXED).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(fixedHotspots.stream().map(IssueDto::getKey).toArray(String[]::new));
}
Aggregations