use of org.sonar.server.issue.index.IssueIndexSyncProgressChecker in project sonarqube by SonarSource.
the class SearchEventsActionTest method events.
@Test
public void events() {
userSession.logIn().setRoot();
when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project);
SnapshotDto projectAnalysis = insertAnalysis(project, 1_500_000_000_000L);
db.events().insertEvent(newQualityGateEvent(projectAnalysis).setDate(projectAnalysis.getCreatedAt()).setName("Passed"));
insertIssue(project, projectAnalysis);
insertIssue(project, projectAnalysis);
SnapshotDto branchAnalysis = insertAnalysis(branch, 1_501_000_000_000L);
db.events().insertEvent(newQualityGateEvent(branchAnalysis).setDate(branchAnalysis.getCreatedAt()).setName("Failed"));
insertIssue(branch, branchAnalysis);
issueIndexer.indexAllIssues();
SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(1_499_000_000_000L)).executeProtobuf(SearchEventsWsResponse.class);
assertThat(result.getEventsList()).extracting(Event::getCategory, Event::getProject, Event::getMessage).containsOnly(tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' changed to 'Passed'", project.name())), tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' on branch '%s' changed to 'Failed'", project.name(), branch.getBranch())), tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s'", project.name())), tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on branch '%s'", project.name(), branch.getBranch())));
verify(issueIndexSyncProgressChecker).checkIfAnyComponentsNeedIssueSync(any(), argThat(arg -> arg.contains(project.getKey())));
}
use of org.sonar.server.issue.index.IssueIndexSyncProgressChecker in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspot_of_branch_or_pullRequest.
@Test
public void returns_hotspot_of_branch_or_pullRequest() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto branch = dbTester.components().insertProjectBranch(project);
ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST));
ComponentDto fileProject = dbTester.components().insertComponent(newFileDto(project));
ComponentDto fileBranch = dbTester.components().insertComponent(newFileDto(branch));
ComponentDto filePR = dbTester.components().insertComponent(newFileDto(pullRequest));
IssueDto[] hotspotProject = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(project, fileProject, rule);
}).toArray(IssueDto[]::new);
IssueDto[] hotspotBranch = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(branch, fileBranch, rule);
}).toArray(IssueDto[]::new);
IssueDto[] hotspotPR = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(pullRequest, filePR, rule);
}).toArray(IssueDto[]::new);
indexIssues();
SearchWsResponse responseProject = newRequest(project).executeProtobuf(SearchWsResponse.class);
SearchWsResponse responseBranch = newRequest(branch).executeProtobuf(SearchWsResponse.class);
SearchWsResponse responsePR = newRequest(pullRequest).executeProtobuf(SearchWsResponse.class);
assertThat(responseProject.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(Arrays.stream(hotspotProject).map(IssueDto::getKey).toArray(String[]::new));
assertThat(responseBranch.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(Arrays.stream(hotspotBranch).map(IssueDto::getKey).toArray(String[]::new));
assertThat(responsePR.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(Arrays.stream(hotspotPR).map(IssueDto::getKey).toArray(String[]::new));
verify(issueIndexSyncProgressChecker, times(3)).checkIfComponentNeedIssueSync(any(), eq(project.getDbKey()));
}
use of org.sonar.server.issue.index.IssueIndexSyncProgressChecker 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