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.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;
26 public class NbiNotificationsListenerImplTest extends AbstractTest {
28 private Publisher publisher;
32 MockitoAnnotations.openMocks(this);
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());
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());