aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-06-23 09:06:41 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-06-29 17:23:19 +0200
commite58f19cefe30d06275e45ab44e6d01a69a794676 (patch)
treef3957e7e0b6a82fa1f93dfcb821902b16262c9c1
parent4546ffeb44cb56bcf909e4506f255c354eba3e86 (diff)
downloadsonarqube-e58f19cefe30d06275e45ab44e6d01a69a794676.tar.gz
sonarqube-e58f19cefe30d06275e45ab44e6d01a69a794676.zip
SONAR-9442 Add a suject in email sent to quality profiles admin
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplate.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplateTest.java18
-rw-r--r--tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java12
3 files changed, 33 insertions, 3 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplate.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplate.java
index 69025332316..e30294c2ada 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplate.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplate.java
@@ -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);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplateTest.java
index 89f023a1645..176a22aa7e7 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplateTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplateTest.java
@@ -45,6 +45,24 @@ public class BuiltInQualityProfilesNotificationTemplateTest {
}
@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();
String languageKey = newLanguageKey();
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java b/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java
index a0d8d90d368..d11f252ddad 100644
--- a/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java
@@ -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) {