use of org.sonarqube.ws.Hotspots.Component in project sonarqube by SonarSource.
the class SearchActionTest method returns_details_of_components.
@Test
public void returns_details_of_components() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto directory = dbTester.components().insertComponent(newDirectory(project, "donut/acme"));
ComponentDto directory2 = dbTester.components().insertComponent(newDirectory(project, "foo/bar"));
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
IssueDto fileHotspot = insertHotspot(project, file, rule);
IssueDto dirHotspot = insertHotspot(project, directory, rule);
IssueDto projectHotspot = insertHotspot(project, project, rule);
indexIssues();
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(fileHotspot.getKey(), dirHotspot.getKey(), projectHotspot.getKey());
assertThat(response.getComponentsList()).hasSize(3);
assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project.getKey(), directory.getKey(), file.getKey());
Map<String, Component> componentByKey = response.getComponentsList().stream().collect(uniqueIndex(Component::getKey));
Component actualProject = componentByKey.get(project.getKey());
assertThat(actualProject.getQualifier()).isEqualTo(project.qualifier());
assertThat(actualProject.getName()).isEqualTo(project.name());
assertThat(actualProject.getLongName()).isEqualTo(project.longName());
assertThat(actualProject.hasPath()).isFalse();
assertThat(actualProject.hasBranch()).isFalse();
assertThat(actualProject.hasPullRequest()).isFalse();
Component actualDirectory = componentByKey.get(directory.getKey());
assertThat(actualDirectory.getQualifier()).isEqualTo(directory.qualifier());
assertThat(actualDirectory.getName()).isEqualTo(directory.name());
assertThat(actualDirectory.getLongName()).isEqualTo(directory.longName());
assertThat(actualDirectory.getPath()).isEqualTo(directory.path());
assertThat(actualDirectory.hasBranch()).isFalse();
assertThat(actualDirectory.hasPullRequest()).isFalse();
Component actualFile = componentByKey.get(file.getKey());
assertThat(actualFile.getQualifier()).isEqualTo(file.qualifier());
assertThat(actualFile.getName()).isEqualTo(file.name());
assertThat(actualFile.getLongName()).isEqualTo(file.longName());
assertThat(actualFile.getPath()).isEqualTo(file.path());
assertThat(actualFile.hasBranch()).isFalse();
assertThat(actualFile.hasPullRequest()).isFalse();
}
use of org.sonarqube.ws.Hotspots.Component in project sonarqube by SonarSource.
the class SearchActionTest method returns_pullRequest_field_of_components_of_pullRequest.
@Test
public void returns_pullRequest_field_of_components_of_pullRequest() {
ComponentDto project = dbTester.components().insertPublicProject();
ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST));
userSessionRule.registerComponents(project, pullRequest);
indexPermissions();
ComponentDto directory = dbTester.components().insertComponent(newDirectory(pullRequest, "donut/acme"));
ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
IssueDto fileHotspot = insertHotspot(pullRequest, file, rule);
IssueDto dirHotspot = insertHotspot(pullRequest, directory, rule);
IssueDto projectHotspot = insertHotspot(pullRequest, pullRequest, rule);
indexIssues();
SearchWsResponse response = newRequest(pullRequest).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(fileHotspot.getKey(), dirHotspot.getKey(), projectHotspot.getKey());
assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project.getKey(), directory.getKey(), file.getKey());
Map<String, Component> componentByKey = response.getComponentsList().stream().collect(uniqueIndex(Component::getKey));
Component actualProject = componentByKey.get(project.getKey());
assertThat(actualProject.hasBranch()).isFalse();
assertThat(actualProject.getPullRequest()).isEqualTo(pullRequest.getPullRequest());
Component actualDirectory = componentByKey.get(directory.getKey());
assertThat(actualDirectory.hasBranch()).isFalse();
assertThat(actualDirectory.getPullRequest()).isEqualTo(pullRequest.getPullRequest());
Component actualFile = componentByKey.get(file.getKey());
assertThat(actualFile.hasBranch()).isFalse();
assertThat(actualFile.getPullRequest()).isEqualTo(pullRequest.getPullRequest());
}
use of org.sonarqube.ws.Hotspots.Component 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.Component 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.Component in project sonarqube by SonarSource.
the class SearchActionTest method returns_branch_field_of_components_of_branch.
@Test
public void returns_branch_field_of_components_of_branch() {
ComponentDto project = dbTester.components().insertPublicProject();
ComponentDto branch = dbTester.components().insertProjectBranch(project);
userSessionRule.registerComponents(project, branch);
indexPermissions();
ComponentDto directory = dbTester.components().insertComponent(newDirectory(branch, "donut/acme"));
ComponentDto file = dbTester.components().insertComponent(newFileDto(branch));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
IssueDto fileHotspot = insertHotspot(branch, file, rule);
IssueDto dirHotspot = insertHotspot(branch, directory, rule);
IssueDto projectHotspot = insertHotspot(branch, branch, rule);
indexIssues();
SearchWsResponse response = newRequest(branch).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(fileHotspot.getKey(), dirHotspot.getKey(), projectHotspot.getKey());
assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project.getKey(), directory.getKey(), file.getKey());
Map<String, Component> componentByKey = response.getComponentsList().stream().collect(uniqueIndex(Component::getKey));
Component actualProject = componentByKey.get(project.getKey());
assertThat(actualProject.getBranch()).isEqualTo(branch.getBranch());
assertThat(actualProject.hasPullRequest()).isFalse();
Component actualDirectory = componentByKey.get(directory.getKey());
assertThat(actualDirectory.getBranch()).isEqualTo(branch.getBranch());
assertThat(actualDirectory.hasPullRequest()).isFalse();
Component actualFile = componentByKey.get(file.getKey());
assertThat(actualFile.getBranch()).isEqualTo(branch.getBranch());
assertThat(actualFile.hasPullRequest()).isFalse();
}
Aggregations