bc0a2fa8ff4b0c84127f7ac42fd52c32868c096a
[netconf.git] / netconf / mdsal-netconf-notification / src / test / java / org / opendaylight / controller / config / yang / netconf / mdsal / notification / 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
9 package org.opendaylight.controller.config.yang.netconf.mdsal.notification;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.verify;
15
16 import java.util.Collection;
17 import javax.annotation.Nonnull;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.ArgumentCaptor;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.mdsal.binding.api.DataBroker;
24 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28
29 public class OperationalDatastoreListenerTest {
30
31     @Mock
32     private DataBroker dataBroker;
33
34     @Before
35     public void setUp() throws Exception {
36         MockitoAnnotations.initMocks(this);
37     }
38
39     @Test
40     public void testDataStoreListener() {
41         final InstanceIdentifier<DataObject> instanceIdentifier = InstanceIdentifier.create(DataObject.class);
42         final DataTreeIdentifier<DataObject> testId =
43                 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
44
45         final OperationalDatastoreListener<DataObject> op =
46                 new OperationalDatastoreListener<DataObject>(instanceIdentifier) {
47             @Override
48             public void onDataTreeChanged(@Nonnull final Collection collection) {
49             }
50         };
51         doReturn(null).when(dataBroker).registerDataTreeChangeListener(any(), any());
52
53         ArgumentCaptor<DataTreeIdentifier> argumentId = ArgumentCaptor.forClass(DataTreeIdentifier.class);
54         op.registerOnChanges(dataBroker);
55         verify(dataBroker).registerDataTreeChangeListener(argumentId.capture(), any());
56
57         assertEquals(testId, argumentId.getValue());
58
59     }
60
61 }