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.mdsal.notification.impl;
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;
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.Captor;
20 import org.mockito.Mock;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.mdsal.binding.api.DataBroker;
23 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
24 import org.opendaylight.mdsal.binding.api.DataTreeModification;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.yangtools.yang.binding.ChildOf;
27 import org.opendaylight.yangtools.yang.binding.DataRoot;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 @RunWith(MockitoJUnitRunner.StrictStubs.class)
31 public class OperationalDatastoreListenerTest {
33 private DataBroker dataBroker;
35 private ArgumentCaptor<DataTreeIdentifier<?>> argumentId;
38 public void testDataStoreListener() {
39 final InstanceIdentifier<TestInterface> instanceIdentifier = InstanceIdentifier.create(TestInterface.class);
41 final var op = new OperationalDatastoreListener<>(instanceIdentifier) {
43 public void onDataTreeChanged(final Collection<DataTreeModification<TestInterface>> collection) {
47 doReturn(null).when(dataBroker).registerDataTreeChangeListener(any(), any());
49 op.registerOnChanges(dataBroker);
50 verify(dataBroker).registerDataTreeChangeListener(argumentId.capture(), any());
52 assertEquals(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier),
53 argumentId.getValue());
56 interface TestInterface extends ChildOf<DataRoot> {
58 default Class<TestInterface> implementedInterface() {
59 return TestInterface.class;