1 package org.openecomp.sdc.notification.services.impl;
3 import org.junit.Assert;
4 import org.junit.Before;
7 import org.junit.rules.ExpectedException;
9 import org.openecomp.sdc.destinationprovider.DestinationProvider;
10 import org.openecomp.sdc.notification.dao.NotificationsDao;
11 import org.openecomp.sdc.notification.dtos.Event;
13 import java.util.Arrays;
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.List;
18 import static org.mockito.Matchers.anyList;
19 import static org.mockito.Mockito.*;
23 * @since July 13, 2017
25 public class PropagationServiceImplTest {
27 private NotificationsDao notificationsDaoMock;
29 private Event eventMock;
31 private DestinationProvider destinationProviderMock;
33 private ArgumentCaptor<List> createBatchCaptor;
36 public ExpectedException thrown= ExpectedException.none();
40 private PropagationServiceImpl propagationService;
41 private List<String> subscribersList = Arrays.asList("A1, A2, A3");;
44 public void setUp() throws Exception {
45 MockitoAnnotations.initMocks(this);
50 public void shouldCallToNotificationsDaoWithCreateBatchWithNotificationEntitiesAsNumberOfSubscribers()
52 doReturn(subscribersList).when(destinationProviderMock).getSubscribers();
53 propagationService.notify(eventMock, destinationProviderMock);
54 verify(notificationsDaoMock).createBatch(createBatchCaptor.capture());
55 Assert.assertEquals(createBatchCaptor.getValue().size(), subscribersList.size());
59 public void shouldNotCallNotificationDaoIfSubscriberIsNull() throws Exception {
60 doReturn(Collections.EMPTY_LIST).when(destinationProviderMock).getSubscribers();
61 verify(notificationsDaoMock,never()).createBatch(anyList());
65 public void shouldThrowExceptionIfEventTypeIsNull() throws Exception {
66 doReturn(null).when(eventMock).getEventType();
71 public void shouldThrowExceptionIfOriginatorIdIsNull() throws Exception {
72 doReturn(null).when(eventMock).getOriginatorId();
76 private void callToNotify() {
77 thrown.expect(NullPointerException.class);
78 propagationService.notify(eventMock, destinationProviderMock);
81 private void initEventMock() {
82 doReturn("eventType").when(eventMock).getEventType();
83 doReturn("originator").when(eventMock).getOriginatorId();
84 doReturn("entity").when(eventMock).getEntityId();
85 doReturn(new HashMap<>()).when(eventMock).getAttributes();