Improve testing stability
[sdc.git] / openecomp-be / lib / openecomp-sdc-notification-lib / openecomp-sdc-notification-core / src / test / java / org / openecomp / sdc / notification / services / impl / NotificationPropagationManagerImplTest.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.notification.services.impl;
22
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.*;
27 import org.openecomp.sdc.destinationprovider.DestinationProvider;
28 import org.openecomp.sdc.destinationprovider.impl.MulticastDestination;
29 import org.openecomp.sdc.destinationprovider.impl.UnicastDestination;
30 import org.openecomp.sdc.notification.dtos.Event;
31 import org.openecomp.sdc.notification.services.PropagationService;
32 import org.openecomp.sdc.notification.services.SubscriptionService;
33
34 import static org.mockito.Mockito.verify;
35
36
37 /**
38  * @author avrahamg
39  * @since July 13, 2017
40  */
41 public class NotificationPropagationManagerImplTest {
42     @Mock
43     private PropagationService propagationServiceMock;
44     @Mock
45     private SubscriptionService subscriptionServiceMock;
46     @Mock
47     private Event eventMock;
48     @Captor
49     private ArgumentCaptor<DestinationProvider> destinationProviderCaptor;
50
51     @Spy
52     @InjectMocks
53     private NotificationPropagationManagerImpl notificationPropagationManager;
54
55     @Before
56     public void setUp() throws Exception {
57         MockitoAnnotations.openMocks(this);
58     }
59
60     @Test
61     public void shouldCallPropagationServiceNotifyWithMulticastDestinationWhenNotifySubscribers()
62         throws Exception {
63         notificationPropagationManager.notifySubscribers(eventMock);
64         verify(propagationServiceMock).notify(Matchers.eq(eventMock), destinationProviderCaptor
65             .capture());
66         Assert.assertTrue(destinationProviderCaptor.getValue() instanceof MulticastDestination);
67
68     }
69
70     @Test
71     public void shouldCallPropagationServiceNotifyWithUnicastDestinationWhenDirectNotification()
72         throws Exception {
73         notificationPropagationManager.directNotification(eventMock, "aaa");
74         verify(propagationServiceMock).notify(Matchers.eq(eventMock), destinationProviderCaptor
75             .capture());
76         Assert.assertTrue(destinationProviderCaptor.getValue() instanceof UnicastDestination);
77     }
78 }