use of org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE in project sonarqube by SonarSource.
the class IssueWorkflowTest method automatically_reopen_closed_issue_to_previous_resolution_of_closing_the_issue_if_most_recent_of_all_resolution_changes.
@Test
@UseDataProvider("allResolutionsBeforeClosing")
public void automatically_reopen_closed_issue_to_previous_resolution_of_closing_the_issue_if_most_recent_of_all_resolution_changes(String resolutionBeforeClosed) {
String randomPreviousStatus = ALL_STATUSES_LEADING_TO_CLOSED[new Random().nextInt(ALL_STATUSES_LEADING_TO_CLOSED.length)];
DefaultIssue[] issues = Arrays.stream(SUPPORTED_RESOLUTIONS_FOR_UNCLOSING).map(resolution -> {
DefaultIssue issue = newClosedIssue(resolution);
Date now = new Date();
addResolutionChange(issue, addDays(now, -60), null, RESOLUTION_FALSE_POSITIVE);
addResolutionChange(issue, addDays(now, -10), RESOLUTION_FALSE_POSITIVE, resolutionBeforeClosed);
addResolutionAndStatusChange(issue, now, randomPreviousStatus, STATUS_CLOSED, resolutionBeforeClosed, resolution);
return issue;
}).toArray(DefaultIssue[]::new);
Date now = new Date();
underTest.start();
Arrays.stream(issues).forEach(issue -> {
underTest.doAutomaticTransition(issue, IssueChangeContext.createScan(now));
assertThat(issue.status()).isEqualTo(randomPreviousStatus);
assertThat(issue.resolution()).isEqualTo(resolutionBeforeClosed);
assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND));
assertThat(issue.closeDate()).isNull();
assertThat(issue.isChanged()).isTrue();
});
}
use of org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE in project sonarqube by SonarSource.
the class FPOrWontFixNotificationHandlerTest method deliver_send_a_separated_email_request_for_FPs_and_Wont_Fix_issues.
@Test
@UseDataProvider("oneOrMoreProjectCounts")
public void deliver_send_a_separated_email_request_for_FPs_and_Wont_Fix_issues(int projectCount) {
Set<Project> projects = IntStream.range(0, projectCount).mapToObj(i -> newProject("prk_key_" + i)).collect(toSet());
User subscriber1 = newUser("subscriber1");
User changeAuthor = newUser("changeAuthor");
Set<ChangedIssue> fpIssues = projects.stream().flatMap(project -> randomIssues(t -> t.setProject(project).setNewResolution(RESOLUTION_FALSE_POSITIVE).setAssignee(subscriber1))).collect(toSet());
Set<ChangedIssue> wontFixIssues = projects.stream().flatMap(project -> randomIssues(t -> t.setProject(project).setNewResolution(RESOLUTION_WONT_FIX).setAssignee(subscriber1))).collect(toSet());
UserChange userChange = newUserChange(changeAuthor);
IssuesChangesNotificationBuilder fpAndWontFixNotifications = new IssuesChangesNotificationBuilder(Stream.concat(fpIssues.stream(), wontFixIssues.stream()).collect(toSet()), userChange);
when(emailNotificationChannel.isActivated()).thenReturn(true);
projects.forEach(project -> when(notificationManager.findSubscribedEmailRecipients(DO_NOT_FIX_ISSUE_CHANGE_DISPATCHER_KEY, project.getKey(), ALL_MUST_HAVE_ROLE_USER)).thenReturn(singleton(emailRecipientOf(subscriber1.getLogin()))));
int deliveredCount = new Random().nextInt(200);
when(emailNotificationChannel.deliverAll(anySet())).thenReturn(deliveredCount).thenThrow(new IllegalStateException("deliver should be called only once"));
Set<IssuesChangesNotification> notifications = singleton(serializer.serialize(fpAndWontFixNotifications));
reset(serializer);
int deliver = underTest.deliver(notifications);
assertThat(deliver).isEqualTo(deliveredCount);
projects.forEach(project -> verify(notificationManager).findSubscribedEmailRecipients(DO_NOT_FIX_ISSUE_CHANGE_DISPATCHER_KEY, project.getKey(), ALL_MUST_HAVE_ROLE_USER));
verifyNoMoreInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
ArgumentCaptor<Set<EmailDeliveryRequest>> captor = ArgumentCaptor.forClass(requestSetType);
verify(emailNotificationChannel).deliverAll(captor.capture());
verifyNoMoreInteractions(emailNotificationChannel);
ListMultimap<String, EmailDeliveryRequest> requestsByRecipientEmail = captor.getValue().stream().collect(index(EmailDeliveryRequest::getRecipientEmail));
assertThat(requestsByRecipientEmail.get(emailOf(subscriber1.getLogin()))).containsOnly(new EmailDeliveryRequest(emailOf(subscriber1.getLogin()), new FPOrWontFixNotification(userChange, wontFixIssues, FpOrWontFix.WONT_FIX)), new EmailDeliveryRequest(emailOf(subscriber1.getLogin()), new FPOrWontFixNotification(userChange, fpIssues, FpOrWontFix.FP)));
}
Aggregations