3 * Copyright (C) 2009-2023 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.
20 package org.sonar.server.notification.ws;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.sonar.api.notifications.NotificationChannel;
25 import org.sonar.server.notification.NotificationDispatcherMetadata;
27 import static org.assertj.core.api.Assertions.assertThat;
28 import static org.mockito.Mockito.mock;
30 public class NotificationCenterTest {
32 private NotificationChannel emailChannel = mock(NotificationChannel.class);
33 private NotificationChannel gtalkChannel = mock(NotificationChannel.class);
35 private NotificationCenter underTest;
39 NotificationDispatcherMetadata metadata1 = NotificationDispatcherMetadata.create("Dispatcher1").setProperty("global", "true").setProperty("on-project", "true");
40 NotificationDispatcherMetadata metadata2 = NotificationDispatcherMetadata.create("Dispatcher2").setProperty("global", "true");
41 NotificationDispatcherMetadata metadata3 = NotificationDispatcherMetadata.create("Dispatcher3").setProperty("global", "FOO").setProperty("on-project", "BAR");
43 underTest = new NotificationCenter(
44 new NotificationDispatcherMetadata[] {metadata1, metadata2, metadata3},
45 new NotificationChannel[] {emailChannel, gtalkChannel}
50 public void shouldReturnChannels() {
51 assertThat(underTest.getChannels()).containsOnly(emailChannel, gtalkChannel);
55 public void shouldReturnDispatcherKeysForSpecificPropertyValue() {
56 assertThat(underTest.getDispatcherKeysForProperty("global", "true")).containsOnly("Dispatcher1", "Dispatcher2");
60 public void shouldReturnDispatcherKeysForExistenceOfProperty() {
61 assertThat(underTest.getDispatcherKeysForProperty("on-project", null)).containsOnly("Dispatcher1", "Dispatcher3");
65 public void testDefaultConstructors() {
66 underTest = new NotificationCenter(new NotificationChannel[] {emailChannel});
67 assertThat(underTest.getChannels()).hasSize(1);
69 underTest = new NotificationCenter();
70 assertThat(underTest.getChannels()).isEmpty();
72 underTest = new NotificationCenter(new NotificationDispatcherMetadata[] {NotificationDispatcherMetadata.create("Dispatcher1").setProperty("global", "true")});
73 assertThat(underTest.getChannels()).isEmpty();
74 assertThat(underTest.getDispatcherKeysForProperty("global", null)).hasSize(1);