2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.destinationprovider.impl;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.openecomp.sdc.notification.services.SubscriptionService;
29 import java.util.Arrays;
30 import java.util.HashSet;
31 import java.util.List;
34 import static org.junit.Assert.*;
35 import static org.mockito.Matchers.any;
36 import static org.mockito.Mockito.doReturn;
40 * @since July 13, 2017
42 public class MulticastDestinationTest {
44 private SubscriptionService subscriptionServiceMock;
46 private final String excludedSubscriber = "excluded";
47 private Set<String> subscribers = new HashSet<>(Arrays.asList("a", "b", excludedSubscriber));
48 private MulticastDestination multicastDestination;
51 public void setUp() throws Exception {
52 MockitoAnnotations.initMocks(this);
56 public void shouldReturnAllSubscribersIfNoExcludedProvided() throws Exception {
57 doReturn(subscribers).when(subscriptionServiceMock).getSubscribers(any());
58 multicastDestination = new MulticastDestination("aa", subscriptionServiceMock);
59 assertEquals(subscribers.size(), multicastDestination.getSubscribers().size());
60 List<String> actualSubscribers = multicastDestination.getSubscribers();
61 assertTrue(actualSubscribers.containsAll(subscribers));
65 public void shouldReturnAllSubscribersExceptExcluded() throws Exception {
66 doReturn(subscribers).when(subscriptionServiceMock).getSubscribers(any());
67 multicastDestination =
68 new MulticastDestination("aa", subscriptionServiceMock, excludedSubscriber);
69 List<String> actualSubscribers = multicastDestination.getSubscribers();
70 assertNotEquals(this.subscribers.size(), actualSubscribers.size());
71 assertFalse(actualSubscribers.containsAll(subscribers));
72 assertFalse(actualSubscribers.contains(excludedSubscriber));
75 @Test(expected = UnsupportedOperationException.class)
76 public void shouldThrowUnsupportedOperationExceptionWhenTryingToChangeSubscribersList() throws
78 doReturn(subscribers).when(subscriptionServiceMock).getSubscribers(any());
79 multicastDestination =
80 new MulticastDestination("aa", subscriptionServiceMock, excludedSubscriber);
81 List<String> actualSubscribers = multicastDestination.getSubscribers();
82 actualSubscribers.add("sss");