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.notification.services.impl;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.ExpectedException;
29 import org.openecomp.sdc.destinationprovider.DestinationProvider;
30 import org.openecomp.sdc.notification.dao.NotificationsDao;
31 import org.openecomp.sdc.notification.dtos.Event;
33 import java.util.Arrays;
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.List;
38 import static org.mockito.Matchers.anyList;
39 import static org.mockito.Mockito.*;
43 * @since July 13, 2017
45 public class PropagationServiceImplTest {
47 private NotificationsDao notificationsDaoMock;
49 private Event eventMock;
51 private DestinationProvider destinationProviderMock;
53 private ArgumentCaptor<List> createBatchCaptor;
56 public ExpectedException thrown= ExpectedException.none();
60 private PropagationServiceImpl propagationService;
61 private List<String> subscribersList = Arrays.asList("A1, A2, A3");;
64 public void setUp() throws Exception {
65 MockitoAnnotations.initMocks(this);
70 public void shouldCallToNotificationsDaoWithCreateBatchWithNotificationEntitiesAsNumberOfSubscribers()
72 doReturn(subscribersList).when(destinationProviderMock).getSubscribers();
73 propagationService.notify(eventMock, destinationProviderMock);
74 verify(notificationsDaoMock).createBatch(createBatchCaptor.capture());
75 Assert.assertEquals(createBatchCaptor.getValue().size(), subscribersList.size());
79 public void shouldNotCallNotificationDaoIfSubscriberIsNull() throws Exception {
80 doReturn(Collections.EMPTY_LIST).when(destinationProviderMock).getSubscribers();
81 verify(notificationsDaoMock,never()).createBatch(anyList());
85 public void shouldThrowExceptionIfEventTypeIsNull() throws Exception {
86 doReturn(null).when(eventMock).getEventType();
91 public void shouldThrowExceptionIfOriginatorIdIsNull() throws Exception {
92 doReturn(null).when(eventMock).getOriginatorId();
96 private void callToNotify() {
97 thrown.expect(NullPointerException.class);
98 propagationService.notify(eventMock, destinationProviderMock);
101 private void initEventMock() {
102 doReturn("eventType").when(eventMock).getEventType();
103 doReturn("originator").when(eventMock).getOriginatorId();
104 doReturn("entity").when(eventMock).getEntityId();
105 doReturn(new HashMap<>()).when(eventMock).getAttributes();