import javax.annotation.Nullable;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
-import org.sonar.api.rules.RuleType;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueChangeContext;
import org.sonar.core.util.stream.MoreCollectors;
private IssueDto doSaveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context,
Optional<RuleDefinitionDto> rule, ComponentDto project, BranchDto branchDto) {
IssueDto issueDto = issueStorage.save(session, singletonList(issue)).iterator().next();
- if (issue.type() == RuleType.SECURITY_HOTSPOT
+ if (
// since this method is called after an update of the issue, date should never be null
- || issue.updateDate() == null
+ issue.updateDate() == null
// name of rule is displayed in notification, rule must therefor be present
|| !rule.isPresent()
// notification are not supported on PRs and short lived branches
import static org.apache.commons.lang.math.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.sonar.api.issue.Issue.RESOLUTION_FIXED;
assertThat(builder.getChange()).isEqualTo(new UserChange(issue.updateDate().getTime(), userOf(changeAuthor)));
}
- @Test
- public void verify_no_notification_on_hotspot() {
- UserDto assignee = db.users().insertUser();
- RuleDto rule = db.rules().insertRule();
- ComponentDto project = db.components().insertMainBranch();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
- DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file)
- .setType(RuleType.SECURITY_HOTSPOT))
- .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, never()).scheduleForSending(any());
- }
-
@Test
public void verify_notification_on_long_branch() {
RuleDto rule = db.rules().insertRule();
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
import static org.sonar.api.rules.RuleType.CODE_SMELL;
-import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT;
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.server.tester.UserSessionRule.standalone;
verify(notificationManager).scheduleForSending(any(IssuesChangesNotification.class));
}
- @Test
- public void do_not_send_notification_on_security_hotspot() {
- IssueDto issue = db.issues().insertIssue(
- issueDto -> issueDto
- .setAssigneeUuid(null)
- .setType(SECURITY_HOTSPOT));
- setUserWithBrowsePermission(issue);
- UserDto arthur = insertUser("arthur");
-
- ws.newRequest()
- .setParam("issue", issue.getKey())
- .setParam("assignee", arthur.getLogin())
- .execute();
-
- verifyZeroInteractions(notificationManager);
- }
-
@Test
public void fail_when_assignee_does_not_exist() {
IssueDto issue = newIssueWithBrowsePermission();