]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9442 Add profile links to the notification
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 22 Jun 2017 11:32:04 +0000 (13:32 +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/BuiltInQualityProfilesNotification.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationSender.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplate.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationSenderTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTemplateTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQualityProfilesNotificationTest.java
tests/src/test/java/org/sonarqube/tests/qualityProfile/BuiltInQualityProfilesNotificationTest.java

index 6609ae3d829faff69825a51621e42e1442fea859..fe2c0ddc6ebafcdd7db687027f27259c4c585b84 100644 (file)
@@ -36,7 +36,8 @@ public class BuiltInQualityProfilesNotification {
 
   private static final String NUMBER_OF_PROFILES = "numberOfProfiles";
   private static final String PROFILE_NAME = ".profileName";
-  private static final String LANGUAGE = ".language";
+  private static final String LANGUAGE_KEY = ".languageKey";
+  private static final String LANGUAGE_NAME = ".languageName";
   private static final String NEW_RULES = ".newRules";
   private static final String UPDATED_RULES = ".updatedRules";
   private static final String REMOVED_RULES = ".removedRules";
@@ -55,7 +56,8 @@ public class BuiltInQualityProfilesNotification {
     profiles.forEach(profile -> {
       int index = count.getAndIncrement();
       notification.setFieldValue(index + PROFILE_NAME, profile.getProfileName());
-      notification.setFieldValue(index + LANGUAGE, profile.getLanguage());
+      notification.setFieldValue(index + LANGUAGE_KEY, profile.getLanguageKey());
+      notification.setFieldValue(index + LANGUAGE_NAME, profile.getLanguageName());
       notification.setFieldValue(index + NEW_RULES, String.valueOf(profile.getNewRules()));
       notification.setFieldValue(index + UPDATED_RULES, String.valueOf(profile.getUpdatedRules()));
       notification.setFieldValue(index + REMOVED_RULES, String.valueOf(profile.getRemovedRules()));
@@ -71,9 +73,10 @@ public class BuiltInQualityProfilesNotification {
     checkState(numberOfProfilesText != null, "Could not read the built-in quality profile notification");
     Integer numberOfProfiles = Integer.valueOf(numberOfProfilesText);
     IntStream.rangeClosed(0, numberOfProfiles - 1)
-      .mapToObj(index -> Profile.newBuilder(
-        getNonNullFieldValue(notification, index + PROFILE_NAME),
-        getNonNullFieldValue(notification, index + LANGUAGE))
+      .mapToObj(index -> Profile.newBuilder()
+        .setProfileName(getNonNullFieldValue(notification, index + PROFILE_NAME))
+        .setLanguageKey(getNonNullFieldValue(notification, index + LANGUAGE_KEY))
+        .setLanguageName(getNonNullFieldValue(notification, index + LANGUAGE_NAME))
         .setNewRules(parseInt(getNonNullFieldValue(notification, index + NEW_RULES)))
         .setUpdatedRules(parseInt(getNonNullFieldValue(notification, index + UPDATED_RULES)))
         .setRemovedRules(parseInt(getNonNullFieldValue(notification, index + REMOVED_RULES)))
@@ -93,14 +96,16 @@ public class BuiltInQualityProfilesNotification {
 
   public static class Profile {
     private final String profileName;
-    private final String language;
+    private final String languageKey;
+    private final String languageName;
     private final int newRules;
     private final int updatedRules;
     private final int removedRules;
 
     public Profile(Builder builder) {
       this.profileName = builder.profileName;
-      this.language = builder.language;
+      this.languageKey = builder.languageKey;
+      this.languageName = builder.languageName;
       this.newRules = builder.newRules;
       this.updatedRules = builder.updatedRules;
       this.removedRules = builder.removedRules;
@@ -110,8 +115,12 @@ public class BuiltInQualityProfilesNotification {
       return profileName;
     }
 
-    public String getLanguage() {
-      return language;
+    public String getLanguageKey() {
+      return languageKey;
+    }
+
+    public String getLanguageName() {
+      return languageName;
     }
 
     public int getNewRules() {
@@ -126,20 +135,34 @@ public class BuiltInQualityProfilesNotification {
       return removedRules;
     }
 
-    public static Builder newBuilder(String profileName, String language) {
-      return new Builder(profileName, language);
+    public static Builder newBuilder() {
+      return new Builder();
     }
 
     public static class Builder {
-      private final String profileName;
-      private final String language;
+      private String profileName;
+      private String languageKey;
+      private String languageName;
       private int newRules;
       private int updatedRules;
       private int removedRules;
 
-      private Builder(String profileName, String language) {
+      private Builder() {
+      }
+
+      public Builder setLanguageKey(String languageKey) {
+        this.languageKey = requireNonNull(languageKey, "languageKEy should not be null");
+        return this;
+      }
+
+      public Builder setLanguageName(String languageName) {
+        this.languageName = requireNonNull(languageName, "languageName should not be null");
+        return this;
+      }
+
+      public Builder setProfileName(String profileName) {
         this.profileName = requireNonNull(profileName, "profileName should not be null");
-        this.language = requireNonNull(language, "language should not be null");
+        return this;
       }
 
       public Builder setNewRules(int newRules) {
index fee337a98320db8798a8c6d55fea992027b46a0d..9ed6c7c150a7c43ce0350251564bc5b046bc565b 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.qualityprofile;
 
 import com.google.common.collect.Multimap;
 import java.util.Collection;
+import org.sonar.api.resources.Language;
 import org.sonar.api.resources.Languages;
 import org.sonar.server.notification.NotificationManager;
 import org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.Profile;
@@ -47,12 +48,15 @@ public class BuiltInQualityProfilesNotificationSender {
     changedProfiles.keySet().stream()
       .map(changedProfile -> {
         String profileName = changedProfile.getName();
-        String languageName = languages.get(changedProfile.getLanguage()).getName();
+        Language language = languages.get(changedProfile.getLanguage());
         Collection<ActiveRuleChange> activeRuleChanges = changedProfiles.get(changedProfile);
         int newRules = (int) activeRuleChanges.stream().map(ActiveRuleChange::getType).filter(ACTIVATED::equals).count();
         int updatedRules = (int) activeRuleChanges.stream().map(ActiveRuleChange::getType).filter(UPDATED::equals).count();
         int removedRules = (int) activeRuleChanges.stream().map(ActiveRuleChange::getType).filter(DEACTIVATED::equals).count();
-        return Profile.newBuilder(profileName, languageName)
+        return Profile.newBuilder()
+          .setProfileName(profileName)
+          .setLanguageKey(language.getKey())
+          .setLanguageName(language.getName())
           .setNewRules(newRules)
           .setUpdatedRules(updatedRules)
           .setRemovedRules(removedRules)
index 82db0ca0b9ef92b79c8d6831b4c4ce2f65055a6e..d26f07fc8e03faea856cc9f798e8e51cf873be77 100644 (file)
  */
 package org.sonar.server.qualityprofile;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.Comparator;
 import org.sonar.api.notifications.Notification;
+import org.sonar.api.platform.Server;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 import org.sonar.plugins.emailnotifications.api.EmailTemplate;
-import org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.Profile;
 
+import static org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.Profile;
+import static org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.parse;
 import static org.sonar.server.qualityprofile.BuiltInQualityProfilesNotificationSender.BUILT_IN_QUALITY_PROFILES;
 
 public class BuiltInQualityProfilesNotificationTemplate extends EmailTemplate {
 
+  private final Server server;
+
+  public BuiltInQualityProfilesNotificationTemplate(Server server) {
+    this.server = server;
+  }
+
   @Override
   public EmailMessage format(Notification notification) {
     if (!BUILT_IN_QUALITY_PROFILES.equals(notification.getType())) {
       return null;
     }
 
-    BuiltInQualityProfilesNotification profilesNotification = BuiltInQualityProfilesNotification.parse(notification);
+    BuiltInQualityProfilesNotification profilesNotification = parse(notification);
 
     StringBuilder message = new StringBuilder("Built-in quality profiles have been updated:\n");
     profilesNotification.getProfiles().stream()
-      .sorted(Comparator.comparing(Profile::getLanguage).thenComparing(Profile::getProfileName))
+      .sorted(Comparator.comparing(Profile::getLanguageName).thenComparing(Profile::getProfileName))
       .forEach(profile -> {
         message.append("\"")
-          .append(profile.getProfileName()).append("\" - ")
-          .append(profile.getLanguage()).append("\n");
+          .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("\n");
         int newRules = profile.getNewRules();
         if (newRules > 0) {
           message.append(" ").append(newRules).append(" new rules\n");
@@ -58,8 +76,8 @@ public class BuiltInQualityProfilesNotificationTemplate extends EmailTemplate {
         }
       });
 
-    message.append(
-      "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
+    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()
@@ -68,4 +86,11 @@ public class BuiltInQualityProfilesNotificationTemplate extends EmailTemplate {
       .setMessage(message.toString());
   }
 
+  public String encode(String text) {
+    try {
+      return URLEncoder.encode(text, StandardCharsets.UTF_8.name());
+    } catch (UnsupportedEncodingException e) {
+      throw new IllegalStateException(String.format("Cannot encode %s", text), e);
+    }
+  }
 }
index 9bd803d14bc4fc9d5cd9a75c4b2fb951b92c106e..cdca660efc4e709b69cacb94556808a457efa4c6 100644 (file)
@@ -63,7 +63,7 @@ public class BuiltInQualityProfilesNotificationSenderTest {
     verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
     verifyNoMoreInteractions(notificationManager);
     assertThat(BuiltInQualityProfilesNotification.parse(notificationArgumentCaptor.getValue()).getProfiles())
-      .extracting(Profile::getProfileName, Profile::getLanguage, Profile::getNewRules)
+      .extracting(Profile::getProfileName, Profile::getLanguageKey, Profile::getLanguageName, Profile::getNewRules)
       .containsExactlyInAnyOrder(expectedTuple);
   }
 
@@ -80,7 +80,7 @@ public class BuiltInQualityProfilesNotificationSenderTest {
     verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
     verifyNoMoreInteractions(notificationManager);
     assertThat(BuiltInQualityProfilesNotification.parse(notificationArgumentCaptor.getValue()).getProfiles())
-      .extracting(Profile::getProfileName, Profile::getLanguage, Profile::getUpdatedRules)
+      .extracting(Profile::getProfileName, Profile::getLanguageKey, Profile::getLanguageName, Profile::getUpdatedRules)
       .containsExactlyInAnyOrder(expectedTuple);
   }
 
@@ -97,7 +97,7 @@ public class BuiltInQualityProfilesNotificationSenderTest {
     verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
     verifyNoMoreInteractions(notificationManager);
     assertThat(BuiltInQualityProfilesNotification.parse(notificationArgumentCaptor.getValue()).getProfiles())
-      .extracting(Profile::getProfileName, Profile::getLanguage, Profile::getRemovedRules)
+      .extracting(Profile::getProfileName, Profile::getLanguageKey, Profile::getLanguageName, Profile::getRemovedRules)
       .containsExactlyInAnyOrder(expectedTuple);
   }
 
@@ -115,7 +115,7 @@ public class BuiltInQualityProfilesNotificationSenderTest {
     verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
     verifyNoMoreInteractions(notificationManager);
     assertThat(BuiltInQualityProfilesNotification.parse(notificationArgumentCaptor.getValue()).getProfiles())
-      .extracting(Profile::getProfileName, Profile::getLanguage, Profile::getNewRules)
+      .extracting(Profile::getProfileName, Profile::getLanguageKey, Profile::getLanguageName, Profile::getNewRules)
       .containsExactlyInAnyOrder(expectedTuple1, expectedTuple2);
   }
 
@@ -127,7 +127,7 @@ public class BuiltInQualityProfilesNotificationSenderTest {
     profiles.putAll(
       new QProfileName(language.getKey(), profileName),
       IntStream.range(0, numberOfChanges).mapToObj(i -> new ActiveRuleChange(type, ActiveRuleKey.parse("qp:repo:rule" + i))).collect(Collectors.toSet()));
-    return tuple(profileName, language.getName(), numberOfChanges);
+    return tuple(profileName, language.getKey(), language.getName(), numberOfChanges);
   }
 
   private static String randomLowerCaseText() {
index 1bd78367688aa2d07b5428addd701326712b7dae..b7d055214d75df704788bd25a2bb1c296431628e 100644 (file)
 
 package org.sonar.server.qualityprofile;
 
+import org.junit.Before;
 import org.junit.Test;
+import org.sonar.api.platform.Server;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 import org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.Profile;
 
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class BuiltInQualityProfilesNotificationTemplateTest {
 
-  private BuiltInQualityProfilesNotificationTemplate underTest = new BuiltInQualityProfilesNotificationTemplate();
+  private Server server = mock(Server.class);
+
+  private BuiltInQualityProfilesNotificationTemplate underTest = new BuiltInQualityProfilesNotificationTemplate(server);
+
+  @Before
+  public void setUp() throws Exception {
+    when(server.getPublicRootUrl()).thenReturn("http://" + randomAlphanumeric(10));
+  }
 
   @Test
   public void notification_contains_list_of_new_rules() {
-    String profileName = randomAlphanumeric(20);
-    String language = randomAlphanumeric(20);
+    String profileName = newProfileName();
+    String languageKey = newLanguageKey();
+    String languageName = newLanguageName();
     BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
-      .addProfile(Profile.newBuilder(profileName, language)
+      .addProfile(Profile.newBuilder()
+        .setProfileName(profileName)
+        .setLanguageKey(languageKey)
+        .setLanguageName(languageName)
         .setNewRules(2)
         .build());
 
     EmailMessage emailMessage = underTest.format(notification.serialize());
 
-    assertThat(emailMessage.getMessage()).isEqualTo("Built-in quality profiles have been updated:\n" +
-      "\"" + profileName + "\" - " + language + "\n" +
-      " 2 new rules\n" +
-      "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
+    assertMessage(emailMessage,
+      profileTitleText(profileName, languageKey, languageName) +
+        " 2 new rules\n");
   }
 
   @Test
   public void notification_contains_list_of_updated_rules() {
-    String profileName = randomAlphanumeric(20);
-    String language = randomAlphanumeric(20);
+    String profileName = newProfileName();
+    String languageKey = newLanguageKey();
+    String languageName = newLanguageName();
     BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
-      .addProfile(Profile.newBuilder(profileName, language)
+      .addProfile(Profile.newBuilder()
+        .setProfileName(profileName)
+        .setLanguageKey(languageKey)
+        .setLanguageName(languageName)
         .setUpdatedRules(2)
         .build());
 
     EmailMessage emailMessage = underTest.format(notification.serialize());
 
-    assertThat(emailMessage.getMessage()).isEqualTo("Built-in quality profiles have been updated:\n" +
-      "\"" + profileName + "\" - " + language + "\n" +
-      " 2 rules have been updated\n" +
-      "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
+    assertMessage(emailMessage,
+      profileTitleText(profileName, languageKey, languageName) +
+        " 2 rules have been updated\n");
   }
 
   @Test
   public void notification_contains_list_of_removed_rules() {
-    String profileName = randomAlphanumeric(20);
-    String language = randomAlphanumeric(20);
+    String profileName = newProfileName();
+    String languageKey = newLanguageKey();
+    String languageName = newLanguageName();
     BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
-      .addProfile(Profile.newBuilder(profileName, language)
+      .addProfile(Profile.newBuilder()
+        .setProfileName(profileName)
+        .setLanguageKey(languageKey)
+        .setLanguageName(languageName)
         .setRemovedRules(2)
         .build());
 
     EmailMessage emailMessage = underTest.format(notification.serialize());
 
-    assertThat(emailMessage.getMessage()).isEqualTo("Built-in quality profiles have been updated:\n" +
-      "\"" + profileName + "\" - " + language + "\n" +
-      " 2 rules removed\n" +
-      "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
+    assertMessage(emailMessage,
+      profileTitleText(profileName, languageKey, languageName) +
+        " 2 rules removed\n");
   }
 
   @Test
   public void notification_contains_list_of_new_updated_and_removed_rules() {
-    String profileName = randomAlphanumeric(20);
-    String language = randomAlphanumeric(20);
+    String profileName = newProfileName();
+    String languageKey = newLanguageKey();
+    String languageName = newLanguageName();
     BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
-      .addProfile(Profile.newBuilder(profileName, language)
+      .addProfile(Profile.newBuilder()
+        .setProfileName(profileName)
+        .setLanguageKey(languageKey)
+        .setLanguageName(languageName)
         .setNewRules(2)
         .setUpdatedRules(3)
         .setRemovedRules(4)
@@ -95,55 +119,100 @@ public class BuiltInQualityProfilesNotificationTemplateTest {
 
     EmailMessage emailMessage = underTest.format(notification.serialize());
 
-    assertThat(emailMessage.getMessage()).isEqualTo("Built-in quality profiles have been updated:\n" +
-      "\"" + profileName + "\" - " + language + "\n" +
-      " 2 new rules\n" +
-      " 3 rules have been updated\n" +
-      " 4 rules removed\n" +
-      "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
+    assertMessage(emailMessage,
+      profileTitleText(profileName, languageKey, languageName) +
+        " 2 new rules\n" +
+        " 3 rules have been updated\n" +
+        " 4 rules removed\n");
   }
 
   @Test
   public void notification_contains_many_profiles() {
     String profileName1 = "profile1_" + randomAlphanumeric(20);
-    String language1 = "lang1_" + randomAlphanumeric(20);
-    String profileName2 = "profile1_" + randomAlphanumeric(20);
-    String language2 = "lang2_" + randomAlphanumeric(20);
+    String languageKey1 = "langkey1_" + randomAlphanumeric(20);
+    String languageName1 = "langName1_" + randomAlphanumeric(20);
+    String profileName2 = "profile2_" + randomAlphanumeric(20);
+    String languageKey2 = "langkey2_" + randomAlphanumeric(20);
+    String languageName2 = "langName2_" + randomAlphanumeric(20);
     BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
-      .addProfile(Profile.newBuilder(profileName1, language1)
+      .addProfile(Profile.newBuilder()
+        .setProfileName(profileName1)
+        .setLanguageKey(languageKey1)
+        .setLanguageName(languageName1)
         .setNewRules(2)
         .build())
-      .addProfile(Profile.newBuilder(profileName2, language2)
+      .addProfile(Profile.newBuilder()
+        .setProfileName(profileName2)
+        .setLanguageKey(languageKey2)
+        .setLanguageName(languageName2)
         .setNewRules(13)
         .build());
 
     EmailMessage emailMessage = underTest.format(notification.serialize());
 
-    assertThat(emailMessage.getMessage()).isEqualTo("Built-in quality profiles have been updated:\n" +
-      "\"" + profileName1 + "\" - " + language1 + "\n" +
-      " 2 new rules\n" +
-      "\"" + profileName2 + "\" - " + language2 + "\n" +
-      " 13 new rules\n" +
-      "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
+    assertMessage(emailMessage,
+      profileTitleText(profileName1, languageKey1, languageName1) +
+        " 2 new rules\n" +
+        profileTitleText(profileName2, languageKey2, languageName2) +
+        " 13 new rules\n");
   }
 
   @Test
   public void notification_contains_profiles_sorted_by_language_then_by_profile_name() {
-    String language1 = "lang1_" + randomAlphanumeric(20);
-    String language2 = "lang2_" + randomAlphanumeric(20);
+    String languageKey1 = "langkey1_" + randomAlphanumeric(20);
+    String languageName1 = "langName1_" + randomAlphanumeric(20);
+    String languageKey2 = "langKey2_" + randomAlphanumeric(20);
+    String languageName2 = "langName2_" + randomAlphanumeric(20);
     String profileName1 = "profile1_" + randomAlphanumeric(20);
     String profileName2 = "profile2_" + randomAlphanumeric(20);
     String profileName3 = "profile3_" + randomAlphanumeric(20);
     BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
-      .addProfile(Profile.newBuilder(profileName3, language2).build())
-      .addProfile(Profile.newBuilder(profileName2, language1).build())
-      .addProfile(Profile.newBuilder(profileName1, language2).build());
+      .addProfile(Profile.newBuilder().setProfileName(profileName3).setLanguageKey(languageKey2).setLanguageName(languageName2).build())
+      .addProfile(Profile.newBuilder().setProfileName(profileName2).setLanguageKey(languageKey1).setLanguageName(languageName1).build())
+      .addProfile(Profile.newBuilder().setProfileName(profileName1).setLanguageKey(languageKey2).setLanguageName(languageName2).build());
 
     EmailMessage emailMessage = underTest.format(notification.serialize());
 
     assertThat(emailMessage.getMessage()).containsSequence(
-      "\"" + profileName2 + "\" - " + language1,
-      "\"" + profileName1 + "\" - " + language2,
-      "\"" + profileName3 + "\" - " + language2);
+      "\"" + profileName2 + "\" - " + languageName1,
+      "\"" + profileName1 + "\" - " + languageName2,
+      "\"" + profileName3 + "\" - " + languageName2);
+  }
+
+  @Test
+  public void notification_contains_encoded_profile_name() {
+    BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
+      .addProfile(Profile.newBuilder()
+        .setProfileName("Sonar Way")
+        .setLanguageKey("java")
+        .setLanguageName(newLanguageName())
+        .build());
+
+    EmailMessage emailMessage = underTest.format(notification.serialize());
+
+    assertThat(emailMessage.getMessage()).contains(server.getPublicRootUrl() + "/profiles/changelog?language=java&name=Sonar+Way");
+  }
+
+  private void assertMessage(EmailMessage emailMessage, String expectedProfileDetails) {
+    String expected = "Built-in quality profiles have been updated:\n" +
+      expectedProfileDetails +
+      "This is a good time to review your quality profiles and update them to benefit from the latest evolutions. " + server.getPublicRootUrl() + "/profiles";
+    assertThat(emailMessage.getMessage()).isEqualTo(expected);
+  }
+
+  private String profileTitleText(String profileName, String languageKey, String languageName) {
+    return "\"" + profileName + "\" - " + languageName + " " + server.getPublicRootUrl() + "/profiles/changelog?language=" + languageKey + "&name=" + profileName + "\n";
+  }
+
+  private static String newProfileName() {
+    return "profileName_" + randomAlphanumeric(20);
+  }
+
+  private static String newLanguageName() {
+    return "languageName_" + randomAlphanumeric(20);
+  }
+
+  private static String newLanguageKey() {
+    return "languageKey_" + randomAlphanumeric(20);
   }
 }
index 9180e904311a263178f5e071a1ff7da00bb306d5..bacbaa97af5eca71cce8cf819d0cd568cf1481a3 100644 (file)
@@ -48,10 +48,14 @@ public class BuiltInQualityProfilesNotificationTest {
   @Test
   public void serialize_and_parse_single_profile() {
     String profileName = randomAlphanumeric(20);
-    String language = randomAlphanumeric(20);
+    String languageKey = randomAlphanumeric(20);
+    String languageName = randomAlphanumeric(20);
 
     Notification notification = new BuiltInQualityProfilesNotification()
-      .addProfile(Profile.newBuilder(profileName, language)
+      .addProfile(Profile.newBuilder()
+        .setProfileName(profileName)
+        .setLanguageKey(languageKey)
+        .setLanguageName(languageName)
         .setNewRules(3)
         .setUpdatedRules(5)
         .setRemovedRules(7)
@@ -59,25 +63,36 @@ public class BuiltInQualityProfilesNotificationTest {
       .serialize();
     BuiltInQualityProfilesNotification result = BuiltInQualityProfilesNotification.parse(notification);
 
-    assertThat(result.getProfiles()).extracting(Profile::getProfileName, Profile::getLanguage, Profile::getNewRules, Profile::getUpdatedRules, Profile::getRemovedRules)
-      .containsExactlyInAnyOrder(tuple(profileName, language, 3, 5, 7));
+    assertThat(result.getProfiles()).extracting(Profile::getProfileName, Profile::getLanguageKey, Profile::getLanguageName,
+      Profile::getNewRules, Profile::getUpdatedRules, Profile::getRemovedRules)
+      .containsExactlyInAnyOrder(tuple(profileName, languageKey, languageName, 3, 5, 7));
   }
 
   @Test
   public void serialize_and_parse_multiple_profiles() {
     String profileName1 = randomAlphanumeric(20);
-    String language1 = randomAlphanumeric(20);
+    String languageKey1 = randomAlphanumeric(20);
+    String languageName1 = randomAlphanumeric(20);
     String profileName2 = randomAlphanumeric(20);
-    String language2 = randomAlphanumeric(20);
+    String languageKey2 = randomAlphanumeric(20);
+    String languageName2 = randomAlphanumeric(20);
 
     Notification notification = new BuiltInQualityProfilesNotification()
-      .addProfile(Profile.newBuilder(profileName1, language1).build())
-      .addProfile(Profile.newBuilder(profileName2, language2).build())
+      .addProfile(Profile.newBuilder()
+        .setProfileName(profileName1)
+        .setLanguageKey(languageKey1)
+        .setLanguageName(languageName1)
+        .build())
+      .addProfile(Profile.newBuilder()
+        .setProfileName(profileName2)
+        .setLanguageKey(languageKey2)
+        .setLanguageName(languageName2)
+        .build())
       .serialize();
     BuiltInQualityProfilesNotification result = BuiltInQualityProfilesNotification.parse(notification);
 
-    assertThat(result.getProfiles()).extracting(Profile::getProfileName, Profile::getLanguage)
-      .containsExactlyInAnyOrder(tuple(profileName1, language1), tuple(profileName2, language2));
+    assertThat(result.getProfiles()).extracting(Profile::getProfileName, Profile::getLanguageKey, Profile::getLanguageName)
+      .containsExactlyInAnyOrder(tuple(profileName1, languageKey1, languageName1), tuple(profileName2, languageKey2, languageName2));
   }
 
   @Test
index 7845f3ced145e6bdd64404526b7a21575b62ae54..82aecb351c54bdde736e44494ab090db5a8ba87a 100644 (file)
@@ -70,7 +70,8 @@ public class BuiltInQualityProfilesNotificationTest {
       .addPlugin(pluginArtifact("foo-plugin-v1"))
       .setServerProperty("email.smtp_host.secured", "localhost")
       .setServerProperty("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()))
-      //.setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")// FIXME remove web debugging
+      // .setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")// FIXME
+      // remove web debugging
       .build();
     orchestrator.start();
 
@@ -100,7 +101,8 @@ public class BuiltInQualityProfilesNotificationTest {
       .addPlugin(pluginArtifact("foo-plugin-v1"))
       .setServerProperty("email.smtp_host.secured", "localhost")
       .setServerProperty("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()))
-      //.setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")// FIXME remove web debugging
+      // .setServerProperty("sonar.web.javaAdditionalOpts", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8001")// FIXME
+      // remove web debugging
       .build();
     orchestrator.start();
 
@@ -133,14 +135,15 @@ public class BuiltInQualityProfilesNotificationTest {
       .extracting(this::getMimeMessage)
       .extracting(this::getAllRecipients)
       .containsOnly("<" + profileAdmin1.getEmail() + ">", "<" + profileAdmin2.getEmail() + ">");
+    String url = orchestrator.getServer().getUrl();
     assertThat(messages.get(0).getMimeMessage().getContent().toString())
       .containsSequence(
         "Built-in quality profiles have been updated:",
-        "\"Basic\" - Foo",
+        "\"Basic\" - Foo " + url + "/profiles/changelog?language=foo&name=Basic",
         " 1 new rules",
         " 3 rules have been updated",
         " 1 rules removed",
-        "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.")
+        "This is a good time to review your quality profiles and update them to benefit from the latest evolutions. " + url + "/profiles")
       .isEqualTo(messages.get(1).getMimeMessage().getContent().toString());
   }