Search in sources :

Example 6 with UserChange

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

the class IssuesChangesNotificationBuilderTest method UserChange_not_equal.

@Test
@UseDataProvider("userData")
public void UserChange_not_equal(Object object) {
    long now = System2.INSTANCE.now();
    String uuid_1 = "uuid-1";
    String login_1 = "login-1";
    String name_1 = "name-1";
    UserChange userChange1 = new UserChange(now, new User(uuid_1, login_1, name_1));
    assertThat(userChange1).isNotEqualTo(object);
}
Also used : UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 7 with UserChange

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

the class IssuesChangesNotificationBuilderTest method UserChange_isAuthorLogin.

@Test
public void UserChange_isAuthorLogin() {
    long now = System2.INSTANCE.now();
    String uuid = "uuid-1";
    String login = "login-1";
    String name = "name-1";
    UserChange userChange = new UserChange(now, new User(uuid, login, name));
    assertThat(userChange.isAuthorLogin("other-login")).isFalse();
    assertThat(userChange.isAuthorLogin("login-1")).isTrue();
}
Also used : UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) Test(org.junit.Test)

Example 8 with UserChange

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

the class IssuesChangesNotificationBuilderTest method UserChange_equals.

@Test
public void UserChange_equals() {
    long now = System2.INSTANCE.now();
    String uuid_1 = "uuid-1";
    String login_1 = "login-1";
    String name_1 = "name-1";
    UserChange userChange1 = new UserChange(now, new User(uuid_1, login_1, name_1));
    UserChange userChange2 = new UserChange(now, new User(uuid_1, login_1, name_1));
    assertThat(userChange1).isEqualTo(userChange2).isEqualTo(userChange1);
}
Also used : UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) Test(org.junit.Test)

Example 9 with UserChange

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange 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 10 with UserChange

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

the class FpOrWontFixEmailTemplate method format.

@Override
@CheckForNull
public EmailMessage format(Notification notif) {
    if (!(notif instanceof FPOrWontFixNotification)) {
        return null;
    }
    FPOrWontFixNotification notification = (FPOrWontFixNotification) notif;
    EmailMessage emailMessage = new EmailMessage().setMessageId(getMessageId(notification.getResolution())).setSubject(buildSubject(notification)).setHtmlMessage(buildMessage(notification));
    if (notification.getChange() instanceof UserChange) {
        User user = ((UserChange) notification.getChange()).getUser();
        emailMessage.setFrom(user.getName().orElse(user.getLogin()));
    }
    return emailMessage;
}
Also used : UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) CheckForNull(javax.annotation.CheckForNull)

Aggregations

UserChange (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange)40 Test (org.junit.Test)35 ChangedIssue (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue)27 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)21 Random (java.util.Random)21 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)20 Mockito.mock (org.mockito.Mockito.mock)20 Project (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project)20 User (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User)19 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)18 List (java.util.List)17 Set (java.util.Set)17 AnalysisChange (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange)17 ImmutableSet (com.google.common.collect.ImmutableSet)16 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)16 Collectors.toSet (java.util.stream.Collectors.toSet)16 IntStream (java.util.stream.IntStream)16 Stream (java.util.stream.Stream)16 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)16 RunWith (org.junit.runner.RunWith)16