2 * Copyright (c) 2016 Cisco Systems, 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.netconf.client.mdsal.spi;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.never;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
16 import org.junit.jupiter.api.BeforeEach;
17 import org.junit.jupiter.api.Test;
18 import org.junit.jupiter.api.extension.ExtendWith;
19 import org.mockito.Mock;
20 import org.mockito.junit.jupiter.MockitoExtension;
21 import org.opendaylight.mdsal.dom.api.DOMNotification;
22 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
23 import org.opendaylight.yangtools.concepts.ListenerRegistration;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
27 @ExtendWith(MockitoExtension.class)
28 class NetconfDeviceNotificationServiceTest {
29 private static final Absolute PATH1 = Absolute.of(QName.create("namespace1", "path1"));
30 private static final Absolute PATH2 = Absolute.of(QName.create("namespace2", "path2"));
33 private DOMNotificationListener listener1;
35 private DOMNotificationListener listener2;
37 private DOMNotification notification1;
39 private DOMNotification notification2;
41 private final NetconfDeviceNotificationService service = new NetconfDeviceNotificationService();
42 private ListenerRegistration<DOMNotificationListener> registration;
45 void beforeEach() throws Exception {
46 service.registerNotificationListener(listener1, PATH1);
47 registration = service.registerNotificationListener(listener2, PATH2);
49 doReturn(PATH2).when(notification2).getType();
53 void testPublishNotification() throws Exception {
54 doReturn(PATH1).when(notification1).getType();
56 service.publishNotification(notification1);
57 verify(listener1).onNotification(notification1);
58 verify(listener2, never()).onNotification(notification1);
60 service.publishNotification(notification2);
61 verify(listener2).onNotification(notification2);
62 verify(listener1, never()).onNotification(notification2);
66 void testCloseRegistration() throws Exception {
67 service.publishNotification(notification2);
68 assertEquals(listener2, registration.getInstance());
70 service.publishNotification(notification2);
71 verify(listener2, times(1)).onNotification(notification2);