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.Mockito.times;
12 import static org.mockito.Mockito.verify;
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;
27 public class NbiNotificationsListenerImplTest extends AbstractTest {
29 private Publisher publisher;
31 private PublisherAlarm publisherAlarm;
35 MockitoAnnotations.openMocks(this);
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());
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());