Add service listener to notify Kafka
[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.Mockito.times;
12 import static org.mockito.Mockito.verify;
13
14 import java.util.Map;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mock;
18 import org.mockito.MockitoAnnotations;
19 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
20 import org.opendaylight.transportpce.nbinotifications.producer.PublisherAlarm;
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.PublishNotificationService;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationServiceBuilder;
26
27 public class NbiNotificationsListenerImplTest extends AbstractTest {
28     @Mock
29     private Publisher publisher;
30     @Mock
31     private PublisherAlarm publisherAlarm;
32
33     @Before
34     public void setUp() {
35         MockitoAnnotations.openMocks(this);
36     }
37
38     @Test
39     public void onPublishNotificationServiceTest() {
40         NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisher),
41                 Map.of("test", publisherAlarm));
42         PublishNotificationService notification = new PublishNotificationServiceBuilder().setTopic("test")
43                 .setCommonId("commonId").setConnectionType(ConnectionType.Service).setMessage("Service deleted")
44                 .setOperationalState(State.OutOfService).setServiceName("service name").build();
45         listener.onPublishNotificationService(notification);
46         verify(publisher, times(1)).sendEvent(any());
47     }
48
49     @Test
50     public void onPublishNotificationServiceWrongTopicTest() {
51         NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisher),
52                 Map.of("test", publisherAlarm));
53         PublishNotificationService notification = new PublishNotificationServiceBuilder().setTopic("wrongtopic")
54                 .setCommonId("commonId").setConnectionType(ConnectionType.Service).setMessage("Service deleted")
55                 .setOperationalState(State.OutOfService).setServiceName("service name").build();
56         listener.onPublishNotificationService(notification);
57         verify(publisher, times(0)).sendEvent(any());
58     }
59 }