Decouple config and netconf subsystems.
[controller.git] / opendaylight / md-sal / messagebus-impl / src / test / java / org / opendaylight / controller / messagebus / eventsources / netconf / NetconfEventSourceManagerTest.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 //package org.opendaylight.controller.messagebus.eventsources.netconf;
9 //
10 //import static org.mockito.Matchers.any;
11 //import static org.mockito.Matchers.eq;
12 //import static org.mockito.Matchers.notNull;
13 //import static org.mockito.Mockito.doReturn;
14 //import static org.mockito.Mockito.mock;
15 //import static org.mockito.Mockito.times;
16 //import static org.mockito.Mockito.verify;
17 //
18 //import java.util.ArrayList;
19 //import java.util.HashMap;
20 //import java.util.List;
21 //import java.util.Map;
22 //
23 //import org.junit.Before;
24 //import org.junit.BeforeClass;
25 //import org.junit.Test;
26 //import org.opendaylight.controller.config.yang.messagebus.app.impl.NamespaceToStream;
27 //import org.opendaylight.controller.md.sal.binding.api.DataBroker;
28 //import org.opendaylight.controller.md.sal.binding.api.MountPoint;
29 //import org.opendaylight.controller.md.sal.binding.api.MountPointService;
30 //import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
31 //import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
32 //import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
33 //import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
34 //import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
35 //import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
36 //import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
37 //import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
38 //import org.opendaylight.controller.messagebus.app.impl.EventSourceTopology;
39 //import org.opendaylight.controller.messagebus.spi.EventSource;
40 //import org.opendaylight.controller.messagebus.spi.EventSourceRegistration;
41 //import org.opendaylight.controller.messagebus.spi.EventSourceRegistry;
42 //import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
43 //import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf;
44 //import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams;
45 //import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeFields.ConnectionStatus;
46 //import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
47 //import org.opendaylight.yangtools.concepts.ListenerRegistration;
48 //import org.opendaylight.yangtools.yang.binding.DataObject;
49 //import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
50 //import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
51 //
52 //import com.google.common.base.Optional;
53 //import com.google.common.util.concurrent.CheckedFuture;
54 //
55 //public class NetconfEventSourceManagerTest {
56 //
57 //    NetconfEventSourceManager netconfEventSourceManager;
58 //    ListenerRegistration listenerRegistrationMock;
59 //    DOMMountPointService domMountPointServiceMock;
60 //    MountPointService mountPointServiceMock;
61 //    EventSourceTopology eventSourceTopologyMock;
62 //    AsyncDataChangeEvent asyncDataChangeEventMock;
63 //    RpcProviderRegistry rpcProviderRegistryMock;
64 //    EventSourceRegistry eventSourceRegistry;
65 //    @BeforeClass
66 //    public static void initTestClass() throws IllegalAccessException, InstantiationException {
67 //    }
68 //
69 //    @Before
70 //    public void setUp() throws Exception {
71 //        DataBroker dataBrokerMock = mock(DataBroker.class);
72 //        DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class);
73 //        domMountPointServiceMock = mock(DOMMountPointService.class);
74 //        mountPointServiceMock = mock(MountPointService.class);
75 //        eventSourceTopologyMock = mock(EventSourceTopology.class);
76 //        rpcProviderRegistryMock = mock(RpcProviderRegistry.class);
77 //        eventSourceRegistry = mock(EventSourceRegistry.class);
78 //        List<NamespaceToStream> namespaceToStreamList = new ArrayList<>();
79 //
80 //        listenerRegistrationMock = mock(ListenerRegistration.class);
81 //        doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataChangeListener(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(NetconfEventSourceManager.class), eq(AsyncDataBroker.DataChangeScope.SUBTREE));
82 //
83 //        Optional<DOMMountPoint> optionalDomMountServiceMock = (Optional<DOMMountPoint>) mock(Optional.class);
84 //        doReturn(true).when(optionalDomMountServiceMock).isPresent();
85 //        doReturn(optionalDomMountServiceMock).when(domMountPointServiceMock).getMountPoint((YangInstanceIdentifier)notNull());
86 //
87 //        DOMMountPoint domMountPointMock = mock(DOMMountPoint.class);
88 //        doReturn(domMountPointMock).when(optionalDomMountServiceMock).get();
89 //
90 //
91 //        Optional optionalBindingMountMock = mock(Optional.class);
92 //        doReturn(true).when(optionalBindingMountMock).isPresent();
93 //
94 //        MountPoint mountPointMock = mock(MountPoint.class);
95 //        doReturn(optionalBindingMountMock).when(mountPointServiceMock).getMountPoint(any(InstanceIdentifier.class));
96 //        doReturn(mountPointMock).when(optionalBindingMountMock).get();
97 //
98 //        Optional optionalMpDataBroker = mock(Optional.class);
99 //        DataBroker mpDataBroker = mock(DataBroker.class);
100 //        doReturn(optionalMpDataBroker).when(mountPointMock).getService(DataBroker.class);
101 //        doReturn(true).when(optionalMpDataBroker).isPresent();
102 //        doReturn(mpDataBroker).when(optionalMpDataBroker).get();
103 //
104 //        ReadOnlyTransaction rtx = mock(ReadOnlyTransaction.class);
105 //        doReturn(rtx).when(mpDataBroker).newReadOnlyTransaction();
106 //        CheckedFuture<Optional<Streams>, ReadFailedException> checkFeature = (CheckedFuture<Optional<Streams>, ReadFailedException>)mock(CheckedFuture.class);
107 //        InstanceIdentifier<Streams> pathStream = InstanceIdentifier.builder(Netconf.class).child(Streams.class).build();
108 //        doReturn(checkFeature).when(rtx).read(LogicalDatastoreType.OPERATIONAL, pathStream);
109 //        Optional<Streams> avStreams = NetconfTestUtils.getAvailableStream("stream01", true);
110 //        doReturn(avStreams).when(checkFeature).checkedGet();
111 //
112 //        EventSourceRegistration esrMock = mock(EventSourceRegistration.class);
113 //
114 //        netconfEventSourceManager =
115 //                NetconfEventSourceManager.create(dataBrokerMock,
116 //                        domNotificationPublishServiceMock,
117 //                        domMountPointServiceMock,
118 //                        mountPointServiceMock,
119 //                        eventSourceRegistry,
120 //                        namespaceToStreamList);
121 //    }
122 //
123 //    @Test
124 //    public void onDataChangedCreateEventSourceTestByCreateEntry() throws Exception {
125 //        onDataChangedTestHelper(true,false,true,NetconfTestUtils.notification_capability_prefix);
126 //        netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock);
127 //        verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class));
128 //    }
129 //
130 //    @Test
131 //    public void onDataChangedCreateEventSourceTestByUpdateEntry() throws Exception {
132 //        onDataChangedTestHelper(false,true,true, NetconfTestUtils.notification_capability_prefix);
133 //        netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock);
134 //        verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class));
135 //    }
136 //
137 //    @Test
138 //    public void onDataChangedCreateEventSourceTestNotNeconf() throws Exception {
139 //        onDataChangedTestHelper(false,true,false,NetconfTestUtils.notification_capability_prefix);
140 //        netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock);
141 //        verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class));
142 //    }
143 //
144 //    @Test
145 //    public void onDataChangedCreateEventSourceTestNotNotificationCapability() throws Exception {
146 //        onDataChangedTestHelper(true,false,true,"bad-prefix");
147 //        netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock);
148 //        verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class));
149 //    }
150 //
151 //    private void onDataChangedTestHelper(boolean create, boolean update, boolean isNetconf, String notificationCapabilityPrefix) throws Exception{
152 //        asyncDataChangeEventMock = mock(AsyncDataChangeEvent.class);
153 //        Map<InstanceIdentifier, DataObject> mapCreate = new HashMap<>();
154 //        Map<InstanceIdentifier, DataObject> mapUpdate = new HashMap<>();
155 //
156 //        Node node01;
157 //        String nodeId = "Node01";
158 //        doReturn(mapCreate).when(asyncDataChangeEventMock).getCreatedData();
159 //        doReturn(mapUpdate).when(asyncDataChangeEventMock).getUpdatedData();
160 //
161 //        if(isNetconf){
162 //            node01 = NetconfTestUtils.getNetconfNode(nodeId, "node01.test.local", ConnectionStatus.Connected, notificationCapabilityPrefix);
163 //
164 //        } else {
165 //            node01 = NetconfTestUtils.getNode(nodeId);
166 //        }
167 //
168 //        if(create){
169 //            mapCreate.put(NetconfTestUtils.getInstanceIdentifier(node01), node01);
170 //        }
171 //        if(update){
172 //            mapUpdate.put(NetconfTestUtils.getInstanceIdentifier(node01), node01);
173 //        }
174 //
175 //    }
176 //
177 //}