@Test public void update_issue() { DefaultIssue issue = db.issues().insertIssue(i -> i.setSeverity(MAJOR)).toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid"); issueFieldsSetter.setSeverity(issue, BLOCKER, context); underTest.saveIssue(db.getSession(), issue, context, null); IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issue.key()).get(); assertThat(issueReloaded.getSeverity()).isEqualTo(BLOCKER); }
@Test public void verify_notification() { UserDto assignee = db.users().insertUser(); RuleDto rule = db.rules().insertRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file) .setType(randomTypeExceptHotspot)) .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.saveIssue(db.getSession(), issue, context, "increase severity"); verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture()); IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue(); assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key()); assertThat(issueChangeNotification.getFieldValue("old.severity")).isEqualTo(MAJOR); assertThat(issueChangeNotification.getFieldValue("new.severity")).isEqualTo(BLOCKER); assertThat(issueChangeNotification.getFieldValue("componentKey")).isEqualTo(file.getDbKey()); assertThat(issueChangeNotification.getFieldValue("componentName")).isEqualTo(file.longName()); assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.getDbKey()); assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.name()); assertThat(issueChangeNotification.getFieldValue("ruleName")).isEqualTo(rule.getName()); assertThat(issueChangeNotification.getFieldValue("changeAuthor")).isEqualTo(changeAuthor.getLogin()); assertThat(issueChangeNotification.getFieldValue("comment")).isEqualTo("increase severity"); assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(assignee.getLogin()); }
@Test public void verify_notification_on_branch() { RuleDto rule = db.rules().insertRule(); ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); ComponentDto file = db.components().insertComponent(newFileDto(branch)); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), branch, file) .setType(randomTypeExceptHotspot)).setSeverity(MAJOR).toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid"); issueFieldsSetter.setSeverity(issue, BLOCKER, context); underTest.saveIssue(db.getSession(), issue, context, "increase severity"); verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture()); IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue(); assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key()); assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.getDbKey()); assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.name()); assertThat(issueChangeNotification.getFieldValue("branch")).isEqualTo(branch.getBranch()); }
@Test public void verify_notification_when_issue_is_linked_on_removed_rule() { RuleDto rule = db.rules().insertRule(r -> r.setStatus(RuleStatus.REMOVED)); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file) .setType(randomTypeExceptHotspot)).setSeverity(MAJOR).toDefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid"); issueFieldsSetter.setSeverity(issue, BLOCKER, context); underTest.saveIssue(db.getSession(), issue, context, null); verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture()); assertThat(notificationArgumentCaptor.getValue().getFieldValue("ruleName")).isNull(); }
@Test public void verify_notification_when_assignee_has_changed() { UserDto oldAssignee = db.users().insertUser(); RuleDto rule = db.rules().insertRule(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file) .setType(randomTypeExceptHotspot)) .setAssigneeUuid(oldAssignee.getUuid()) .toDefaultIssue(); UserDto changeAuthor = db.users().insertUser(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid()); UserDto newAssignee = db.users().insertUser(); issueFieldsSetter.assign(issue, newAssignee, context); underTest.saveIssue(db.getSession(), issue, context, null); verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture()); IssueChangeNotification issueChangeNotification = notificationArgumentCaptor.getValue(); assertThat(issueChangeNotification.getFieldValue("key")).isEqualTo(issue.key()); assertThat(issueChangeNotification.getFieldValue("new.assignee")).isEqualTo(newAssignee.getName()); assertThat(issueChangeNotification.getFieldValue("old.assignee")).isNull(); assertThat(issueChangeNotification.getFieldValue("assignee")).isEqualTo(newAssignee.getLogin()); }
@Test public void verify_no_notification_on_hotspot() { UserDto assignee = db.users().insertUser(); RuleDto rule = db.rules().insertRule(); ComponentDto project = db.components().insertPrivateProject(); 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.saveIssue(db.getSession(), issue, context, "increase severity"); verify(notificationManager, never()).scheduleForSending(any()); }