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.Rule;
24 import org.junit.Test;
25 import org.junit.rules.ExpectedException;
26 import org.sonar.api.notifications.Notification;
27 import org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.Profile;
29 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
30 import static org.assertj.core.api.Assertions.assertThat;
31 import static org.assertj.core.api.Assertions.tuple;
32 import static org.sonar.server.qualityprofile.BuiltInQualityProfilesNotificationSender.BUILT_IN_QUALITY_PROFILES;
34 public class BuiltInQualityProfilesNotificationTest {
37 public ExpectedException expectedException = ExpectedException.none();
40 public void serialize_and_parse_no_profile() {
41 Notification notification = new BuiltInQualityProfilesNotification().serialize();
43 BuiltInQualityProfilesNotification result = BuiltInQualityProfilesNotification.parse(notification);
45 assertThat(result.getProfiles()).isEmpty();
49 public void serialize_and_parse_single_profile() {
50 String profileName = randomAlphanumeric(20);
51 String language = randomAlphanumeric(20);
53 Notification notification = new BuiltInQualityProfilesNotification().addProfile(new Profile(profileName, language)).serialize();
54 BuiltInQualityProfilesNotification result = BuiltInQualityProfilesNotification.parse(notification);
56 assertThat(result.getProfiles()).extracting(Profile::getProfileName, Profile::getLanguage)
57 .containsExactlyInAnyOrder(tuple(profileName, language));
61 public void serialize_and_parse_multiple_profiles() {
62 String profileName1 = randomAlphanumeric(20);
63 String language1 = randomAlphanumeric(20);
64 String profileName2 = randomAlphanumeric(20);
65 String language2 = randomAlphanumeric(20);
67 Notification notification = new BuiltInQualityProfilesNotification()
68 .addProfile(new Profile(profileName1, language1))
69 .addProfile(new Profile(profileName2, language2))
71 BuiltInQualityProfilesNotification result = BuiltInQualityProfilesNotification.parse(notification);
73 assertThat(result.getProfiles()).extracting(Profile::getProfileName, Profile::getLanguage)
74 .containsExactlyInAnyOrder(tuple(profileName1, language1), tuple(profileName2, language2));
78 public void fail_with_ISE_when_parsing_empty_notification() {
79 expectedException.expect(IllegalStateException.class);
80 expectedException.expectMessage("Could not read the built-in quality profile notification");
82 BuiltInQualityProfilesNotification.parse(new Notification(BUILT_IN_QUALITY_PROFILES));