2 * Copyright © 2021 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.nbinotifications.listener;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.ArgumentMatchers.anyString;
12 import static org.mockito.Mockito.times;
13 import static org.mockito.Mockito.verify;
15 import java.util.HashMap;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
22 import org.opendaylight.transportpce.test.AbstractTest;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
27 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationAlarmService;
28 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationAlarmServiceBuilder;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessServiceBuilder;
32 public class NbiNotificationsListenerImplTest extends AbstractTest {
34 private Publisher<NotificationProcessService> publisherService;
36 private Publisher<NotificationAlarmService> publisherAlarm;
40 MockitoAnnotations.openMocks(this);
44 public void onPublishNotificationServiceTest() {
45 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
46 Map.of("test", publisherAlarm), new HashMap<>());
47 PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
48 .setPublisherName("test")
49 .setCommonId("commonId")
50 .setConnectionType(ConnectionType.Service)
51 .setMessage("Service deleted")
52 .setOperationalState(State.OutOfService)
53 .setServiceName("service name")
55 listener.onPublishNotificationProcessService(notification);
56 verify(publisherService, times(1)).sendEvent(any(), anyString());
60 public void onPublishNotificationServiceWrongPublisherTest() {
61 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
62 Map.of("test", publisherAlarm), new HashMap<>());
63 PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
64 .setPublisherName("wrongPublisher")
65 .setCommonId("commonId")
66 .setConnectionType(ConnectionType.Service)
67 .setMessage("Service deleted")
68 .setOperationalState(State.OutOfService)
69 .setServiceName("service name")
71 listener.onPublishNotificationProcessService(notification);
72 verify(publisherService, times(0)).sendEvent(any(), anyString());
76 public void onPublishNotificationAlarmServiceTest() {
77 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
78 Map.of("test", publisherAlarm), new HashMap<>());
79 PublishNotificationAlarmService notification = new PublishNotificationAlarmServiceBuilder()
80 .setPublisherName("test")
81 .setConnectionType(ConnectionType.Service)
82 .setMessage("The service is now inService")
83 .setOperationalState(State.OutOfService)
84 .setServiceName("service name")
86 listener.onPublishNotificationAlarmService(notification);
87 verify(publisherAlarm, times(1)).sendEvent(any(), anyString());
91 public void onPublishNotificationAlarmServiceWrongPublisherTest() {
92 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
93 Map.of("test", publisherAlarm), new HashMap<>());
94 PublishNotificationAlarmService notification = new PublishNotificationAlarmServiceBuilder()
95 .setPublisherName("wrongPublisher")
96 .setConnectionType(ConnectionType.Service)
97 .setMessage("The service is now inService")
98 .setOperationalState(State.OutOfService)
99 .setServiceName("service name")
101 listener.onPublishNotificationAlarmService(notification);
102 verify(publisherAlarm, times(0)).sendEvent(any(), anyString());