Search in sources :

Example 11 with ChangedIssue

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

the class IssuesChangesNotificationBuilderTest method ChangedIssue_not_equal.

@Test
@UseDataProvider("changedIssueData")
public void ChangedIssue_not_equal(Object object) {
    ChangedIssue changedIssue = new ChangedIssue.Builder("key").setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")).setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()).setNewStatus("status").setNewResolution("resolution").setAssignee(new User("uuid", "login", "name")).build();
    assertThat(changedIssue).isNotEqualTo(object);
}
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) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 12 with ChangedIssue

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

the class IssuesChangesNotificationBuilderTest method ChangedIssue_equals.

@Test
public void ChangedIssue_equals() {
    ChangedIssue changedIssue1 = new ChangedIssue.Builder("key").setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")).setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()).setNewStatus("status").setNewResolution("resolution").setAssignee(new User("uuid", "login", "name")).build();
    ChangedIssue changedIssue2 = new ChangedIssue.Builder("key").setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")).setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()).setNewStatus("status").setNewResolution("resolution").setAssignee(new User("uuid", "login", "name")).build();
    assertThat(changedIssue1).isEqualTo(changedIssue2).isEqualTo(changedIssue1);
}
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) Test(org.junit.Test)

Example 13 with ChangedIssue

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

the class ChangesOnMyIssuesEmailTemplateTest method formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_master_when_user_change.

@Test
public void formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_master_when_user_change() {
    Project project = newProject("1");
    String ruleName = randomAlphabetic(8);
    String host = randomAlphabetic(15);
    Rule rule = newRule(ruleName, randomRuleTypeHotspotExcluded());
    List<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(i -> newChangedIssue("issue_" + i, randomValidStatus(), project, rule)).collect(toList());
    UserChange userChange = newUserChange();
    when(emailSettings.getServerBaseURL()).thenReturn(host);
    EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(userChange, ImmutableSet.copyOf(changedIssues)));
    String expectedHref = host + "/project/issues?id=" + project.getKey() + "&issues=" + changedIssues.stream().map(ChangedIssue::getKey).collect(joining("%2C"));
    String expectedLinkText = "See all " + changedIssues.size() + " issues";
    HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project.getProjectName()).hasList("Rule " + ruleName + " - " + expectedLinkText).withLink(expectedLinkText, expectedHref).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) Random(java.util.Random) 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) Test(org.junit.Test)

Example 14 with ChangedIssue

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

the class ChangesOnMyIssuesEmailTemplateTest method formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_branch_when_analysis_change.

@Test
public void formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_branch_when_analysis_change() {
    String branchName = randomAlphabetic(19);
    Project project = newBranch("1", branchName);
    String ruleName = randomAlphabetic(8);
    String host = randomAlphabetic(15);
    Rule rule = newRule(ruleName, randomRuleTypeHotspotExcluded());
    String status = randomValidStatus();
    List<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(i -> newChangedIssue("issue_" + i, status, project, rule)).collect(toList());
    AnalysisChange analysisChange = newAnalysisChange();
    when(emailSettings.getServerBaseURL()).thenReturn(host);
    EmailMessage emailMessage = underTest.format(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.copyOf(changedIssues)));
    String expectedHref = host + "/project/issues?id=" + project.getKey() + "&branch=" + branchName + "&issues=" + changedIssues.stream().map(ChangedIssue::getKey).collect(joining("%2C"));
    String expectedLinkText = "See all " + changedIssues.size() + " issues";
    HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph().hasList("Rule " + ruleName + " - " + expectedLinkText).withLink(expectedLinkText, expectedHref).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) Random(java.util.Random) 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 15 with ChangedIssue

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

the class FPOrWontFixNotificationTest method hashcode_is_based_on_issues_change_and_resolution.

@Test
public void hashcode_is_based_on_issues_change_and_resolution() {
    Rule rule = newRandomNotAHotspotRule("rule_name");
    Project project = new Project.Builder("prj_uuid").setKey("prj_key").setProjectName("prj_name").build();
    Set<ChangedIssue> changedIssues = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(i -> new ChangedIssue.Builder("key_" + i).setNewStatus("status").setRule(rule).setProject(project).build()).collect(Collectors.toSet());
    AnalysisChange change = new AnalysisChange(12);
    User user = new User("uuid", "login", null);
    FPOrWontFixNotification underTest = new FPOrWontFixNotification(change, changedIssues, WONT_FIX);
    assertThat(underTest.hashCode()).isEqualTo(new FPOrWontFixNotification(change, changedIssues, WONT_FIX).hashCode()).isEqualTo(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), WONT_FIX).hashCode()).isNotEqualTo(new Object().hashCode()).isNotEqualTo(new FPOrWontFixNotification(change, Collections.emptySet(), WONT_FIX).hashCode()).isNotEqualTo(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssues.iterator().next()), WONT_FIX).hashCode()).isNotEqualTo(new FPOrWontFixNotification(new AnalysisChange(14), changedIssues, WONT_FIX).hashCode()).isNotEqualTo(new FPOrWontFixNotification(new IssuesChangesNotificationBuilder.UserChange(12, user), changedIssues, WONT_FIX).hashCode()).isNotEqualTo(new FPOrWontFixNotification(change, changedIssues, FP)).hashCode();
}
Also used : IntStream(java.util.stream.IntStream) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Random(java.util.Random) Test(org.junit.Test) Collectors(java.util.stream.Collectors) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) WONT_FIX(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.WONT_FIX) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) FP(org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.FP) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Collections(java.util.Collections) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) Random(java.util.Random) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) Test(org.junit.Test)

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