Bump upstreams
[netconf.git] / plugins / netconf-client-mdsal / src / test / java / org / opendaylight / netconf / client / mdsal / spi / NetconfDeviceNotificationServiceTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, 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.netconf.client.mdsal.spi;
9
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;
14
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;
25
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"));
30
31     @Mock
32     private DOMNotificationListener listener1;
33     @Mock
34     private DOMNotificationListener listener2;
35     @Mock
36     private DOMNotification notification1;
37     @Mock
38     private DOMNotification notification2;
39
40     private final NetconfDeviceNotificationService service = new NetconfDeviceNotificationService();
41     private Registration registration;
42
43     @BeforeEach
44     void beforeEach() throws Exception {
45         service.registerNotificationListener(listener1, PATH1);
46         registration = service.registerNotificationListener(listener2, PATH2);
47
48         doReturn(PATH2).when(notification2).getType();
49     }
50
51     @Test
52     void testPublishNotification() throws Exception {
53         doReturn(PATH1).when(notification1).getType();
54
55         service.publishNotification(notification1);
56         verify(listener1).onNotification(notification1);
57         verify(listener2, never()).onNotification(notification1);
58
59         service.publishNotification(notification2);
60         verify(listener2).onNotification(notification2);
61         verify(listener1, never()).onNotification(notification2);
62     }
63
64     @Test
65     void testCloseRegistration() throws Exception {
66         service.publishNotification(notification2);
67         registration.close();
68         service.publishNotification(notification2);
69         verify(listener2, times(1)).onNotification(notification2);
70     }
71 }