use of org.sonar.api.rule.Severity.BLOCKER in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_notification_on_branch.
@Test
public void verify_notification_on_branch() {
RuleDefinitionDto rule = db.rules().insertIssueRule();
ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(BRANCH));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
DefaultIssue issue = db.issues().insertIssue(rule, branch, file, t -> t.setSeverity(MAJOR)).toDefaultIssue();
UserDto changeAuthor = db.users().insertUser();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
IssuesChangesNotification issueChangeNotification = notificationArgumentCaptor.getValue();
IssuesChangesNotificationBuilder builder = issuesChangesSerializer.from(issueChangeNotification);
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changedIssue = builder.getIssues().iterator().next();
assertThat(changedIssue.getKey()).isEqualTo(issue.key());
assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status());
assertThat(changedIssue.getNewResolution()).isEmpty();
assertThat(changedIssue.getAssignee()).isEmpty();
assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
assertThat(changedIssue.getProject()).isEqualTo(projectBranchOf(db, branch));
assertThat(builder.getChange()).isEqualTo(new UserChange(issue.updateDate().getTime(), userOf(changeAuthor)));
}
use of org.sonar.api.rule.Severity.BLOCKER in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_no_notification_on_pr.
@Test
public void verify_no_notification_on_pr() {
RuleDefinitionDto rule = db.rules().insertIssueRule();
ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
DefaultIssue issue = db.issues().insertIssue(rule, branch, file, t -> t.setSeverity(MAJOR)).toDefaultIssue();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
verifyZeroInteractions(notificationManager);
}
use of org.sonar.api.rule.Severity.BLOCKER in project sonarqube by SonarSource.
the class SearchActionTest method facet_filtering_when_searching_for_inactive_rules.
/**
* When the user searches for inactive rules (for example for to "activate more"), then
* only rules of the quality profiles' language are relevant
*/
@Test
public void facet_filtering_when_searching_for_inactive_rules() {
QProfileDto profile = db.qualityProfiles().insert(q -> q.setLanguage("language1"));
// on same language, not activated => match
RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage(profile.getLanguage()).setRepositoryKey("repositoryKey1").setSystemTags(new HashSet<>(singletonList("tag1"))).setSeverity("CRITICAL").setStatus(RuleStatus.BETA).setType(RuleType.CODE_SMELL));
// on same language, activated => no match
RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage(profile.getLanguage()).setRepositoryKey("repositoryKey2").setSystemTags(new HashSet<>(singletonList("tag2"))).setSeverity("MAJOR").setStatus(RuleStatus.DEPRECATED).setType(RuleType.VULNERABILITY));
RuleActivation activation = RuleActivation.create(rule2.getUuid(), null, null);
qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
// on other language, not activated => no match
RuleDefinitionDto rule3 = db.rules().insert(r -> r.setLanguage("language3").setRepositoryKey("repositoryKey3").setSystemTags(new HashSet<>(singletonList("tag3"))).setSeverity("BLOCKER").setStatus(RuleStatus.READY).setType(RuleType.BUG));
indexRules();
indexActiveRules();
SearchResponse result = ws.newRequest().setParam("facets", "languages,repositories,tags,severities,statuses,types").setParam("activation", "false").setParam("qprofile", profile.getKee()).executeProtobuf(SearchResponse.class);
assertThat(result.getRulesList()).extracting(Rule::getKey).containsExactlyInAnyOrder(rule1.getKey().toString());
assertThat(result.getFacets().getFacetsList().stream().filter(f -> "languages".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet languages").containsExactlyInAnyOrder(tuple(rule1.getLanguage(), 1L), // known limitation: irrelevant languages are shown in this case (SONAR-9683)
tuple(rule3.getLanguage(), 1L));
assertThat(result.getFacets().getFacetsList().stream().filter(f -> "tags".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet tags").containsExactlyInAnyOrder(tuple(rule1.getSystemTags().iterator().next(), 1L));
assertThat(result.getFacets().getFacetsList().stream().filter(f -> "repositories".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet repositories").containsExactlyInAnyOrder(tuple(rule1.getRepositoryKey(), 1L));
assertThat(result.getFacets().getFacetsList().stream().filter(f -> "severities".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet severities").containsExactlyInAnyOrder(tuple("BLOCKER", /* rule2 */
0L), tuple("CRITICAL", /* rule1 */
1L), tuple("MAJOR", 0L), tuple("MINOR", 0L), tuple("INFO", 0L));
assertThat(result.getFacets().getFacetsList().stream().filter(f -> "statuses".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet statuses").containsExactlyInAnyOrder(tuple("READY", /* rule2 */
0L), tuple("BETA", /* rule1 */
1L), tuple("DEPRECATED", 0L));
assertThat(result.getFacets().getFacetsList().stream().filter(f -> "types".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet types").containsExactlyInAnyOrder(tuple("BUG", /* rule2 */
0L), tuple("CODE_SMELL", /* rule1 */
1L), tuple("VULNERABILITY", 0L), tuple("SECURITY_HOTSPOT", 0L));
}
use of org.sonar.api.rule.Severity.BLOCKER in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_notification_without_resolution.
@Test
public void verify_notification_without_resolution() {
UserDto assignee = db.users().insertUser();
RuleDefinitionDto rule = db.rules().insertIssueRule();
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
DefaultIssue issue = db.issues().insertIssue(rule, project, file, t -> t.setSeverity(MAJOR).setAssigneeUuid(assignee.getUuid())).toDefaultIssue();
UserDto changeAuthor = db.users().insertUser();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
IssuesChangesNotification issueChangeNotification = notificationArgumentCaptor.getValue();
IssuesChangesNotificationBuilder builder = issuesChangesSerializer.from(issueChangeNotification);
assertThat(builder.getIssues()).hasSize(1);
ChangedIssue changedIssue = builder.getIssues().iterator().next();
assertThat(changedIssue.getKey()).isEqualTo(issue.key());
assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status());
assertThat(changedIssue.getNewResolution()).isEmpty();
assertThat(changedIssue.getAssignee()).contains(userOf(assignee));
assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
assertThat(changedIssue.getProject()).isEqualTo(projectOf(project));
assertThat(builder.getChange()).isEqualTo(new UserChange(issue.updateDate().getTime(), userOf(changeAuthor)));
}
use of org.sonar.api.rule.Severity.BLOCKER in project sonarqube by SonarSource.
the class IssueUpdaterTest method verify_notification_when_issue_is_linked_on_removed_rule.
@Test
public void verify_notification_when_issue_is_linked_on_removed_rule() {
RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setStatus(RuleStatus.REMOVED));
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
DefaultIssue issue = db.issues().insertIssue(rule, project, file, t -> t.setSeverity(MAJOR)).toDefaultIssue();
IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
issueFieldsSetter.setSeverity(issue, BLOCKER, context);
underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
verifyZeroInteractions(notificationManager);
}
Aggregations