X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fmessagebus-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmessagebus%2Feventsources%2Fnetconf%2FNetconfEventSourceManagerTest.java;h=2ae7de25eee22e55d0ab04929c8c4e81befa0a1f;hp=d592a8041d874a1b142866efc739717cc521f7b2;hb=refs%2Fchanges%2F13%2F23413%2F26;hpb=071a641d7c12c0e6112d5ce0afe806b54f116ed2 diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java index d592a8041d..2ae7de25ee 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java @@ -1,177 +1,177 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.messagebus.eventsources.netconf; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.notNull; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.controller.config.yang.messagebus.app.impl.NamespaceToStream; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.MountPoint; -import org.opendaylight.controller.md.sal.binding.api.MountPointService; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; -import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; -import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; -import org.opendaylight.controller.messagebus.app.impl.EventSourceTopology; -import org.opendaylight.controller.messagebus.spi.EventSource; -import org.opendaylight.controller.messagebus.spi.EventSourceRegistration; -import org.opendaylight.controller.messagebus.spi.EventSourceRegistry; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeFields.ConnectionStatus; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; - -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; - -public class NetconfEventSourceManagerTest { - - NetconfEventSourceManager netconfEventSourceManager; - ListenerRegistration listenerRegistrationMock; - DOMMountPointService domMountPointServiceMock; - MountPointService mountPointServiceMock; - EventSourceTopology eventSourceTopologyMock; - AsyncDataChangeEvent asyncDataChangeEventMock; - RpcProviderRegistry rpcProviderRegistryMock; - EventSourceRegistry eventSourceRegistry; - @BeforeClass - public static void initTestClass() throws IllegalAccessException, InstantiationException { - } - - @Before - public void setUp() throws Exception { - DataBroker dataBrokerMock = mock(DataBroker.class); - DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class); - domMountPointServiceMock = mock(DOMMountPointService.class); - mountPointServiceMock = mock(MountPointService.class); - eventSourceTopologyMock = mock(EventSourceTopology.class); - rpcProviderRegistryMock = mock(RpcProviderRegistry.class); - eventSourceRegistry = mock(EventSourceRegistry.class); - List namespaceToStreamList = new ArrayList<>(); - - listenerRegistrationMock = mock(ListenerRegistration.class); - doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataChangeListener(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(NetconfEventSourceManager.class), eq(AsyncDataBroker.DataChangeScope.SUBTREE)); - - Optional optionalDomMountServiceMock = (Optional) mock(Optional.class); - doReturn(true).when(optionalDomMountServiceMock).isPresent(); - doReturn(optionalDomMountServiceMock).when(domMountPointServiceMock).getMountPoint((YangInstanceIdentifier)notNull()); - - DOMMountPoint domMountPointMock = mock(DOMMountPoint.class); - doReturn(domMountPointMock).when(optionalDomMountServiceMock).get(); - - - Optional optionalBindingMountMock = mock(Optional.class); - doReturn(true).when(optionalBindingMountMock).isPresent(); - - MountPoint mountPointMock = mock(MountPoint.class); - doReturn(optionalBindingMountMock).when(mountPointServiceMock).getMountPoint(any(InstanceIdentifier.class)); - doReturn(mountPointMock).when(optionalBindingMountMock).get(); - - Optional optionalMpDataBroker = mock(Optional.class); - DataBroker mpDataBroker = mock(DataBroker.class); - doReturn(optionalMpDataBroker).when(mountPointMock).getService(DataBroker.class); - doReturn(true).when(optionalMpDataBroker).isPresent(); - doReturn(mpDataBroker).when(optionalMpDataBroker).get(); - - ReadOnlyTransaction rtx = mock(ReadOnlyTransaction.class); - doReturn(rtx).when(mpDataBroker).newReadOnlyTransaction(); - CheckedFuture, ReadFailedException> checkFeature = (CheckedFuture, ReadFailedException>)mock(CheckedFuture.class); - InstanceIdentifier pathStream = InstanceIdentifier.builder(Netconf.class).child(Streams.class).build(); - doReturn(checkFeature).when(rtx).read(LogicalDatastoreType.OPERATIONAL, pathStream); - Optional avStreams = NetconfTestUtils.getAvailableStream("stream01", true); - doReturn(avStreams).when(checkFeature).checkedGet(); - - EventSourceRegistration esrMock = mock(EventSourceRegistration.class); - - netconfEventSourceManager = - NetconfEventSourceManager.create(dataBrokerMock, - domNotificationPublishServiceMock, - domMountPointServiceMock, - mountPointServiceMock, - eventSourceRegistry, - namespaceToStreamList); - } - - @Test - public void onDataChangedCreateEventSourceTestByCreateEntry() throws Exception { - onDataChangedTestHelper(true,false,true,NetconfTestUtils.notification_capability_prefix); - netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); - verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class)); - } - - @Test - public void onDataChangedCreateEventSourceTestByUpdateEntry() throws Exception { - onDataChangedTestHelper(false,true,true, NetconfTestUtils.notification_capability_prefix); - netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); - verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class)); - } - - @Test - public void onDataChangedCreateEventSourceTestNotNeconf() throws Exception { - onDataChangedTestHelper(false,true,false,NetconfTestUtils.notification_capability_prefix); - netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); - verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class)); - } - - @Test - public void onDataChangedCreateEventSourceTestNotNotificationCapability() throws Exception { - onDataChangedTestHelper(true,false,true,"bad-prefix"); - netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); - verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class)); - } - - private void onDataChangedTestHelper(boolean create, boolean update, boolean isNetconf, String notificationCapabilityPrefix) throws Exception{ - asyncDataChangeEventMock = mock(AsyncDataChangeEvent.class); - Map mapCreate = new HashMap<>(); - Map mapUpdate = new HashMap<>(); - - Node node01; - String nodeId = "Node01"; - doReturn(mapCreate).when(asyncDataChangeEventMock).getCreatedData(); - doReturn(mapUpdate).when(asyncDataChangeEventMock).getUpdatedData(); - - if(isNetconf){ - node01 = NetconfTestUtils.getNetconfNode(nodeId, "node01.test.local", ConnectionStatus.Connected, notificationCapabilityPrefix); - - } else { - node01 = NetconfTestUtils.getNode(nodeId); - } - - if(create){ - mapCreate.put(NetconfTestUtils.getInstanceIdentifier(node01), node01); - } - if(update){ - mapUpdate.put(NetconfTestUtils.getInstanceIdentifier(node01), node01); - } - - } - -} \ No newline at end of file +///* +// * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. +// * +// * This program and the accompanying materials are made available under the +// * terms of the Eclipse Public License v1.0 which accompanies this distribution, +// * and is available at http://www.eclipse.org/legal/epl-v10.html +// */ +//package org.opendaylight.controller.messagebus.eventsources.netconf; +// +//import static org.mockito.Matchers.any; +//import static org.mockito.Matchers.eq; +//import static org.mockito.Matchers.notNull; +//import static org.mockito.Mockito.doReturn; +//import static org.mockito.Mockito.mock; +//import static org.mockito.Mockito.times; +//import static org.mockito.Mockito.verify; +// +//import java.util.ArrayList; +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +// +//import org.junit.Before; +//import org.junit.BeforeClass; +//import org.junit.Test; +//import org.opendaylight.controller.config.yang.messagebus.app.impl.NamespaceToStream; +//import org.opendaylight.controller.md.sal.binding.api.DataBroker; +//import org.opendaylight.controller.md.sal.binding.api.MountPoint; +//import org.opendaylight.controller.md.sal.binding.api.MountPointService; +//import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +//import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; +//import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; +//import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +//import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +//import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; +//import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; +//import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; +//import org.opendaylight.controller.messagebus.app.impl.EventSourceTopology; +//import org.opendaylight.controller.messagebus.spi.EventSource; +//import org.opendaylight.controller.messagebus.spi.EventSourceRegistration; +//import org.opendaylight.controller.messagebus.spi.EventSourceRegistry; +//import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf; +//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams; +//import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeFields.ConnectionStatus; +//import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +//import org.opendaylight.yangtools.concepts.ListenerRegistration; +//import org.opendaylight.yangtools.yang.binding.DataObject; +//import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +//import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +// +//import com.google.common.base.Optional; +//import com.google.common.util.concurrent.CheckedFuture; +// +//public class NetconfEventSourceManagerTest { +// +// NetconfEventSourceManager netconfEventSourceManager; +// ListenerRegistration listenerRegistrationMock; +// DOMMountPointService domMountPointServiceMock; +// MountPointService mountPointServiceMock; +// EventSourceTopology eventSourceTopologyMock; +// AsyncDataChangeEvent asyncDataChangeEventMock; +// RpcProviderRegistry rpcProviderRegistryMock; +// EventSourceRegistry eventSourceRegistry; +// @BeforeClass +// public static void initTestClass() throws IllegalAccessException, InstantiationException { +// } +// +// @Before +// public void setUp() throws Exception { +// DataBroker dataBrokerMock = mock(DataBroker.class); +// DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class); +// domMountPointServiceMock = mock(DOMMountPointService.class); +// mountPointServiceMock = mock(MountPointService.class); +// eventSourceTopologyMock = mock(EventSourceTopology.class); +// rpcProviderRegistryMock = mock(RpcProviderRegistry.class); +// eventSourceRegistry = mock(EventSourceRegistry.class); +// List namespaceToStreamList = new ArrayList<>(); +// +// listenerRegistrationMock = mock(ListenerRegistration.class); +// doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataChangeListener(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(NetconfEventSourceManager.class), eq(AsyncDataBroker.DataChangeScope.SUBTREE)); +// +// Optional optionalDomMountServiceMock = (Optional) mock(Optional.class); +// doReturn(true).when(optionalDomMountServiceMock).isPresent(); +// doReturn(optionalDomMountServiceMock).when(domMountPointServiceMock).getMountPoint((YangInstanceIdentifier)notNull()); +// +// DOMMountPoint domMountPointMock = mock(DOMMountPoint.class); +// doReturn(domMountPointMock).when(optionalDomMountServiceMock).get(); +// +// +// Optional optionalBindingMountMock = mock(Optional.class); +// doReturn(true).when(optionalBindingMountMock).isPresent(); +// +// MountPoint mountPointMock = mock(MountPoint.class); +// doReturn(optionalBindingMountMock).when(mountPointServiceMock).getMountPoint(any(InstanceIdentifier.class)); +// doReturn(mountPointMock).when(optionalBindingMountMock).get(); +// +// Optional optionalMpDataBroker = mock(Optional.class); +// DataBroker mpDataBroker = mock(DataBroker.class); +// doReturn(optionalMpDataBroker).when(mountPointMock).getService(DataBroker.class); +// doReturn(true).when(optionalMpDataBroker).isPresent(); +// doReturn(mpDataBroker).when(optionalMpDataBroker).get(); +// +// ReadOnlyTransaction rtx = mock(ReadOnlyTransaction.class); +// doReturn(rtx).when(mpDataBroker).newReadOnlyTransaction(); +// CheckedFuture, ReadFailedException> checkFeature = (CheckedFuture, ReadFailedException>)mock(CheckedFuture.class); +// InstanceIdentifier pathStream = InstanceIdentifier.builder(Netconf.class).child(Streams.class).build(); +// doReturn(checkFeature).when(rtx).read(LogicalDatastoreType.OPERATIONAL, pathStream); +// Optional avStreams = NetconfTestUtils.getAvailableStream("stream01", true); +// doReturn(avStreams).when(checkFeature).checkedGet(); +// +// EventSourceRegistration esrMock = mock(EventSourceRegistration.class); +// +// netconfEventSourceManager = +// NetconfEventSourceManager.create(dataBrokerMock, +// domNotificationPublishServiceMock, +// domMountPointServiceMock, +// mountPointServiceMock, +// eventSourceRegistry, +// namespaceToStreamList); +// } +// +// @Test +// public void onDataChangedCreateEventSourceTestByCreateEntry() throws Exception { +// onDataChangedTestHelper(true,false,true,NetconfTestUtils.notification_capability_prefix); +// netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); +// verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class)); +// } +// +// @Test +// public void onDataChangedCreateEventSourceTestByUpdateEntry() throws Exception { +// onDataChangedTestHelper(false,true,true, NetconfTestUtils.notification_capability_prefix); +// netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); +// verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class)); +// } +// +// @Test +// public void onDataChangedCreateEventSourceTestNotNeconf() throws Exception { +// onDataChangedTestHelper(false,true,false,NetconfTestUtils.notification_capability_prefix); +// netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); +// verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class)); +// } +// +// @Test +// public void onDataChangedCreateEventSourceTestNotNotificationCapability() throws Exception { +// onDataChangedTestHelper(true,false,true,"bad-prefix"); +// netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); +// verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class)); +// } +// +// private void onDataChangedTestHelper(boolean create, boolean update, boolean isNetconf, String notificationCapabilityPrefix) throws Exception{ +// asyncDataChangeEventMock = mock(AsyncDataChangeEvent.class); +// Map mapCreate = new HashMap<>(); +// Map mapUpdate = new HashMap<>(); +// +// Node node01; +// String nodeId = "Node01"; +// doReturn(mapCreate).when(asyncDataChangeEventMock).getCreatedData(); +// doReturn(mapUpdate).when(asyncDataChangeEventMock).getUpdatedData(); +// +// if(isNetconf){ +// node01 = NetconfTestUtils.getNetconfNode(nodeId, "node01.test.local", ConnectionStatus.Connected, notificationCapabilityPrefix); +// +// } else { +// node01 = NetconfTestUtils.getNode(nodeId); +// } +// +// if(create){ +// mapCreate.put(NetconfTestUtils.getInstanceIdentifier(node01), node01); +// } +// if(update){ +// mapUpdate.put(NetconfTestUtils.getInstanceIdentifier(node01), node01); +// } +// +// } +// +//} \ No newline at end of file