Search in sources :

Example 1 with AnalysisChange

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

the class ChangesOnMyIssuesEmailTemplateTest method format_set_html_message_with_footer_when_security_hotspot_change_from_analysis.

@Test
@UseDataProvider("securityHotspotsStatuses")
public void format_set_html_message_with_footer_when_security_hotspot_change_from_analysis(String securityHotspotStatus) {
    AnalysisChange analysisChange = newAnalysisChange();
    format_set_html_message_with_footer(analysisChange, securityHotspotStatus, c -> c.hasParagraph().hasList(), SECURITY_HOTSPOT);
}
Also used : IssuesChangesNotificationBuilderTesting.newAnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newAnalysisChange) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 2 with AnalysisChange

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

the class ChangesOnMyIssuesEmailTemplateTest method formats_fails_with_ISE_if_change_from_Analysis_and_no_issue.

@Test
public void formats_fails_with_ISE_if_change_from_Analysis_and_no_issue() {
    AnalysisChange analysisChange = newAnalysisChange();
    assertThatThrownBy(() -> underTest.format(new ChangesOnMyIssuesNotification(analysisChange, Collections.emptySet()))).isInstanceOf(IllegalStateException.class).hasMessage("changedIssues can't be empty");
}
Also used : IssuesChangesNotificationBuilderTesting.newAnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newAnalysisChange) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Test(org.junit.Test)

Example 3 with AnalysisChange

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

the class ChangesOnMyIssuesEmailTemplateTest method format_set_html_message_with_footer_when_issue_change_from_analysis.

@Test
@UseDataProvider("issueStatuses")
public void format_set_html_message_with_footer_when_issue_change_from_analysis(String issueStatus) {
    AnalysisChange analysisChange = newAnalysisChange();
    format_set_html_message_with_footer(analysisChange, issueStatus, c -> c.hasParagraph().hasList(), randomRuleTypeHotspotExcluded());
}
Also used : IssuesChangesNotificationBuilderTesting.newAnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newAnalysisChange) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with AnalysisChange

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

the class ChangesOnMyIssuesEmailTemplateTest method formats_returns_html_message_with_multiple_links_by_rule_of_groups_of_up_to_40_issues_when_analysis_change.

@Test
public void formats_returns_html_message_with_multiple_links_by_rule_of_groups_of_up_to_40_issues_when_analysis_change() {
    Project project1 = newProject("1");
    Rule rule1 = newRandomNotAHotspotRule("1");
    Rule rule2 = newRandomNotAHotspotRule("a");
    String host = randomAlphabetic(15);
    String issueStatusClosed = STATUS_CLOSED;
    String otherIssueStatus = STATUS_RESOLVED;
    List<ChangedIssue> changedIssues = Stream.of(IntStream.range(0, 39).mapToObj(i -> newChangedIssue("39_" + i, issueStatusClosed, project1, rule1)), IntStream.range(0, 40).mapToObj(i -> newChangedIssue("40_" + i, issueStatusClosed, project1, rule2)), IntStream.range(0, 81).mapToObj(i -> newChangedIssue("1-40_41-80_1_" + i, otherIssueStatus, project1, rule2)), IntStream.range(0, 6).mapToObj(i -> newChangedIssue("6_" + i, otherIssueStatus, project1, rule1))).flatMap(t -> t).collect(toList());
    Collections.shuffle(changedIssues);
    AnalysisChange analysisChange = newAnalysisChange();
    when(emailSettings.getServerBaseURL()).thenReturn(host);
    EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.copyOf(changedIssues)));
    HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(// skip title based on status
    "Closed issues:").hasList("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("Open issues:").hasList("Rule " + rule2.getName() + " - See issues 1-40 41-80 81", "Rule " + rule1.getName() + " - See all 6 issues").withLink("1-40", host + "/project/issues?id=" + project1.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=" + project1.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=" + project1.getKey() + "&issues=" + "1-40_41-80_1_9" + "&open=" + "1-40_41-80_1_9").withLink("See all 6 issues", host + "/project/issues?id=" + project1.getKey() + "&issues=" + IntStream.range(0, 6).mapToObj(i -> "6_" + i).sorted().collect(joining("%2C"))).hasParagraph().hasParagraph().noMoreBlock();
}
Also used : Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) STATUS_CLOSED(org.sonar.api.issue.Issue.STATUS_CLOSED) IssuesChangesNotificationBuilderTesting.newUserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newUserChange) Locale(java.util.Locale) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) IssuesChangesNotificationBuilderTesting.newProject(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newProject) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) Notification(org.sonar.api.notifications.Notification) Set(java.util.Set) Sets(org.elasticsearch.common.util.set.Sets) Collectors.joining(java.util.stream.Collectors.joining) STATUS_TO_REVIEW(org.sonar.api.issue.Issue.STATUS_TO_REVIEW) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) STATUS_CONFIRMED(org.sonar.api.issue.Issue.STATUS_CONFIRMED) List(java.util.List) Stream(java.util.stream.Stream) STATUS_REVIEWED(org.sonar.api.issue.Issue.STATUS_REVIEWED) HtmlParagraphAssert(org.sonar.test.html.HtmlParagraphAssert) Change(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change) IssuesChangesNotificationBuilderTesting.newAnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newAnalysisChange) IssuesChangesNotificationBuilderTesting.newRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRule) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) HtmlFragmentAssert(org.sonar.test.html.HtmlFragmentAssert) HtmlListAssert(org.sonar.test.html.HtmlListAssert) I18n(org.sonar.core.i18n.I18n) STATUS_OPEN(org.sonar.api.issue.Issue.STATUS_OPEN) RunWith(org.junit.runner.RunWith) STATUS_RESOLVED(org.sonar.api.issue.Issue.STATUS_RESOLVED) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Function(java.util.function.Function) IssuesChangesNotificationBuilderTesting.newBranch(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newBranch) IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule) RuleType(org.sonar.api.rules.RuleType) EmailSettings(org.sonar.api.config.EmailSettings) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SECURITY_HOTSPOT(org.sonar.api.rules.RuleType.SECURITY_HOTSPOT) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) STATUS_REOPENED(org.sonar.api.issue.Issue.STATUS_REOPENED) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) IssuesChangesNotificationBuilderTesting.newChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newChangedIssue) 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) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Collectors.toList(java.util.stream.Collectors.toList) IssuesChangesNotificationBuilderTesting.randomRuleTypeHotspotExcluded(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.randomRuleTypeHotspotExcluded) Collections(java.util.Collections) IssuesChangesNotificationBuilderTesting.newProject(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newProject) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) IssuesChangesNotificationBuilderTesting.newChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newChangedIssue) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) IssuesChangesNotificationBuilderTesting.newRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRule) IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) IssuesChangesNotificationBuilderTesting.newAnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newAnalysisChange) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Test(org.junit.Test)

Example 5 with AnalysisChange

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

the class IssuesChangesNotificationBuilderTest method fail_if_changed_issues_empty.

@Test
public void fail_if_changed_issues_empty() {
    AnalysisChange analysisChange = new AnalysisChange(1_000_000_000L);
    Set<ChangedIssue> issues = Collections.emptySet();
    assertThatThrownBy(() -> new IssuesChangesNotificationBuilder(issues, analysisChange)).isInstanceOf(IllegalArgumentException.class).hasMessage("issues can't be empty");
}
Also used : ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Test(org.junit.Test)

Aggregations

AnalysisChange (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange)31 Test (org.junit.Test)28 ChangedIssue (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue)19 Random (java.util.Random)17 Project (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project)16 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)15 IssuesChangesNotificationBuilderTesting.newAnalysisChange (org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newAnalysisChange)15 Set (java.util.Set)14 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)13 Collections (java.util.Collections)13 IntStream (java.util.stream.IntStream)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule)13 ImmutableSet (com.google.common.collect.ImmutableSet)12 IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule (org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule)12 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)11 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)11 RunWith (org.junit.runner.RunWith)11 Notification (org.sonar.api.notifications.Notification)11 RuleType (org.sonar.api.rules.RuleType)11