f8a95b73cc7ab6f1f658f69f1bd460b929e5321d
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / BindingDOMDataBrokerAdapterTest.java
1 /*
2  * Copyright (c) 2015 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.md.sal.binding.impl.test;
10
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.mockito.ArgumentCaptor;
14 import org.mockito.Mock;
15 import org.mockito.Mockito;
16 import org.mockito.MockitoAnnotations;
17 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataChangeListener;
18 import org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter;
19 import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
20 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
21 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
24 import org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataChangeListener;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
26 import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
27 import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
28 import org.opendaylight.yangtools.yang.binding.DataObject;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
31
32
33 public class BindingDOMDataBrokerAdapterTest {
34
35     @Mock
36     DOMDataBroker dataBroker;
37
38     @Mock
39     GeneratedClassLoadingStrategy classLoadingStrategy;
40     @Mock
41     BindingNormalizedNodeCodecRegistry codecRegistry;
42
43     @Mock
44     YangInstanceIdentifier yangInstanceIdentifier;
45
46
47     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier
48         .create(Top.class);
49
50     @Before
51     public void setUp() {
52         MockitoAnnotations.initMocks(this);
53     }
54
55     @Test
56     public void testClusteredDataChangeListernerRegisteration() {
57
58         BindingToNormalizedNodeCodec codec = new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry);
59
60         try (BindingDOMDataBrokerAdapter bindingDOMDataBrokerAdapter = new BindingDOMDataBrokerAdapter(dataBroker,
61                 codec)) {
62             Mockito.when(codecRegistry.toYangInstanceIdentifier(TOP_PATH)).thenReturn(yangInstanceIdentifier);
63
64             ArgumentCaptor<ClusteredDOMDataChangeListener> clusteredDOMListener = ArgumentCaptor
65                     .forClass(ClusteredDOMDataChangeListener.class);
66             ArgumentCaptor<LogicalDatastoreType> logicalDatastoreType = ArgumentCaptor
67                     .forClass(LogicalDatastoreType.class);
68             ArgumentCaptor<AsyncDataBroker.DataChangeScope> dataChangeScope = ArgumentCaptor
69                     .forClass(AsyncDataBroker.DataChangeScope.class);
70             ArgumentCaptor<YangInstanceIdentifier> yangInstanceIdentifier = ArgumentCaptor
71                     .forClass(YangInstanceIdentifier.class);
72
73             TestListener listener = new TestListener();
74
75             bindingDOMDataBrokerAdapter.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, TOP_PATH,
76                     listener, AsyncDataBroker.DataChangeScope.BASE);
77             Mockito.verify(dataBroker).registerDataChangeListener(logicalDatastoreType.capture(),
78                     yangInstanceIdentifier.capture(), clusteredDOMListener.capture(), dataChangeScope.capture());
79         }
80
81     }
82
83     private class TestListener implements ClusteredDataChangeListener {
84
85         @Override
86         public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
87
88         }
89     }
90 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.