Search in sources :

Example 61 with ChangedIssue

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.

the class ChangesOnMyIssueNotificationHandlerTest method deliver_ignores_issues_which_assignee_is_the_changeAuthor.

@Test
@UseDataProvider("userOrAnalysisChange")
public void deliver_ignores_issues_which_assignee_is_the_changeAuthor(Change userOrAnalysisChange) {
    when(emailNotificationChannel.isActivated()).thenReturn(true);
    Project project1 = newProject();
    Project project2 = newProject();
    User assignee1 = newUser("assignee_1");
    User assignee2 = newUser("assignee_2");
    Set<ChangedIssue> assignee1Issues = IntStream.range(0, 10).mapToObj(i -> newChangedIssue("1_issue_key_" + i, assignee1, project1)).collect(toSet());
    Set<ChangedIssue> assignee2Issues = IntStream.range(0, 10).mapToObj(i -> newChangedIssue("2_issue_key_" + i, assignee2, project2)).collect(toSet());
    UserChange assignee2Change1 = new UserChange(new Random().nextLong(), assignee2);
    Set<IssuesChangesNotification> notifications = Stream.of(// notification from assignee1 with issues from assignee1 only
    new IssuesChangesNotificationBuilder(assignee1Issues.stream().limit(4).collect(toSet()), new UserChange(new Random().nextLong(), assignee1)), // notification from assignee2 with issues from assignee1 and assignee2
    new IssuesChangesNotificationBuilder(Stream.concat(assignee1Issues.stream().skip(4).limit(2), assignee2Issues.stream().limit(4)).collect(toSet()), assignee2Change1), // notification from assignee2 with issues from assignee2 only
    new IssuesChangesNotificationBuilder(assignee2Issues.stream().skip(4).limit(3).collect(toSet()), new UserChange(new Random().nextLong(), assignee2)), // notification from other change with issues from assignee1 and assignee2)
    new IssuesChangesNotificationBuilder(Stream.concat(assignee1Issues.stream().skip(6), assignee2Issues.stream().skip(7)).collect(toSet()), userOrAnalysisChange)).map(t -> serializer.serialize(t)).collect(toSet());
    when(notificationManager.findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, project1.getKey(), ImmutableSet.of(assignee1.getLogin()), ALL_MUST_HAVE_ROLE_USER)).thenReturn(ImmutableSet.of(emailRecipientOf(assignee1.getLogin())));
    when(notificationManager.findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, project2.getKey(), ImmutableSet.of(assignee2.getLogin()), ALL_MUST_HAVE_ROLE_USER)).thenReturn(ImmutableSet.of(emailRecipientOf(assignee2.getLogin())));
    int deliveredCount = new Random().nextInt(100);
    when(emailNotificationChannel.deliverAll(anySet())).thenReturn(deliveredCount);
    int deliver = underTest.deliver(notifications);
    assertThat(deliver).isEqualTo(deliveredCount);
    verify(notificationManager).findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, project1.getKey(), ImmutableSet.of(assignee1.getLogin()), ALL_MUST_HAVE_ROLE_USER);
    verify(notificationManager).findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, project2.getKey(), ImmutableSet.of(assignee2.getLogin()), ALL_MUST_HAVE_ROLE_USER);
    verifyNoMoreInteractions(notificationManager);
    verify(emailNotificationChannel).isActivated();
    verify(emailNotificationChannel).deliverAll(emailDeliveryRequestSetCaptor.capture());
    verifyNoMoreInteractions(emailNotificationChannel);
    Set<EmailDeliveryRequest> emailDeliveryRequests = emailDeliveryRequestSetCaptor.getValue();
    assertThat(emailDeliveryRequests).hasSize(3);
    ListMultimap<String, EmailDeliveryRequest> emailDeliveryRequestByEmail = emailDeliveryRequests.stream().collect(index(EmailDeliveryRequest::getRecipientEmail));
    List<EmailDeliveryRequest> assignee1Requests = emailDeliveryRequestByEmail.get(emailOf(assignee1.getLogin()));
    assertThat(assignee1Requests).hasSize(2).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChange).containsOnly(userOrAnalysisChange, assignee2Change1);
    assertThat(assignee1Requests).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChangedIssues).containsOnly(assignee1Issues.stream().skip(4).limit(2).collect(unorderedIndex(t -> project1, t -> t)), assignee1Issues.stream().skip(6).collect(unorderedIndex(t -> project1, t -> t)));
    List<EmailDeliveryRequest> assignee2Requests = emailDeliveryRequestByEmail.get(emailOf(assignee2.getLogin()));
    assertThat(assignee2Requests).hasSize(1).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChange).containsOnly(userOrAnalysisChange);
    assertThat(assignee2Requests).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChangedIssues).containsOnly(assignee2Issues.stream().skip(7).collect(unorderedIndex(t -> project2, t -> t)));
}
Also used : IntStream(java.util.stream.IntStream) 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) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ArgumentCaptor(org.mockito.ArgumentCaptor) EmailDeliveryRequest(org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest) MoreCollectors.index(org.sonar.core.util.stream.MoreCollectors.index) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) NotificationManager(org.sonar.server.notification.NotificationManager) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) MoreCollectors.unorderedIndex(org.sonar.core.util.stream.MoreCollectors.unorderedIndex) 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.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) 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) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Mockito(org.mockito.Mockito) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) List(java.util.List) Stream(java.util.stream.Stream) 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) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) 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)

Example 62 with ChangedIssue

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.

the class FpOrWontFixEmailTemplateTest method formats_returns_html_message_for_multiple_hotspots_of_same_rule_on_same_project_on_master.

@Test
@UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange")
public void formats_returns_html_message_for_multiple_hotspots_of_same_rule_on_same_project_on_master(Change change, FpOrWontFix fpOrWontFix) {
    Project project = newProject("1");
    String ruleName = randomAlphabetic(8);
    String host = randomAlphabetic(15);
    Rule rule = newSecurityHotspotRule(ruleName);
    List<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(i -> newChangedIssue("issue_" + i, project, rule)).collect(toList());
    when(emailSettings.getServerBaseURL()).thenReturn(host);
    EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix));
    String expectedHref = host + "/project/issues?id=" + project.getKey() + "&issues=" + changedIssues.stream().map(ChangedIssue::getKey).collect(joining("%2C"));
    String expectedLinkText = "See all " + changedIssues.size() + " hotspots";
    HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project.getProjectName()).hasList("Rule " + ruleName + " - " + expectedLinkText).withLink(expectedLinkText, expectedHref).hasParagraph().hasParagraph().noMoreBlock();
}
Also used : IntStream(java.util.stream.IntStream) HtmlFragmentAssert(org.sonar.test.html.HtmlFragmentAssert) I18n(org.sonar.core.i18n.I18n) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule) RuleType(org.sonar.api.rules.RuleType) FpOrWontFix(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix) EmailSettings(org.sonar.api.config.EmailSettings) Locale(java.util.Locale) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) SECURITY_HOTSPOT(org.sonar.api.rules.RuleType.SECURITY_HOTSPOT) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) 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) Notification(org.sonar.api.notifications.Notification) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) Collectors.joining(java.util.stream.Collectors.joining) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) WONT_FIX(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.WONT_FIX) Stream(java.util.stream.Stream) RuleKey(org.sonar.api.rule.RuleKey) Change(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change) IssuesChangesNotificationBuilderTesting.randomRuleTypeHotspotExcluded(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.randomRuleTypeHotspotExcluded) FP(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.FP) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) Random(java.util.Random) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 63 with ChangedIssue

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.

the class FpOrWontFixEmailTemplateTest method formats_returns_html_message_with_projects_ordered_by_name.

@Test
@UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange")
public void formats_returns_html_message_with_projects_ordered_by_name(Change change, FpOrWontFix fpOrWontFix) {
    Project project1 = newProject("1");
    Project project1Branch1 = newBranch("1", "a");
    Project project1Branch2 = newBranch("1", "b");
    Project project2 = newProject("B");
    Project project2Branch1 = newBranch("B", "a");
    Project project3 = newProject("C");
    String host = randomAlphabetic(15);
    List<ChangedIssue> changedIssues = Stream.of(project1, project1Branch1, project1Branch2, project2, project2Branch1, project3).map(project -> newChangedIssue("issue_" + project.getUuid(), project, newRandomNotAHotspotRule(randomAlphabetic(2)))).collect(toList());
    Collections.shuffle(changedIssues);
    when(emailSettings.getServerBaseURL()).thenReturn(host);
    EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix));
    HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project1.getProjectName()).hasList().hasParagraph(project1Branch1.getProjectName() + ", " + project1Branch1.getBranchName().get()).hasList().hasParagraph(project1Branch2.getProjectName() + ", " + project1Branch2.getBranchName().get()).hasList().hasParagraph(project2.getProjectName()).hasList().hasParagraph(project2Branch1.getProjectName() + ", " + project2Branch1.getBranchName().get()).hasList().hasParagraph(project3.getProjectName()).hasList().hasParagraph().hasParagraph().noMoreBlock();
}
Also used : IntStream(java.util.stream.IntStream) HtmlFragmentAssert(org.sonar.test.html.HtmlFragmentAssert) I18n(org.sonar.core.i18n.I18n) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule) RuleType(org.sonar.api.rules.RuleType) FpOrWontFix(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix) EmailSettings(org.sonar.api.config.EmailSettings) Locale(java.util.Locale) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) SECURITY_HOTSPOT(org.sonar.api.rules.RuleType.SECURITY_HOTSPOT) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) 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) Notification(org.sonar.api.notifications.Notification) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) Collectors.joining(java.util.stream.Collectors.joining) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) WONT_FIX(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.WONT_FIX) Stream(java.util.stream.Stream) RuleKey(org.sonar.api.rule.RuleKey) Change(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change) IssuesChangesNotificationBuilderTesting.randomRuleTypeHotspotExcluded(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.randomRuleTypeHotspotExcluded) FP(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.FP) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 64 with ChangedIssue

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.

the class FpOrWontFixEmailTemplateTest method formats_returns_html_message_for_single_issue_on_master.

@Test
@UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange")
public void formats_returns_html_message_for_single_issue_on_master(Change change, FpOrWontFix fpOrWontFix) {
    Project project = newProject("1");
    String ruleName = randomAlphabetic(8);
    String host = randomAlphabetic(15);
    ChangedIssue changedIssue = newChangedIssue("key", project, ruleName, randomRuleTypeHotspotExcluded());
    when(emailSettings.getServerBaseURL()).thenReturn(host);
    EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssue), fpOrWontFix));
    HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project.getProjectName()).hasList("Rule " + ruleName + " - See the single issue").withLink("See the single issue", host + "/project/issues?id=" + project.getKey() + "&issues=" + changedIssue.getKey() + "&open=" + changedIssue.getKey()).hasParagraph().hasParagraph().noMoreBlock();
}
Also used : Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 65 with ChangedIssue

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.

the class FpOrWontFixEmailTemplateTest method formats_returns_html_message_with_multiple_links_by_rule_of_groups_of_up_to_40_issues.

@Test
@UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange")
public void formats_returns_html_message_with_multiple_links_by_rule_of_groups_of_up_to_40_issues(Change change, FpOrWontFix fpOrWontFix) {
    Project project1 = newProject("1");
    Project project2 = newProject("V");
    Project project2Branch = newBranch("V", "AB");
    Rule rule1 = newRandomNotAHotspotRule("1");
    Rule rule2 = newRandomNotAHotspotRule("a");
    String host = randomAlphabetic(15);
    List<ChangedIssue> changedIssues = Stream.of(IntStream.range(0, 39).mapToObj(i -> newChangedIssue("39_" + i, project1, rule1)), IntStream.range(0, 40).mapToObj(i -> newChangedIssue("40_" + i, project1, rule2)), IntStream.range(0, 81).mapToObj(i -> newChangedIssue("1-40_41-80_1_" + i, project2, rule2)), IntStream.range(0, 6).mapToObj(i -> newChangedIssue("6_" + i, project2Branch, rule1))).flatMap(t -> t).collect(toList());
    Collections.shuffle(changedIssues);
    when(emailSettings.getServerBaseURL()).thenReturn(host);
    EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix));
    HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project1.getProjectName()).hasList().withItemTexts("Rule " + rule1.getName() + " - See all 39 issues", "Rule " + rule2.getName() + " - See all 40 issues").withLink("See all 39 issues", host + "/project/issues?id=" + project1.getKey() + "&issues=" + IntStream.range(0, 39).mapToObj(i -> "39_" + i).sorted().collect(joining("%2C"))).withLink("See all 40 issues", host + "/project/issues?id=" + project1.getKey() + "&issues=" + IntStream.range(0, 40).mapToObj(i -> "40_" + i).sorted().collect(joining("%2C"))).hasParagraph(project2.getProjectName()).hasList("Rule " + rule2.getName() + " - See issues 1-40 41-80 81").withLink("1-40", host + "/project/issues?id=" + project2.getKey() + "&issues=" + IntStream.range(0, 81).mapToObj(i -> "1-40_41-80_1_" + i).sorted().limit(40).collect(joining("%2C"))).withLink("41-80", host + "/project/issues?id=" + project2.getKey() + "&issues=" + IntStream.range(0, 81).mapToObj(i -> "1-40_41-80_1_" + i).sorted().skip(40).limit(40).collect(joining("%2C"))).withLink("81", host + "/project/issues?id=" + project2.getKey() + "&issues=" + "1-40_41-80_1_9" + "&open=" + "1-40_41-80_1_9").hasParagraph(project2Branch.getProjectName() + ", " + project2Branch.getBranchName().get()).hasList("Rule " + rule1.getName() + " - See all 6 issues").withLink("See all 6 issues", host + "/project/issues?id=" + project2Branch.getKey() + "&branch=" + project2Branch.getBranchName().get() + "&issues=" + IntStream.range(0, 6).mapToObj(i -> "6_" + i).sorted().collect(joining("%2C"))).hasParagraph().hasParagraph().noMoreBlock();
}
Also used : IntStream(java.util.stream.IntStream) HtmlFragmentAssert(org.sonar.test.html.HtmlFragmentAssert) I18n(org.sonar.core.i18n.I18n) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule) RuleType(org.sonar.api.rules.RuleType) FpOrWontFix(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix) EmailSettings(org.sonar.api.config.EmailSettings) Locale(java.util.Locale) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) SECURITY_HOTSPOT(org.sonar.api.rules.RuleType.SECURITY_HOTSPOT) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) 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) Notification(org.sonar.api.notifications.Notification) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) Collectors.joining(java.util.stream.Collectors.joining) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) WONT_FIX(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.WONT_FIX) Stream(java.util.stream.Stream) RuleKey(org.sonar.api.rule.RuleKey) Change(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change) IssuesChangesNotificationBuilderTesting.randomRuleTypeHotspotExcluded(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.randomRuleTypeHotspotExcluded) FP(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.FP) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

ChangedIssue (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue)71 Test (org.junit.Test)65 Project (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project)54 UserChange (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange)47 Random (java.util.Random)45 AnalysisChange (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange)44 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)43 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)43 Mockito.mock (org.mockito.Mockito.mock)40 IntStream (java.util.stream.IntStream)39 Rule (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule)39 ImmutableSet (com.google.common.collect.ImmutableSet)38 Collections (java.util.Collections)38 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)37 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)37 List (java.util.List)37 RunWith (org.junit.runner.RunWith)37 IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule (org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule)37 Set (java.util.Set)36 Stream (java.util.stream.Stream)36