Merge "Device Renderer to support transponder for B100G"
[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.test.AbstractTest;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
23 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationService;
24 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationServiceBuilder;
25
26 public class NbiNotificationsListenerImplTest extends AbstractTest {
27     @Mock
28     private Publisher publisher;
29
30     @Before
31     public void setUp() {
32         MockitoAnnotations.openMocks(this);
33     }
34
35     @Test
36     public void onPublishNotificationServiceTest() {
37         NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisher));
38         PublishNotificationService notification = new PublishNotificationServiceBuilder().setTopic("test")
39                 .setCommonId("commonId").setConnectionType(ConnectionType.Service).setMessage("Service deleted")
40                 .setOperationalState(State.OutOfService).setServiceName("service name").build();
41         listener.onPublishNotificationService(notification);
42         verify(publisher, times(1)).sendEvent(any());
43     }
44
45     @Test
46     public void onPublishNotificationServiceWrongTopicTest() {
47         NbiNotificationsListenerImpl listener = new NbiNotificationsListenerImpl(Map.of("test", publisher));
48         PublishNotificationService notification = new PublishNotificationServiceBuilder().setTopic("wrongtopic")
49                 .setCommonId("commonId").setConnectionType(ConnectionType.Service).setMessage("Service deleted")
50                 .setOperationalState(State.OutOfService).setServiceName("service name").build();
51         listener.onPublishNotificationService(notification);
52         verify(publisher, times(0)).sendEvent(any());
53     }
54 }