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.rev190531.ConnectionType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
24 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationAlarmService;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationService;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationAlarmService;
27 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationAlarmServiceBuilder;
28 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationService;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationServiceBuilder;
31 public class NbiNotificationsListenerImplTest extends AbstractTest {
33 private Publisher<NotificationService> 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 PublishNotificationService notification = new PublishNotificationServiceBuilder().setTopic("test")
47 .setCommonId("commonId").setConnectionType(ConnectionType.Service).setMessage("Service deleted")
48 .setOperationalState(State.OutOfService).setServiceName("service name").build();
49 listener.onPublishNotificationService(notification);
50 verify(publisherService, times(1)).sendEvent(any(), anyString());
54 public void onPublishNotificationServiceWrongTopicTest() {
55 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
56 Map.of("test", publisherAlarm));
57 PublishNotificationService notification = new PublishNotificationServiceBuilder().setTopic("wrongtopic")
58 .setCommonId("commonId").setConnectionType(ConnectionType.Service).setMessage("Service deleted")
59 .setOperationalState(State.OutOfService).setServiceName("service name").build();
60 listener.onPublishNotificationService(notification);
61 verify(publisherService, times(0)).sendEvent(any(), anyString());
65 public void onPublishNotificationAlarmServiceTest() {
66 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
67 Map.of("test", publisherAlarm));
68 PublishNotificationAlarmService notification = new PublishNotificationAlarmServiceBuilder().setTopic("test")
69 .setConnectionType(ConnectionType.Service).setMessage("The service is now inService")
70 .setOperationalState(State.OutOfService).setServiceName("service name").build();
71 listener.onPublishNotificationAlarmService(notification);
72 verify(publisherAlarm, times(1)).sendEvent(any(), anyString());
76 public void onPublishNotificationAlarmServiceWrongTopicTest() {
77 NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisherService),
78 Map.of("test", publisherAlarm));
79 PublishNotificationAlarmService notification = new PublishNotificationAlarmServiceBuilder()
80 .setTopic("wrongtopic").setConnectionType(ConnectionType.Service)
81 .setMessage("The service is now inService").setOperationalState(State.OutOfService)
82 .setServiceName("service name").build();
83 listener.onPublishNotificationAlarmService(notification);
84 verify(publisherAlarm, times(0)).sendEvent(any(), anyString());