1743723e6883853be8d9a3563d6fad0199953e23
[transportpce.git] / nbinotifications / src / test / java / org / opendaylight / transportpce / nbinotifications / listener / NbiNotificationsListenerImplTest.java
1 /*
2  * Copyright © 2021 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.nbinotifications.listener;
9
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;
14
15 import java.util.HashMap;
16 import java.util.Map;
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;
31
32 public class NbiNotificationsListenerImplTest extends AbstractTest {
33     @Mock
34     private Publisher<NotificationProcessService> publisherService;
35     @Mock
36     private Publisher<NotificationAlarmService> publisherAlarm;
37
38     @Before
39     public void setUp() {
40         MockitoAnnotations.openMocks(this);
41     }
42
43     @Test
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")
54                 .build();
55         listener.onPublishNotificationProcessService(notification);
56         verify(publisherService, times(1)).sendEvent(any(), anyString());
57     }
58
59     @Test
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")
70                 .build();
71         listener.onPublishNotificationProcessService(notification);
72         verify(publisherService, times(0)).sendEvent(any(), anyString());
73     }
74
75     @Test
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")
85                 .build();
86         listener.onPublishNotificationAlarmService(notification);
87         verify(publisherAlarm, times(1)).sendEvent(any(), anyString());
88     }
89
90     @Test
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")
100                 .build();
101         listener.onPublishNotificationAlarmService(notification);
102         verify(publisherAlarm, times(0)).sendEvent(any(), anyString());
103     }
104 }