Bump upstreams to SNAPSHOTs
[netconf.git] / netconf / mdsal-netconf-notification / src / test / java / org / opendaylight / netconf / mdsal / notification / impl / OperationalDatastoreListenerTest.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.mdsal.notification.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.verify;
14
15 import java.util.Collection;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.ArgumentCaptor;
19 import org.mockito.Mock;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.mdsal.binding.api.DataBroker;
22 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
23 import org.opendaylight.mdsal.binding.api.DataTreeModification;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.yangtools.yang.binding.ChildOf;
26 import org.opendaylight.yangtools.yang.binding.DataRoot;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28
29 @RunWith(MockitoJUnitRunner.StrictStubs.class)
30 public class OperationalDatastoreListenerTest {
31     @Mock
32     private DataBroker dataBroker;
33
34     @Test
35     public void testDataStoreListener() {
36         final InstanceIdentifier<TestInterface> instanceIdentifier = InstanceIdentifier.create(TestInterface.class);
37         final DataTreeIdentifier<TestInterface> testId =
38                 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
39
40         final var op = new OperationalDatastoreListener<>(instanceIdentifier) {
41             @Override
42             public void onDataTreeChanged(final Collection<DataTreeModification<TestInterface>> collection) {
43                 // no-op
44             }
45         };
46         doReturn(null).when(dataBroker).registerDataTreeChangeListener(any(), any());
47
48         ArgumentCaptor<DataTreeIdentifier> argumentId = ArgumentCaptor.forClass(DataTreeIdentifier.class);
49         op.registerOnChanges(dataBroker);
50         verify(dataBroker).registerDataTreeChangeListener(argumentId.capture(), any());
51
52         assertEquals(testId, argumentId.getValue());
53
54     }
55
56     interface TestInterface extends ChildOf<DataRoot> {
57         @Override
58         default Class<TestInterface> implementedInterface() {
59             return TestInterface.class;
60         }
61     }
62 }