Search in sources :

Example 26 with EmailMessage

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

the class QGChangeEmailTemplateTest method shouldFormatAlertWithSeveralMessages.

@Test
public void shouldFormatAlertWithSeveralMessages() {
    Notification notification = createNotification("Failed", "violations > 4, coverage < 75%", "ERROR", "false");
    EmailMessage message = template.format(notification);
    assertThat(message.getMessageId(), is("alerts/45"));
    assertThat(message.getSubject(), is("Quality gate status changed on \"Foo\""));
    assertThat(message.getMessage(), is("" + "Project: Foo\n" + "Version: V1-SNAP\n" + "Quality gate status: Failed\n" + "\n" + "Quality gate thresholds:\n" + "  - violations > 4\n" + "  - coverage < 75%\n" + "\n" + "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo"));
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 27 with EmailMessage

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

the class QGChangeEmailTemplateTest method shouldFormatBackToGreenMessageOnBranch.

@Test
public void shouldFormatBackToGreenMessageOnBranch() {
    Notification notification = createNotification("Passed", "", "OK", "false").setFieldValue("branch", "feature");
    EmailMessage message = template.format(notification);
    assertThat(message.getMessageId(), is("alerts/45"));
    assertThat(message.getSubject(), is("\"Foo (feature)\" is back to green"));
    assertThat(message.getMessage(), is("" + "Project: Foo\n" + "Branch: feature\n" + "Version: V1-SNAP\n" + "Quality gate status: Passed\n" + "\n" + "\n" + "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo&branch=feature"));
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 28 with EmailMessage

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

the class BuiltInQPChangeNotificationTemplate method format.

@Override
@CheckForNull
public EmailMessage format(Notification notification) {
    if (!BuiltInQPChangeNotification.TYPE.equals(notification.getType())) {
        return null;
    }
    BuiltInQPChangeNotificationBuilder profilesNotification = parse(notification);
    StringBuilder message = new StringBuilder("The following built-in profiles have been updated:\n\n");
    profilesNotification.getProfiles().stream().sorted(Comparator.comparing(Profile::getLanguageName).thenComparing(Profile::getProfileName)).forEach(profile -> {
        message.append("\"").append(profile.getProfileName()).append("\" - ").append(profile.getLanguageName()).append(": ").append(server.getPublicRootUrl()).append("/profiles/changelog?language=").append(profile.getLanguageKey()).append("&name=").append(encode(profile.getProfileName())).append("&since=").append(formatDate(new Date(profile.getStartDate()))).append("&to=").append(formatDate(new Date(profile.getEndDate()))).append("\n");
        int newRules = profile.getNewRules();
        if (newRules > 0) {
            message.append(" ").append(newRules).append(" new rule").append(plural(newRules)).append('\n');
        }
        int updatedRules = profile.getUpdatedRules();
        if (updatedRules > 0) {
            message.append(" ").append(updatedRules).append(" rule").append(updatedRules > 1 ? "s have been updated" : " has been updated").append("\n");
        }
        int removedRules = profile.getRemovedRules();
        if (removedRules > 0) {
            message.append(" ").append(removedRules).append(" rule").append(plural(removedRules)).append(" removed\n");
        }
        message.append("\n");
    });
    message.append("This is a good time to review your quality profiles and update them to benefit from the latest evolutions: ");
    message.append(server.getPublicRootUrl()).append("/profiles");
    // And finally return the email that will be sent
    return new EmailMessage().setMessageId(BuiltInQPChangeNotification.TYPE).setSubject("Built-in quality profiles have been updated").setPlainTextMessage(message.toString());
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Profile(org.sonar.server.qualityprofile.builtin.BuiltInQPChangeNotificationBuilder.Profile) DateUtils.formatDate(org.sonar.api.utils.DateUtils.formatDate) Date(java.util.Date) CheckForNull(javax.annotation.CheckForNull)

Example 29 with EmailMessage

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

the class BuiltInQPChangeNotificationTemplateTest method notification_contains_a_subject.

@Test
public void notification_contains_a_subject() {
    String profileName = newProfileName();
    String languageKey = newLanguageKey();
    String languageName = newLanguageName();
    BuiltInQPChangeNotificationBuilder notification = new BuiltInQPChangeNotificationBuilder().addProfile(Profile.newBuilder().setProfileName(profileName).setLanguageKey(languageKey).setLanguageName(languageName).setNewRules(2).build());
    EmailMessage emailMessage = underTest.format(notification.build());
    assertThat(emailMessage.getSubject()).isEqualTo("Built-in quality profiles have been updated");
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Test(org.junit.Test)

Example 30 with EmailMessage

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

the class BuiltInQPChangeNotificationTemplateTest method notification_contains_count_of_updated_rules.

@Test
public void notification_contains_count_of_updated_rules() {
    String profileName = newProfileName();
    String languageKey = newLanguageKey();
    String languageName = newLanguageName();
    BuiltInQPChangeNotificationBuilder notification = new BuiltInQPChangeNotificationBuilder().addProfile(Profile.newBuilder().setProfileName(profileName).setLanguageKey(languageKey).setLanguageName(languageName).setUpdatedRules(2).build());
    EmailMessage emailMessage = underTest.format(notification.build());
    assertMessage(emailMessage, "\n 2 rules have been updated\n");
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Test(org.junit.Test)

Aggregations

EmailMessage (org.sonar.server.issue.notification.EmailMessage)32 Test (org.junit.Test)27 Notification (org.sonar.api.notifications.Notification)13 CheckForNull (javax.annotation.CheckForNull)3 MimeMessage (javax.mail.internet.MimeMessage)3 WiserMessage (org.subethamail.wiser.WiserMessage)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Date (java.util.Date)2 EmailException (org.apache.commons.mail.EmailException)2 DateUtils.formatDate (org.sonar.api.utils.DateUtils.formatDate)2 EmailTemplate (org.sonar.server.issue.notification.EmailTemplate)2 EmailDeliveryRequest (org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1