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;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.mockito.MockitoAnnotations;
20 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
21 import org.opendaylight.transportpce.test.AbstractTest;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
24 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessService;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationAlarmService;
27 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationAlarmServiceBuilder;
28 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationProcessService;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationProcessServiceBuilder;
31 public class NbiNotificationsListenerImplTest extends AbstractTest {
33 private Publisher<NotificationProcessService> publisherService;
35 private Publisher<NotificationAlarmService> publisherAlarm;
39 MockitoAnnotations.openMocks(this);
43 public void onPublishNotificationServiceTest() {
44 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
45 Map.of("test", publisherAlarm));
46 PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
47 .setPublisherName("test")
48 .setCommonId("commonId")
49 .setConnectionType(ConnectionType.Service)
50 .setMessage("Service deleted")
51 .setOperationalState(State.OutOfService)
52 .setServiceName("service name")
54 listener.onPublishNotificationProcessService(notification);
55 verify(publisherService, times(1)).sendEvent(any(), anyString());
59 public void onPublishNotificationServiceWrongPublisherTest() {
60 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
61 Map.of("test", publisherAlarm));
62 PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
63 .setPublisherName("wrongPublisher")
64 .setCommonId("commonId")
65 .setConnectionType(ConnectionType.Service)
66 .setMessage("Service deleted")
67 .setOperationalState(State.OutOfService)
68 .setServiceName("service name")
70 listener.onPublishNotificationProcessService(notification);
71 verify(publisherService, times(0)).sendEvent(any(), anyString());
75 public void onPublishNotificationAlarmServiceTest() {
76 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
77 Map.of("test", publisherAlarm));
78 PublishNotificationAlarmService notification = new PublishNotificationAlarmServiceBuilder()
79 .setPublisherName("test")
80 .setConnectionType(ConnectionType.Service)
81 .setMessage("The service is now inService")
82 .setOperationalState(State.OutOfService)
83 .setServiceName("service name")
85 listener.onPublishNotificationAlarmService(notification);
86 verify(publisherAlarm, times(1)).sendEvent(any(), anyString());
90 public void onPublishNotificationAlarmServiceWrongPublisherTest() {
91 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
92 Map.of("test", publisherAlarm));
93 PublishNotificationAlarmService notification = new PublishNotificationAlarmServiceBuilder()
94 .setPublisherName("wrongPublisher")
95 .setConnectionType(ConnectionType.Service)
96 .setMessage("The service is now inService")
97 .setOperationalState(State.OutOfService)
98 .setServiceName("service name")
100 listener.onPublishNotificationAlarmService(notification);
101 verify(publisherAlarm, times(0)).sendEvent(any(), anyString());