3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.server.qualityprofile;
23 import org.junit.Test;
24 import org.sonar.plugins.emailnotifications.api.EmailMessage;
25 import org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.Profile;
27 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
28 import static org.assertj.core.api.Assertions.assertThat;
30 public class BuiltInQualityProfilesNotificationTemplateTest {
32 private BuiltInQualityProfilesNotificationTemplate underTest = new BuiltInQualityProfilesNotificationTemplate();
35 public void notification_contains_list_of_new_rules() {
36 String profileName = randomAlphanumeric(20);
37 String language = randomAlphanumeric(20);
38 BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
39 .addProfile(Profile.newBuilder(profileName, language)
43 EmailMessage emailMessage = underTest.format(notification.serialize());
45 assertThat(emailMessage.getMessage()).isEqualTo("Built-in quality profiles have been updated:\n" +
46 "\"" + profileName + "\" - " + language + "\n" +
48 "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
52 public void notification_contains_list_of_updated_rules() {
53 String profileName = randomAlphanumeric(20);
54 String language = randomAlphanumeric(20);
55 BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
56 .addProfile(Profile.newBuilder(profileName, language)
60 EmailMessage emailMessage = underTest.format(notification.serialize());
62 assertThat(emailMessage.getMessage()).isEqualTo("Built-in quality profiles have been updated:\n" +
63 "\"" + profileName + "\" - " + language + "\n" +
64 " 2 rules have been updated\n" +
65 "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
69 public void notification_contains_list_of_removed_rules() {
70 String profileName = randomAlphanumeric(20);
71 String language = randomAlphanumeric(20);
72 BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
73 .addProfile(Profile.newBuilder(profileName, language)
77 EmailMessage emailMessage = underTest.format(notification.serialize());
79 assertThat(emailMessage.getMessage()).isEqualTo("Built-in quality profiles have been updated:\n" +
80 "\"" + profileName + "\" - " + language + "\n" +
81 " 2 rules removed\n" +
82 "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
86 public void notification_contains_list_of_new_updated_and_removed_rules() {
87 String profileName = randomAlphanumeric(20);
88 String language = randomAlphanumeric(20);
89 BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
90 .addProfile(Profile.newBuilder(profileName, language)
96 EmailMessage emailMessage = underTest.format(notification.serialize());
98 assertThat(emailMessage.getMessage()).isEqualTo("Built-in quality profiles have been updated:\n" +
99 "\"" + profileName + "\" - " + language + "\n" +
101 " 3 rules have been updated\n" +
102 " 4 rules removed\n" +
103 "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
107 public void notification_contains_many_profiles() {
108 String profileName1 = "profile1_" + randomAlphanumeric(20);
109 String language1 = "lang1_" + randomAlphanumeric(20);
110 String profileName2 = "profile1_" + randomAlphanumeric(20);
111 String language2 = "lang2_" + randomAlphanumeric(20);
112 BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
113 .addProfile(Profile.newBuilder(profileName1, language1)
116 .addProfile(Profile.newBuilder(profileName2, language2)
120 EmailMessage emailMessage = underTest.format(notification.serialize());
122 assertThat(emailMessage.getMessage()).isEqualTo("Built-in quality profiles have been updated:\n" +
123 "\"" + profileName1 + "\" - " + language1 + "\n" +
125 "\"" + profileName2 + "\" - " + language2 + "\n" +
127 "This is a good time to review your quality profiles and update them to benefit from the latest evolutions.");
131 public void notification_contains_profiles_sorted_by_language_then_by_profile_name() {
132 String language1 = "lang1_" + randomAlphanumeric(20);
133 String language2 = "lang2_" + randomAlphanumeric(20);
134 String profileName1 = "profile1_" + randomAlphanumeric(20);
135 String profileName2 = "profile2_" + randomAlphanumeric(20);
136 String profileName3 = "profile3_" + randomAlphanumeric(20);
137 BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
138 .addProfile(Profile.newBuilder(profileName3, language2).build())
139 .addProfile(Profile.newBuilder(profileName2, language1).build())
140 .addProfile(Profile.newBuilder(profileName1, language2).build());
142 EmailMessage emailMessage = underTest.format(notification.serialize());
144 assertThat(emailMessage.getMessage()).containsSequence(
145 "\"" + profileName2 + "\" - " + language1,
146 "\"" + profileName1 + "\" - " + language2,
147 "\"" + profileName3 + "\" - " + language2);