78265769e55541bfed69e9ac940c8563e4c206e4
[sdc.git] /
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.jupiter.api.Test;
24 import org.junit.jupiter.api.extension.ExtendWith;
25 import org.mockito.Mock;
26 import org.mockito.junit.jupiter.MockitoExtension;
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.jupiter.api.Assertions.assertEquals;
35 import static org.junit.jupiter.api.Assertions.assertFalse;
36 import static org.junit.jupiter.api.Assertions.assertNotEquals;
37 import static org.junit.jupiter.api.Assertions.assertTrue;
38 import static org.mockito.Matchers.any;
39 import static org.mockito.Mockito.doReturn;
40
41 /**
42  * @author avrahamg
43  * @since July 13, 2017
44  */
45 @ExtendWith(MockitoExtension.class)
46 public class MulticastDestinationTest {
47     @Mock
48     private SubscriptionService subscriptionServiceMock;
49
50     private final String excludedSubscriber = "excluded";
51     private Set<String> subscribers = new HashSet<>(Arrays.asList("a", "b", excludedSubscriber));
52     private MulticastDestination multicastDestination;
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
76     public void entityIdTest() {
77         multicastDestination =
78                 new MulticastDestination("aa", subscriptionServiceMock, excludedSubscriber);
79         multicastDestination.setEntityId("entityId");
80         assertEquals("entityId", multicastDestination.getEntityId());
81     }
82 }