Search in sources :

Example 1 with RESOLUTION_FALSE_POSITIVE

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();
    });
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) RESOLUTION_WONT_FIX(org.sonar.api.issue.Issue.RESOLUTION_WONT_FIX) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) STATUS_OPEN(org.sonar.api.issue.Issue.STATUS_OPEN) RunWith(org.junit.runner.RunWith) DateUtils.addDays(org.apache.commons.lang.time.DateUtils.addDays) STATUS_RESOLVED(org.sonar.api.issue.Issue.STATUS_RESOLVED) Random(java.util.Random) Collections2(com.google.common.collect.Collections2) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) STATUS_CLOSED(org.sonar.api.issue.Issue.STATUS_CLOSED) ArrayList(java.util.ArrayList) IssueFieldsSetter(org.sonar.server.issue.IssueFieldsSetter) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Calendar(java.util.Calendar) DateUtils(org.apache.commons.lang.time.DateUtils) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) RESOLUTION_FALSE_POSITIVE(org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE) Assert.fail(org.junit.Assert.fail) RESOLUTION_FIXED(org.sonar.api.issue.Issue.RESOLUTION_FIXED) Nullable(javax.annotation.Nullable) DefaultIssue(org.sonar.core.issue.DefaultIssue) STATUS_REOPENED(org.sonar.api.issue.Issue.STATUS_REOPENED) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Collection(java.util.Collection) Test(org.junit.Test) RESOLUTION_REMOVED(org.sonar.api.issue.Issue.RESOLUTION_REMOVED) STATUS_TO_REVIEW(org.sonar.api.issue.Issue.STATUS_TO_REVIEW) FieldDiffs(org.sonar.core.issue.FieldDiffs) STATUS_CONFIRMED(org.sonar.api.issue.Issue.STATUS_CONFIRMED) List(java.util.List) STATUS_REVIEWED(org.sonar.api.issue.Issue.STATUS_REVIEWED) DefaultTransitions(org.sonar.api.issue.DefaultTransitions) RuleKey(org.sonar.api.rule.RuleKey) Random(java.util.Random) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 2 with RESOLUTION_FALSE_POSITIVE

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)));
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) ALL_MUST_HAVE_ROLE_USER(org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER) ListMultimap(com.google.common.collect.ListMultimap) RESOLUTION_WONT_FIX(org.sonar.api.issue.Issue.RESOLUTION_WONT_FIX) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) Mockito.spy(org.mockito.Mockito.spy) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) FpOrWontFix(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix) ArgumentCaptor(org.mockito.ArgumentCaptor) EmailDeliveryRequest(org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest) MoreCollectors.index(org.sonar.core.util.stream.MoreCollectors.index) Collections.singleton(java.util.Collections.singleton) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) RESOLUTION_FALSE_POSITIVE(org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) Assert.fail(org.junit.Assert.fail) NotificationManager(org.sonar.server.notification.NotificationManager) IssuesChangesNotificationBuilderTesting.newProject(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newProject) Collectors.toSet(java.util.stream.Collectors.toSet) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Set(java.util.Set) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) PER_PROJECT_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Mockito(org.mockito.Mockito) Stream(java.util.stream.Stream) Issue(org.sonar.api.issue.Issue) GLOBAL_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.GLOBAL_NOTIFICATION) Change(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change) NotificationDispatcherMetadata(org.sonar.server.notification.NotificationDispatcherMetadata) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel) Mockito.reset(org.mockito.Mockito.reset) Mockito.mock(org.mockito.Mockito.mock) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) IssuesChangesNotificationBuilderTesting.newProject(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newProject) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) Random(java.util.Random) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) EmailDeliveryRequest(org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Random (java.util.Random)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assert.fail (org.junit.Assert.fail)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 RESOLUTION_FALSE_POSITIVE (org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE)2 RESOLUTION_WONT_FIX (org.sonar.api.issue.Issue.RESOLUTION_WONT_FIX)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Collections2 (com.google.common.collect.Collections2)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ListMultimap (com.google.common.collect.ListMultimap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Collections.singleton (java.util.Collections.singleton)1 Date (java.util.Date)1