public IssueChangeNotification setComponent(String componentKey, String componentName) { setFieldValue("componentName", componentName); setFieldValue("componentKey", componentKey); return this; }
public IssueChangeNotification setProject(String projectKey, String projectName, @Nullable String branch, @Nullable String pullRequest) { setFieldValue(FIELD_PROJECT_NAME, projectName); setFieldValue(FIELD_PROJECT_KEY, projectKey); if (branch != null) { setFieldValue(FIELD_BRANCH, branch); } if (pullRequest != null) { setFieldValue(FIELD_PULL_REQUEST, pullRequest); } return this; }
public IssueChangeNotification setRuleName(@Nullable String s) { if (s != null) { setFieldValue("ruleName", s); } return this; }
public IssueChangeNotification setComment(@Nullable String s) { if (s != null) { setFieldValue("comment", s); } return this; }
public IssueChangeNotification setAssignee(@Nullable UserDto assignee) { if (assignee != null) { setFieldValue("assignee", assignee.getLogin()); } return this; } }
public IssueChangeNotification setChangeAuthor(@Nullable UserDto author) { if (author == null) { return this; } setFieldValue("changeAuthor", author.getLogin()); return this; }
public IssueChangeNotification setIssue(DefaultIssue issue) { setFieldValue("key", issue.key()); setFieldValue("message", issue.message()); FieldDiffs currentChange = issue.currentChange(); if (currentChange != null) { for (Map.Entry<String, FieldDiffs.Diff> entry : currentChange.diffs().entrySet()) { String type = entry.getKey(); FieldDiffs.Diff diff = entry.getValue(); setFieldValue("old." + type, neverEmptySerializableToString(diff.oldValue())); setFieldValue("new." + type, neverEmptySerializableToString(diff.newValue())); } } return this; }
@Test public void should_dispatch_to_assignee() { Multimap<String, NotificationChannel> recipients = HashMultimap.create(); recipients.put("simon", emailChannel); recipients.put("freddy", twitterChannel); recipients.put("godin", twitterChannel); when(notifications.findSubscribedRecipientsForDispatcher(underTest, "struts", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); Notification notification = new IssueChangeNotification() .setFieldValue("projectKey", "struts") .setFieldValue("changeAuthor", "olivier") .setFieldValue("assignee", "freddy"); underTest.performDispatch(notification, context); verify(context).addUser("freddy", twitterChannel); verify(context, never()).addUser("godin", twitterChannel); verifyNoMoreInteractions(context); }
@Test public void should_dispatch_to_subscribers() { Multimap<String, NotificationChannel> recipients = HashMultimap.create(); recipients.put("simon", emailChannel); recipients.put("freddy", twitterChannel); recipients.put("godin", twitterChannel); when(notifications.findSubscribedRecipientsForDispatcher(underTest, "struts", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); Notification fpNotif = new IssueChangeNotification() .setFieldValue("projectKey", "struts") .setFieldValue("changeAuthor", "godin") .setFieldValue("new.resolution", Issue.RESOLUTION_FALSE_POSITIVE) .setFieldValue("assignee", "freddy"); underTest.performDispatch(fpNotif, context); verify(context).addUser("simon", emailChannel); verify(context).addUser("freddy", twitterChannel); // do not notify the person who flagged the issue as false-positive verify(context, never()).addUser("godin", twitterChannel); verifyNoMoreInteractions(context); }
@Test public void should_not_dispatch_to_author_of_changes() { Multimap<String, NotificationChannel> recipients = HashMultimap.create(); recipients.put("simon", emailChannel); recipients.put("freddy", twitterChannel); recipients.put("godin", twitterChannel); when(notifications.findSubscribedRecipientsForDispatcher(underTest, "uuid1", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); // change author is the assignee underTest.performDispatch( new IssueChangeNotification() .setFieldValue("projectKey", "struts") .setFieldValue("projectUuid", "uuid1") .setFieldValue("changeAuthor", "simon") .setFieldValue("assignee", "simon"), context); // no change author underTest.performDispatch(new IssueChangeNotification().setFieldValue("projectKey", "struts") .setFieldValue("new.resolution", "FIXED"), context); verifyNoMoreInteractions(context); } }
/** * Only false positive and won't fix resolutions */ @Test public void ignore_other_resolutions() { Notification fixedNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts") .setFieldValue("changeAuthor", "godin") .setFieldValue("new.resolution", Issue.RESOLUTION_FIXED) .setFieldValue("assignee", "freddy"); underTest.performDispatch(fixedNotif, context); verifyZeroInteractions(context); } }
private static Notification generateNotification() { return new IssueChangeNotification() .setFieldValue("projectName", "Struts") .setFieldValue("projectKey", "org.apache:struts") .setFieldValue("componentName", "Action") .setFieldValue("componentKey", "org.apache.struts.Action") .setFieldValue("key", "ABCDE") .setFieldValue("ruleName", "Avoid Cycles") .setFieldValue("message", "Has 3 cycles"); } }
public IssueChangeNotification setComponent(String componentKey, String componentName) { setFieldValue("componentName", componentName); setFieldValue("componentKey", componentKey); return this; }
public IssueChangeNotification setProject(String projectKey, String projectName, @Nullable String branch, @Nullable String pullRequest) { setFieldValue(FIELD_PROJECT_NAME, projectName); setFieldValue(FIELD_PROJECT_KEY, projectKey); if (branch != null) { setFieldValue(FIELD_BRANCH, branch); } if (pullRequest != null) { setFieldValue(FIELD_PULL_REQUEST, pullRequest); } return this; }
public IssueChangeNotification setRuleName(@Nullable String s) { if (s != null) { setFieldValue("ruleName", s); } return this; }
public IssueChangeNotification setComment(@Nullable String s) { if (s != null) { setFieldValue("comment", s); } return this; }
public IssueChangeNotification setChangeAuthor(@Nullable UserDto author) { if (author == null) { return this; } setFieldValue("changeAuthor", author.getLogin()); return this; }
public IssueChangeNotification setAssignee(@Nullable UserDto assignee) { if (assignee != null) { setFieldValue("assignee", assignee.getLogin()); } return this; } }
public IssueChangeNotification setIssue(DefaultIssue issue) { setFieldValue("key", issue.key()); setFieldValue("message", issue.message()); FieldDiffs currentChange = issue.currentChange(); if (currentChange != null) { for (Map.Entry<String, FieldDiffs.Diff> entry : currentChange.diffs().entrySet()) { String type = entry.getKey(); FieldDiffs.Diff diff = entry.getValue(); setFieldValue("old." + type, neverEmptySerializableToString(diff.oldValue())); setFieldValue("new." + type, neverEmptySerializableToString(diff.newValue())); } } return this; }