]> source.dussan.org Git - sonarqube.git/blob
819412888d52e0b5e990bf9af6668bfdd3a6e514
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2017 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.server.qualityprofile;
21
22 import java.util.List;
23 import org.junit.Test;
24 import org.mockito.ArgumentCaptor;
25 import org.sonar.api.notifications.Notification;
26 import org.sonar.api.resources.Languages;
27 import org.sonar.server.language.LanguageTesting;
28 import org.sonar.server.notification.NotificationManager;
29 import org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.Profile;
30
31 import static java.util.Collections.singletonList;
32 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
33 import static org.assertj.core.api.Java6Assertions.assertThat;
34 import static org.assertj.core.api.Java6Assertions.tuple;
35 import static org.mockito.Mockito.mock;
36 import static org.mockito.Mockito.verify;
37 import static org.mockito.Mockito.verifyNoMoreInteractions;
38
39 public class BuiltInQualityProfilesNotificationSenderTest {
40
41   private NotificationManager notificationManager = mock(NotificationManager.class);
42
43   @Test
44   public void add_profile_to_notification() throws Exception {
45     String profileName = randomLowerCaseText();
46     String languageKey = randomLowerCaseText();
47     String languageName = randomLowerCaseText();
48     List<QProfileName> profileNames = singletonList(new QProfileName(languageKey, profileName));
49     Languages languages = new Languages(LanguageTesting.newLanguage(languageKey, languageName));
50
51     BuiltInQualityProfilesNotificationSender underTest = new BuiltInQualityProfilesNotificationSender(notificationManager, languages);
52     underTest.send(profileNames);
53
54     ArgumentCaptor<Notification> notificationArgumentCaptor = ArgumentCaptor.forClass(Notification.class);
55     verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
56     verifyNoMoreInteractions(notificationManager);
57     assertThat(BuiltInQualityProfilesNotification.parse(notificationArgumentCaptor.getValue()).getProfiles())
58       .extracting(Profile::getProfileName, Profile::getLanguage)
59       .containsExactlyInAnyOrder(tuple(profileName, languageName));
60   }
61
62   private static String randomLowerCaseText() {
63     return randomAlphanumeric(20).toLowerCase();
64   }
65 }