Adjust to yangtools-2.0.0/odlparent-3.0.0 changes
[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
9 package org.opendaylight.netconf.sal.connect.netconf.sal;
10
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;
15
16 import java.net.URI;
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
23 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
24 import org.opendaylight.yangtools.concepts.ListenerRegistration;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
27
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         MockitoAnnotations.initMocks(this);
46         final SchemaPath path1 = SchemaPath.create(true, QName.create(new URI("namespace1"), "path1"));
47         final SchemaPath path2 = SchemaPath.create(true, QName.create(new URI("namespace2"), "path2"));
48         service = new NetconfDeviceNotificationService();
49         service.registerNotificationListener(listener1, path1);
50         registration = service.registerNotificationListener(listener2, path2);
51
52         doReturn(path1).when(notification1).getType();
53         doReturn(path2).when(notification2).getType();
54
55     }
56
57     @Test
58     public void testPublishNotification() throws Exception {
59
60         service.publishNotification(notification1);
61         verify(listener1).onNotification(notification1);
62         verify(listener2, never()).onNotification(notification1);
63
64         service.publishNotification(notification2);
65         verify(listener2).onNotification(notification2);
66         verify(listener1, never()).onNotification(notification2);
67     }
68
69     @Test
70     public void testCloseRegistration() throws Exception {
71         service.publishNotification(notification2);
72         Assert.assertEquals(listener2, registration.getInstance());
73         registration.close();
74         service.publishNotification(notification2);
75         verify(listener2, times(1)).onNotification(notification2);
76     }
77 }