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.mockito.Mockito.doReturn;
11 import static org.mockito.Mockito.never;
12 import static org.mockito.Mockito.times;
13 import static org.mockito.Mockito.verify;
15 import org.junit.jupiter.api.BeforeEach;
16 import org.junit.jupiter.api.Test;
17 import org.junit.jupiter.api.extension.ExtendWith;
18 import org.mockito.Mock;
19 import org.mockito.junit.jupiter.MockitoExtension;
20 import org.opendaylight.mdsal.dom.api.DOMNotification;
21 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
22 import org.opendaylight.yangtools.concepts.Registration;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
26 @ExtendWith(MockitoExtension.class)
27 class NetconfDeviceNotificationServiceTest {
28 private static final Absolute PATH1 = Absolute.of(QName.create("namespace1", "path1"));
29 private static final Absolute PATH2 = Absolute.of(QName.create("namespace2", "path2"));
32 private DOMNotificationListener listener1;
34 private DOMNotificationListener listener2;
36 private DOMNotification notification1;
38 private DOMNotification notification2;
40 private final NetconfDeviceNotificationService service = new NetconfDeviceNotificationService();
41 private Registration registration;
44 void beforeEach() throws Exception {
45 service.registerNotificationListener(listener1, PATH1);
46 registration = service.registerNotificationListener(listener2, PATH2);
48 doReturn(PATH2).when(notification2).getType();
52 void testPublishNotification() throws Exception {
53 doReturn(PATH1).when(notification1).getType();
55 service.publishNotification(notification1);
56 verify(listener1).onNotification(notification1);
57 verify(listener2, never()).onNotification(notification1);
59 service.publishNotification(notification2);
60 verify(listener2).onNotification(notification2);
61 verify(listener1, never()).onNotification(notification2);
65 void testCloseRegistration() throws Exception {
66 service.publishNotification(notification2);
68 service.publishNotification(notification2);
69 verify(listener2, times(1)).onNotification(notification2);