]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9442 Add a suject in email sent to quality profiles admin
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 23 Jun 2017 07:06:41 +0000 (09:06 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 29 Jun 2017 15:23:19 +0000 (17:23 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplate.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplateTest.java
tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java

index 69025332316c7e3804a21e58372a28b4f30909a1..e30294c2ada278bb0c2df14dbd44c2a91abb86fb 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.qualityprofile;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
 import java.util.Comparator;
 import java.util.Date;
 import org.sonar.api.notifications.Notification;
@@ -29,6 +28,7 @@ import org.sonar.api.platform.Server;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 import org.sonar.plugins.emailnotifications.api.EmailTemplate;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.sonar.api.utils.DateUtils.formatDate;
 import static org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.Profile;
 import static org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.parse;
@@ -88,13 +88,13 @@ public class BuiltInQualityProfilesNotificationTemplate extends EmailTemplate {
     // And finally return the email that will be sent
     return new EmailMessage()
       .setMessageId(BUILT_IN_QUALITY_PROFILES)
-      .setSubject("empty")
+      .setSubject("Built-in quality profiles have been updated")
       .setMessage(message.toString());
   }
 
   public String encode(String text) {
     try {
-      return URLEncoder.encode(text, StandardCharsets.UTF_8.name());
+      return URLEncoder.encode(text, UTF_8.name());
     } catch (UnsupportedEncodingException e) {
       throw new IllegalStateException(String.format("Cannot encode %s", text), e);
     }
index 89f023a1645c2fa6cd6b6ed08bcdc71fd501e2ea..176a22aa7e747aa45aa076fbbdd00b4af4bfd286 100644 (file)
@@ -44,6 +44,24 @@ public class BuiltInQualityProfilesNotificationTemplateTest {
     when(server.getPublicRootUrl()).thenReturn("http://" + randomAlphanumeric(10));
   }
 
+  @Test
+  public void notification_contains_a_subject() {
+    String profileName = newProfileName();
+    String languageKey = newLanguageKey();
+    String languageName = newLanguageName();
+    BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
+      .addProfile(Profile.newBuilder()
+        .setProfileName(profileName)
+        .setLanguageKey(languageKey)
+        .setLanguageName(languageName)
+        .setNewRules(2)
+        .build());
+
+    EmailMessage emailMessage = underTest.format(notification.serialize());
+
+    assertThat(emailMessage.getSubject()).isEqualTo("Built-in quality profiles have been updated");
+  }
+
   @Test
   public void notification_contains_list_of_new_rules() {
     String profileName = newProfileName();
index a0d8d90d36821c8b7e8aed92aa0f16ad4fbc8ae4..d11f252ddad3fc368bf5326f388ce5051ef8e839 100644 (file)
@@ -131,6 +131,10 @@ public class BuiltInQualityProfilesNotificationTest {
       .extracting(this::getMimeMessage)
       .extracting(this::getAllRecipients)
       .containsOnly("<" + profileAdmin1.getEmail() + ">", "<" + profileAdmin2.getEmail() + ">");
+    assertThat(messages)
+      .extracting(this::getMimeMessage)
+      .extracting(this::getSubject)
+      .containsOnly("[SONARQUBE] Built-in quality profiles have been updated");
     String url = orchestrator.getServer().getUrl();
     assertThat(messages.get(0).getMimeMessage().getContent().toString())
       .containsSequence(
@@ -196,6 +200,14 @@ public class BuiltInQualityProfilesNotificationTest {
     }
   }
 
+  private String getSubject(MimeMessage mimeMessage) {
+    try {
+      return mimeMessage.getSubject();
+    } catch (MessagingException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
   private static void waitUntilAllNotificationsAreDelivered(int expectedNumberOfEmails, int pollNumber, int pollMillis) throws InterruptedException {
     for (int i = 0; i < pollNumber; i++) {
       if (smtpServer.getMessages().size() == expectedNumberOfEmails) {