Search in sources :

Example 51 with ChangedIssue

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

the class ChangesOnMyIssuesEmailTemplateTest method formats_returns_html_message_with_projects_ordered_by_name_when_user_change.

@Test
public void formats_returns_html_message_with_projects_ordered_by_name_when_user_change() {
    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(), randomValidStatus(), project, newRule(randomAlphabetic(2), randomRuleTypeHotspotExcluded()))).collect(toList());
    Collections.shuffle(changedIssues);
    UserChange userChange = newUserChange();
    when(emailSettings.getServerBaseURL()).thenReturn(host);
    EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(userChange, ImmutableSet.copyOf(changedIssues)));
    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 : 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) IssuesChangesNotificationBuilderTesting.newUserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newUserChange) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) IssuesChangesNotificationBuilderTesting.newChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newChangedIssue) Test(org.junit.Test)

Example 52 with ChangedIssue

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

the class ChangesOnMyIssuesEmailTemplateTest method format_set_html_message_with_header_dealing_with_plural_when_change_from_Analysis.

@Test
public void format_set_html_message_with_header_dealing_with_plural_when_change_from_Analysis() {
    Set<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(4)).mapToObj(i -> newChangedIssue(i + "", randomValidStatus(), newProject("prj_" + i), newRandomNotAHotspotRule("rule_" + i))).collect(toSet());
    AnalysisChange analysisChange = newAnalysisChange();
    EmailMessage singleIssueMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, changedIssues.stream().limit(1).collect(toSet())));
    EmailMessage multiIssueMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, changedIssues));
    HtmlFragmentAssert.assertThat(singleIssueMessage.getMessage()).hasParagraph("Hi,").hasParagraph("An analysis has updated an issue assigned to you:");
    HtmlFragmentAssert.assertThat(multiIssueMessage.getMessage()).hasParagraph("Hi,").hasParagraph("An analysis has updated issues assigned to you:");
}
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) Random(java.util.Random) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) IssuesChangesNotificationBuilderTesting.newChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newChangedIssue) IssuesChangesNotificationBuilderTesting.newAnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newAnalysisChange) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Test(org.junit.Test)

Example 53 with ChangedIssue

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

the class IssuesChangesNotificationBuilderTest method ChangedIssue_getters.

@Test
public void ChangedIssue_getters() {
    Project project = new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build();
    Rule rule = newRule("repository", "key", RuleType.CODE_SMELL, "name");
    User user = new User("uuid", "login", "name");
    ChangedIssue changedIssue = new ChangedIssue.Builder("key").setRule(rule).setProject(project).setNewStatus("status").setNewResolution("resolution").setAssignee(user).build();
    assertThat(changedIssue.getKey()).isEqualTo("key");
    assertThat(changedIssue.getNewStatus()).isEqualTo("status");
    assertThat(changedIssue.getAssignee()).hasValue(user);
    assertThat(changedIssue.getNewResolution()).hasValue("resolution");
    assertThat(changedIssue.getProject()).isEqualTo(project);
    assertThat(changedIssue.getRule()).isEqualTo(rule);
}
Also used : Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) Test(org.junit.Test)

Example 54 with ChangedIssue

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

the class ChangesOnMyIssuesNotificationTest method hashcode_is_based_on_change_and_issues.

@Test
public void hashcode_is_based_on_change_and_issues() {
    AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
    ChangedIssue changedIssue = IssuesChangesNotificationBuilderTesting.newChangedIssue("doo", IssuesChangesNotificationBuilderTesting.newProject("prj"), newRandomNotAHotspotRule("rul"));
    ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue));
    assertThat(underTest.hashCode()).isEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue)).hashCode()).isNotEqualTo(mock(Notification.class).hashCode()).isNotEqualTo(new ChangesOnMyIssuesNotification(new AnalysisChange(analysisChange.getDate() + 10), ImmutableSet.of(changedIssue)).hashCode()).isNotEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of())).hashCode();
}
Also used : Random(java.util.Random) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 55 with ChangedIssue

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

the class FPOrWontFixNotificationHandlerTest method randomIssues.

private static Stream<ChangedIssue> randomIssues(Consumer<ChangedIssue.Builder> consumer) {
    return IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> {
        ChangedIssue.Builder builder = new ChangedIssue.Builder("key_" + i).setAssignee(new User(randomAlphabetic(3), randomAlphabetic(4), randomAlphabetic(5))).setNewStatus(randomAlphabetic(12)).setNewResolution(randomAlphabetic(13)).setRule(newRandomNotAHotspotRule(randomAlphabetic(8))).setProject(new Project.Builder(randomAlphabetic(9)).setKey(randomAlphabetic(10)).setProjectName(randomAlphabetic(11)).build());
        consumer.accept(builder);
        return builder.build();
    });
}
Also used : User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) Random(java.util.Random) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue)

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