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.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertNull;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.ArgumentMatchers.anyString;
14 import static org.mockito.ArgumentMatchers.eq;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
19 import java.util.UUID;
20 import java.util.concurrent.ExecutionException;
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
23 import org.mockito.Mock;
24 import org.mockito.MockitoAnnotations;
25 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
26 import org.opendaylight.transportpce.nbinotifications.utils.NotificationServiceDataUtils;
27 import org.opendaylight.transportpce.test.AbstractTest;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ConnectionType;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
32 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
33 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.PublishNotificationAlarmService;
34 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.PublishNotificationAlarmServiceBuilder;
35 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.PublishNotificationProcessService;
36 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.PublishNotificationProcessServiceBuilder;
37 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.PublishTapiNotificationService;
38 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.PublishTapiNotificationServiceBuilder;
40 public class NbiNotificationsHandlerTest extends AbstractTest {
42 private Publisher<NotificationProcessService> publisherService;
44 private Publisher<NotificationAlarmService> publisherAlarm;
46 private Publisher<NotificationTapiService> publisherTapiService;
49 void setUp() throws ExecutionException, InterruptedException {
50 MockitoAnnotations.openMocks(this);
54 void onPublishNotificationServiceTest() {
55 NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
56 Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
57 PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
58 .setPublisherName("test")
59 .setCommonId("commonId")
60 .setConnectionType(ConnectionType.Service)
61 .setIsTempService(false)
62 .setMessage("Service deleted")
63 .setOperationalState(State.OutOfService)
64 .setServiceName("service name")
66 listener.onPublishNotificationProcessService(notification);
67 verify(publisherService, times(1)).sendEvent(any(), anyString());
71 void onPublishNotificationServiceWrongPublisherTest() {
72 NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
73 Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
74 PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
75 .setPublisherName("wrongPublisher")
76 .setCommonId("commonId")
77 .setConnectionType(ConnectionType.Service)
78 .setMessage("Service deleted")
79 .setOperationalState(State.OutOfService)
80 .setServiceName("service name")
82 listener.onPublishNotificationProcessService(notification);
83 verify(publisherService, times(0)).sendEvent(any(), anyString());
87 void onPublishNotificationAlarmServiceTest() {
88 NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
89 Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
90 PublishNotificationAlarmService notification = new PublishNotificationAlarmServiceBuilder()
91 .setPublisherName("test")
92 .setConnectionType(ConnectionType.Service)
93 .setMessage("The service is now inService")
94 .setOperationalState(State.OutOfService)
95 .setServiceName("service name")
97 listener.onPublishNotificationAlarmService(notification);
98 verify(publisherAlarm, times(1)).sendEvent(any(), anyString());
102 void onPublishNotificationAlarmServiceWrongPublisherTest() {
103 NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
104 Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
105 PublishNotificationAlarmService notification = new PublishNotificationAlarmServiceBuilder()
106 .setPublisherName("wrongPublisher")
107 .setConnectionType(ConnectionType.Service)
108 .setMessage("The service is now inService")
109 .setOperationalState(State.OutOfService)
110 .setServiceName("service name")
112 listener.onPublishNotificationAlarmService(notification);
113 verify(publisherAlarm, times(0)).sendEvent(any(), anyString());
117 void onPublishTapiNotificationServiceTest() throws ExecutionException, InterruptedException {
118 NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
119 Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
121 PublishTapiNotificationService notification
122 = new PublishTapiNotificationServiceBuilder(NotificationServiceDataUtils.buildReceivedTapiAlarmEvent())
125 listener.onPublishTapiNotificationService(notification);
126 verify(publisherTapiService, times(1)).sendEvent(any(), anyString());
130 void onPublishTapiNotificationServiceTestWrongPublisherTest() {
131 NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
132 Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
133 PublishTapiNotificationService notification
134 = new PublishTapiNotificationServiceBuilder(NotificationServiceDataUtils.buildReceivedTapiAlarmEvent())
135 .setTopic(UUID.randomUUID().toString())
137 listener.onPublishTapiNotificationService(notification);
138 verify(publisherTapiService, times(0)).sendEvent(any(), eq(notification.getTopic()));
142 void getTapiPublisherFromTopicTest() {
143 NbiNotificationsHandler listener = new NbiNotificationsHandler(Map.of("test", publisherService),
144 Map.of("test", publisherAlarm), Map.of("test", publisherTapiService));
145 assertNull(listener.getTapiPublisherFromTopic("toto"));
146 assertEquals(publisherTapiService, listener.getTapiPublisherFromTopic("test"));