Added oparent to sdc main
[sdc.git] / openecomp-be / lib / openecomp-sdc-notification-lib / openecomp-sdc-notification-core / src / test / java / org / openecomp / sdc / destinationprovider / impl / MulticastDestinationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.destinationprovider.impl;
22
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;
28
29 import java.util.Arrays;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Set;
33
34 import static org.junit.Assert.*;
35 import static org.mockito.Matchers.any;
36 import static org.mockito.Mockito.doReturn;
37
38 /**
39  * @author avrahamg
40  * @since July 13, 2017
41  */
42 public class MulticastDestinationTest {
43     @Mock
44     private SubscriptionService subscriptionServiceMock;
45
46     private final String excludedSubscriber = "excluded";
47     private Set<String> subscribers = new HashSet<>(Arrays.asList("a", "b", excludedSubscriber));
48     private MulticastDestination multicastDestination;
49
50     @Before
51     public void setUp() throws Exception {
52         MockitoAnnotations.initMocks(this);
53     }
54
55     @Test
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));
62     }
63
64     @Test
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));
73     }
74
75     @Test(expected = UnsupportedOperationException.class)
76     public void shouldThrowUnsupportedOperationExceptionWhenTryingToChangeSubscribersList() throws
77         Exception {
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");
83     }
84 }