Remove NormalizedNodeInputOutput and related classes
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / BindingDOMDataTreeChangeServiceAdapterTest.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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.controller.md.sal.binding.impl;
9
10 import static org.mockito.AdditionalMatchers.not;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.ArgumentMatchers.isA;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.reset;
15 import static org.mockito.Mockito.verify;
16
17 import java.util.Collection;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.ArgumentMatchers;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
24 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
25 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeService;
26 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
27 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
28 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
29 import org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener;
30 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
31 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
32 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
33 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
34 import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
36 import org.opendaylight.yangtools.concepts.ListenerRegistration;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
39
40 /**
41  * Unit tests for BindingDOMDataTreeChangeServiceAdapter.
42  *
43  * @author Thomas Pantelis
44  */
45 @Deprecated
46 public class BindingDOMDataTreeChangeServiceAdapterTest {
47     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
48
49     @Mock
50     private DOMDataTreeChangeService mockDOMService;
51
52     @Mock
53     private GeneratedClassLoadingStrategy classLoadingStrategy;
54
55     @Mock
56     private BindingNormalizedNodeCodecRegistry codecRegistry;
57
58     @Mock
59     private YangInstanceIdentifier mockYangID;
60
61     @SuppressWarnings("rawtypes")
62     @Mock
63     private ListenerRegistration mockDOMReg;
64
65     @Before
66     public void setUp() {
67         MockitoAnnotations.initMocks(this);
68         doReturn(this.mockYangID).when(this.codecRegistry).toYangInstanceIdentifier(TOP_PATH);
69     }
70
71     @Test
72     public void testRegisterDataTreeChangeListener() {
73         final BindingToNormalizedNodeCodec codec =
74                 new BindingToNormalizedNodeCodec(this.classLoadingStrategy, this.codecRegistry);
75
76         final DataTreeChangeService service = BindingDOMDataTreeChangeServiceAdapter.create(codec, this.mockDOMService);
77
78         doReturn(this.mockDOMReg).when(this.mockDOMService).registerDataTreeChangeListener(
79                 domDataTreeIdentifier(this.mockYangID),
80                 any(DOMDataTreeChangeListener.class));
81         final DataTreeIdentifier<Top> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, TOP_PATH);
82         final TestClusteredDataTreeChangeListener mockClusteredListener = new TestClusteredDataTreeChangeListener();
83         service.registerDataTreeChangeListener(treeId , mockClusteredListener);
84
85         verify(this.mockDOMService).registerDataTreeChangeListener(domDataTreeIdentifier(this.mockYangID),
86                 isA(ClusteredDOMDataTreeChangeListener.class));
87
88         reset(this.mockDOMService);
89         doReturn(this.mockDOMReg).when(this.mockDOMService).registerDataTreeChangeListener(
90                 domDataTreeIdentifier(this.mockYangID), any(DOMDataTreeChangeListener.class));
91         final TestDataTreeChangeListener mockNonClusteredListener = new TestDataTreeChangeListener();
92         service.registerDataTreeChangeListener(treeId , mockNonClusteredListener);
93
94         verify(this.mockDOMService).registerDataTreeChangeListener(domDataTreeIdentifier(this.mockYangID),
95                 not(isA(ClusteredDOMDataTreeChangeListener.class)));
96     }
97
98     static DOMDataTreeIdentifier domDataTreeIdentifier(final YangInstanceIdentifier yangID) {
99         return ArgumentMatchers.argThat(treeId -> treeId.getDatastoreType() == LogicalDatastoreType.CONFIGURATION
100                         && yangID.equals(treeId.getRootIdentifier()));
101     }
102
103     @Deprecated
104     private static class TestClusteredDataTreeChangeListener implements ClusteredDataTreeChangeListener<Top> {
105         @Override
106         public void onDataTreeChanged(final Collection<DataTreeModification<Top>> changes) {
107         }
108     }
109
110     @Deprecated
111     private static class TestDataTreeChangeListener implements DataTreeChangeListener<Top> {
112         @Override
113         public void onDataTreeChanged(final Collection<DataTreeModification<Top>> changes) {
114         }
115     }
116 }

©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.