Bump MRI upstreams
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / sal / 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.sal.connect.netconf.sal;
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.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.junit.MockitoJUnitRunner;
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;
26
27 @RunWith(MockitoJUnitRunner.StrictStubs.class)
28 public class NetconfDeviceNotificationServiceTest {
29
30     @Mock
31     private DOMNotificationListener listener1;
32     @Mock
33     private DOMNotificationListener listener2;
34     @Mock
35     private DOMNotification notification1;
36     @Mock
37     private DOMNotification notification2;
38
39     private NetconfDeviceNotificationService service;
40     private ListenerRegistration<DOMNotificationListener> registration;
41
42
43     @Before
44     public void setUp() throws Exception {
45         final Absolute path1 = Absolute.of(QName.create("namespace1", "path1"));
46         final Absolute path2 = Absolute.of(QName.create("namespace2", "path2"));
47         service = new NetconfDeviceNotificationService();
48         service.registerNotificationListener(listener1, path1);
49         registration = service.registerNotificationListener(listener2, path2);
50
51         doReturn(path1).when(notification1).getType();
52         doReturn(path2).when(notification2).getType();
53     }
54
55     @Test
56     public void testPublishNotification() throws Exception {
57
58         service.publishNotification(notification1);
59         verify(listener1).onNotification(notification1);
60         verify(listener2, never()).onNotification(notification1);
61
62         service.publishNotification(notification2);
63         verify(listener2).onNotification(notification2);
64         verify(listener1, never()).onNotification(notification2);
65     }
66
67     @Test
68     public void testCloseRegistration() throws Exception {
69         service.publishNotification(notification2);
70         Assert.assertEquals(listener2, registration.getInstance());
71         registration.close();
72         service.publishNotification(notification2);
73         verify(listener2, times(1)).onNotification(notification2);
74     }
75 }