From c9204fb5ecb0e5d842a9bc843198bbea6728bd57 Mon Sep 17 00:00:00 2001 From: Gilles Thouenon Date: Mon, 12 Apr 2021 09:07:38 +0200 Subject: [PATCH] Refactor (un)registration of device listeners - simplify the way to register/unregister node listeners, taking into acount the different device versions - adapt UT of NetConfTopologyListener class JIRA: TRNSPRTPCE-430 Signed-off-by: Gilles Thouenon Change-Id: Id8d1d04ac2f43035fb3de6e71d9a77a77a14faec --- .../networkmodel/NetConfTopologyListener.java | 139 +++--------------- .../networkmodel/dto/NodeRegistration.java | 120 ++++++++++----- .../networkmodel/dto/NodeRegistration22.java | 71 --------- .../NetConfTopologyListenerTest.java | 10 +- 4 files changed, 115 insertions(+), 225 deletions(-) delete mode 100644 networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration22.java diff --git a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java index 34d2a1ea8..43e4c64e4 100644 --- a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java +++ b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java @@ -7,6 +7,7 @@ */ package org.opendaylight.transportpce.networkmodel; +import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.ListenableFuture; import java.util.Collection; import java.util.Map; @@ -25,20 +26,7 @@ import org.opendaylight.transportpce.common.StringConstants; import org.opendaylight.transportpce.common.device.DeviceTransactionManager; import org.opendaylight.transportpce.common.mapping.PortMapping; import org.opendaylight.transportpce.networkmodel.dto.NodeRegistration; -import org.opendaylight.transportpce.networkmodel.dto.NodeRegistration22; -import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener; -import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener221; -import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener; -import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener221; -import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener121; -import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener221; -import org.opendaylight.transportpce.networkmodel.listeners.TcaListener; -import org.opendaylight.transportpce.networkmodel.listeners.TcaListener221; import org.opendaylight.transportpce.networkmodel.service.NetworkModelService; -import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev161014.OrgOpenroadmAlarmListener; -import org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev161014.OrgOpenroadmDeOperationsListener; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceListener; -import org.opendaylight.yang.gen.v1.http.org.openroadm.tca.rev161014.OrgOpenroadmTcaListener; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInputBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionOutput; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.NotificationsService; @@ -47,7 +35,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev15 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability; 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.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +47,6 @@ public class NetConfTopologyListener implements DataTreeChangeListener { private final DataBroker dataBroker; private final DeviceTransactionManager deviceTransactionManager; private final Map registrations; - private final Map registrations22; private final PortMapping portMapping; public NetConfTopologyListener(final NetworkModelService networkModelService, final DataBroker dataBroker, @@ -69,7 +55,6 @@ public class NetConfTopologyListener implements DataTreeChangeListener { this.dataBroker = dataBroker; this.deviceTransactionManager = deviceTransactionManager; this.registrations = new ConcurrentHashMap<>(); - this.registrations22 = new ConcurrentHashMap<>(); this.portMapping = portMapping; } @@ -85,13 +70,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener { switch (rootNode.getModificationType()) { case DELETE: this.networkModelService.deleteOpenRoadmnode(nodeId); - String deviceVersion = netconfNodeBefore - .getAvailableCapabilities().getAvailableCapability().stream() - .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME)) - .sorted((c1, c2) -> c1.getCapability().compareTo(c2.getCapability())) - .findFirst() - .get().getCapability(); - onDeviceDisConnected(nodeId, deviceVersion); + onDeviceDisConnected(nodeId); LOG.info("Device {} correctly disconnected from controller", nodeId); break; case WRITE: @@ -102,7 +81,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener { Optional deviceCapabilityOpt = netconfNodeAfter .getAvailableCapabilities().getAvailableCapability().stream() .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME)) - .sorted((c1, c2) -> c1.getCapability().compareTo(c2.getCapability())) + .sorted((c1, c2) -> c2.getCapability().compareTo(c1.getCapability())) .findFirst(); if (deviceCapabilityOpt.isEmpty()) { LOG.error("Unable to get openroadm-device-capability"); @@ -140,105 +119,18 @@ public class NetConfTopologyListener implements DataTreeChangeListener { LOG.error(RPC_SERVICE_FAILED, nodeId); return; } - switch (openRoadmVersion) { - case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1: - NodeRegistration node121Registration = registrateNode121Listeners(nodeId, notificationService.get()); - registrations.put(nodeId, node121Registration); - break; - case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1: - NodeRegistration22 node221Registration = registrateNode221Listeners(nodeId, notificationService.get()); - registrations22.put(nodeId, node221Registration); - break; - default: - break; - } + NodeRegistration nodeRegistration = new NodeRegistration(nodeId, openRoadmVersion, + notificationService.get(), this.dataBroker, this.portMapping); + nodeRegistration.registerListeners(); + registrations.put(nodeId, nodeRegistration); String streamName = "NETCONF"; subscribeStream(mountPoint, streamName, nodeId); } - private void onDeviceDisConnected(final String nodeId, String openRoadmVersion) { + private void onDeviceDisConnected(final String nodeId) { LOG.info("onDeviceDisConnected: {}", nodeId); - switch (openRoadmVersion) { - case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1: - NodeRegistration nodeRegistration = this.registrations.remove(nodeId); - if (nodeRegistration != null) { - nodeRegistration.getAccessAlarmNotificationListenerRegistration().close(); - nodeRegistration.getAccessDeOperationasNotificationListenerRegistration().close(); - nodeRegistration.getAccessDeviceNotificationListenerRegistration().close(); - nodeRegistration.getAccessTcaNotificationListenerRegistration().close(); - } - break; - case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1: - NodeRegistration22 nodeRegistration221 = this.registrations22.remove(nodeId); - if (nodeRegistration221 != null) { - nodeRegistration221.getAccessAlarmNotificationListenerRegistration().close(); - nodeRegistration221.getAccessDeOperationasNotificationListenerRegistration().close(); - nodeRegistration221.getAccessDeviceNotificationListenerRegistration().close(); - nodeRegistration221.getAccessTcaNotificationListenerRegistration().close(); - } - break; - default: - break; - } - } - - private NodeRegistration registrateNode121Listeners(String nodeId, NotificationService notificationService) { - final OrgOpenroadmAlarmListener alarmListener = new AlarmNotificationListener(this.dataBroker); - LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId); - final ListenerRegistration accessAlarmNotificationListenerRegistration = - notificationService.registerNotificationListener(alarmListener); - - final OrgOpenroadmDeOperationsListener deOperationsListener = new DeOperationsListener(); - LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId); - final ListenerRegistration - accessDeOperationasNotificationListenerRegistration = - notificationService.registerNotificationListener(deOperationsListener); - - final OrgOpenroadmDeviceListener deviceListener = new DeviceListener121(nodeId, this.portMapping); - LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId); - final ListenerRegistration accessDeviceNotificationListenerRegistration = - notificationService.registerNotificationListener(deviceListener); - - TcaListener tcaListener = new TcaListener(); - LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId); - final ListenerRegistration accessTcaNotificationListenerRegistration = - notificationService.registerNotificationListener(tcaListener); - return new NodeRegistration(nodeId, accessAlarmNotificationListenerRegistration, - accessDeOperationasNotificationListenerRegistration, accessDeviceNotificationListenerRegistration, - null, accessTcaNotificationListenerRegistration); - } - - private NodeRegistration22 registrateNode221Listeners(String nodeId, NotificationService notificationService) { - final org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev181019.OrgOpenroadmAlarmListener - alarmListener = new AlarmNotificationListener221(dataBroker); - LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId); - final ListenerRegistration accessAlarmNotificationListenerRegistration = - notificationService.registerNotificationListener(alarmListener); - - final org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev181019 - .OrgOpenroadmDeOperationsListener deOperationsListener = new DeOperationsListener221(); - LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId); - final ListenerRegistration accessDeOperationasNotificationListenerRegistration = - notificationService.registerNotificationListener(deOperationsListener); - - final org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OrgOpenroadmDeviceListener - deviceListener = new DeviceListener221(nodeId, this.portMapping); - LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId); - final ListenerRegistration accessDeviceNotificationListenerRegistration = - notificationService.registerNotificationListener(deviceListener); - - final org.opendaylight.yang.gen.v1.http.org.openroadm.tca.rev181019.OrgOpenroadmTcaListener - tcaListener = new TcaListener221(); - LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId); - final ListenerRegistration accessTcaNotificationListenerRegistration = - notificationService.registerNotificationListener(tcaListener); - return new NodeRegistration22(nodeId, accessAlarmNotificationListenerRegistration, - accessDeOperationasNotificationListenerRegistration, accessDeviceNotificationListenerRegistration, - null, accessTcaNotificationListenerRegistration); + NodeRegistration nodeRegistration = this.registrations.remove(nodeId); + nodeRegistration.unregisterListeners(); } private boolean subscribeStream(MountPoint mountPoint, String streamName, String nodeId) { @@ -263,4 +155,15 @@ public class NetConfTopologyListener implements DataTreeChangeListener { } return true; } + + @VisibleForTesting + public NetConfTopologyListener(final NetworkModelService networkModelService, final DataBroker dataBroker, + DeviceTransactionManager deviceTransactionManager, PortMapping portMapping, + Map registrations) { + this.networkModelService = networkModelService; + this.dataBroker = dataBroker; + this.deviceTransactionManager = deviceTransactionManager; + this.portMapping = portMapping; + this.registrations = registrations; + } } diff --git a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration.java b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration.java index e802091b5..8bcfaab59 100644 --- a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration.java +++ b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration.java @@ -7,60 +7,110 @@ */ package org.opendaylight.transportpce.networkmodel.dto; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.NotificationService; +import org.opendaylight.transportpce.common.StringConstants; +import org.opendaylight.transportpce.common.mapping.PortMapping; +import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener; +import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener221; +import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener; +import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener221; +import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener121; +import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener221; +import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener710; +import org.opendaylight.transportpce.networkmodel.listeners.TcaListener; +import org.opendaylight.transportpce.networkmodel.listeners.TcaListener221; import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev161014.OrgOpenroadmAlarmListener; import org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev161014.OrgOpenroadmDeOperationsListener; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceListener; -import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.OrgOpenroadmLldpListener; -import org.opendaylight.yang.gen.v1.http.org.openroadm.tca.rev161014.OrgOpenroadmTcaListener; import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class NodeRegistration { - + private static final Logger LOG = LoggerFactory.getLogger(NodeRegistration.class); private final String nodeId; - private final ListenerRegistration accessAlarmNotificationListenerRegistration; - private final ListenerRegistration - accessDeOperationasNotificationListenerRegistration; - private final ListenerRegistration accessDeviceNotificationListenerRegistration; - private final ListenerRegistration accessLldpNotificationListenerRegistration; - private final ListenerRegistration accessTcaNotificationListenerRegistration; + private final String nodeVersion; + private final NotificationService notificationService; + private final DataBroker dataBroker; + private final PortMapping portMapping; + private final List> listeners; - public NodeRegistration(String nodeId, - ListenerRegistration accessAlarmNotificationListenerRegistration, - ListenerRegistration accessDeOperationasNotificationListenerRegistration, - ListenerRegistration accessDeviceNotificationListenerRegistration, - ListenerRegistration accessLldpNotificationListenerRegistration, - ListenerRegistration accessTcaNotificationListenerRegistration) { + public NodeRegistration(String nodeId, String nodeVersion, NotificationService notificationService, + DataBroker dataBroker, PortMapping portMapping) { this.nodeId = nodeId; - this.accessAlarmNotificationListenerRegistration = accessAlarmNotificationListenerRegistration; - this.accessDeOperationasNotificationListenerRegistration = accessDeOperationasNotificationListenerRegistration; - this.accessDeviceNotificationListenerRegistration = accessDeviceNotificationListenerRegistration; - this.accessLldpNotificationListenerRegistration = accessLldpNotificationListenerRegistration; - this.accessTcaNotificationListenerRegistration = accessTcaNotificationListenerRegistration; + this.nodeVersion = nodeVersion; + this.notificationService = notificationService; + this.dataBroker = dataBroker; + this.portMapping = portMapping; + listeners = new ArrayList>(); } - public String getNodeId() { - return nodeId; + public void registerListeners() { + switch (this.nodeVersion) { + case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1: + registerListeners121(); + break; + case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1: + registerListeners221(); + break; + case StringConstants.OPENROADM_DEVICE_VERSION_7_1_0: + registerListeners710(); + break; + default: + LOG.debug("Unable to register listeners - unknown device version for {}", this.nodeId); + break; + } } - public ListenerRegistration getAccessAlarmNotificationListenerRegistration() { - return accessAlarmNotificationListenerRegistration; + public void unregisterListeners() { + LOG.info("Unregistering notification listeners for node: {}", this.nodeId); + for (ListenerRegistration listenerRegistration : listeners) { + listenerRegistration.close(); + } } - public ListenerRegistration - getAccessDeOperationasNotificationListenerRegistration() { - return accessDeOperationasNotificationListenerRegistration; - } + private void registerListeners121() { + OrgOpenroadmAlarmListener alarmListener = new AlarmNotificationListener(this.dataBroker); + LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId); + listeners.add(notificationService.registerNotificationListener(alarmListener)); - public ListenerRegistration getAccessDeviceNotificationListenerRegistration() { - return accessDeviceNotificationListenerRegistration; - } + OrgOpenroadmDeOperationsListener deOperationsListener = new DeOperationsListener(); + LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId); + listeners.add(notificationService.registerNotificationListener(deOperationsListener)); + + OrgOpenroadmDeviceListener deviceListener = new DeviceListener121(nodeId, this.portMapping); + LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId); + listeners.add(notificationService.registerNotificationListener(deviceListener)); - public ListenerRegistration getAccessLldpNotificationListenerRegistration() { - return accessLldpNotificationListenerRegistration; + TcaListener tcaListener = new TcaListener(); + LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId); + listeners.add(notificationService.registerNotificationListener(tcaListener)); } - public ListenerRegistration getAccessTcaNotificationListenerRegistration() { - return accessTcaNotificationListenerRegistration; + private void registerListeners221() { + AlarmNotificationListener221 alarmListener = new AlarmNotificationListener221(dataBroker); + LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId); + listeners.add(notificationService.registerNotificationListener(alarmListener)); + + DeOperationsListener221 deOperationsListener = new DeOperationsListener221(); + LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId); + listeners.add(notificationService.registerNotificationListener(deOperationsListener)); + + DeviceListener221 deviceListener = new DeviceListener221(nodeId, this.portMapping); + LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId); + listeners.add(notificationService.registerNotificationListener(deviceListener)); + + TcaListener221 tcaListener = new TcaListener221(); + LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId); + listeners.add(notificationService.registerNotificationListener(tcaListener)); } + private void registerListeners710() { + DeviceListener710 deviceListener = new DeviceListener710(nodeId, this.portMapping); + LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId); + listeners.add(notificationService.registerNotificationListener(deviceListener)); + } } diff --git a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration22.java b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration22.java deleted file mode 100644 index 91788643c..000000000 --- a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration22.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright © 2016 AT&T 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.transportpce.networkmodel.dto; - -import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev181019.OrgOpenroadmAlarmListener; -import org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev181019.OrgOpenroadmDeOperationsListener; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OrgOpenroadmDeviceListener; -import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.OrgOpenroadmLldpListener; -import org.opendaylight.yang.gen.v1.http.org.openroadm.tca.rev181019.OrgOpenroadmTcaListener; -import org.opendaylight.yangtools.concepts.ListenerRegistration; - -public class NodeRegistration22 { - - private final String nodeId; - private final ListenerRegistration accessAlarmNotificationListenerRegistration; - private final ListenerRegistration - accessDeOperationasNotificationListenerRegistration; - private final ListenerRegistration accessDeviceNotificationListenerRegistration; - private final ListenerRegistration accessLldpNotificationListenerRegistration; - private final ListenerRegistration accessTcaNotificationListenerRegistration; - - public NodeRegistration22(String nodeId, - ListenerRegistration - accessAlarmNotificationListenerRegistration, - ListenerRegistration - accessDeOperationasNotificationListenerRegistration, - ListenerRegistration - accessDeviceNotificationListenerRegistration, - ListenerRegistration - accessLldpNotificationListenerRegistration, - ListenerRegistration - accessTcaNotificationListenerRegistration) { - this.nodeId = nodeId; - this.accessAlarmNotificationListenerRegistration = accessAlarmNotificationListenerRegistration; - this.accessDeOperationasNotificationListenerRegistration = accessDeOperationasNotificationListenerRegistration; - this.accessDeviceNotificationListenerRegistration = accessDeviceNotificationListenerRegistration; - this.accessLldpNotificationListenerRegistration = accessLldpNotificationListenerRegistration; - this.accessTcaNotificationListenerRegistration = accessTcaNotificationListenerRegistration; - } - - public String getNodeId() { - return nodeId; - } - - public ListenerRegistration getAccessAlarmNotificationListenerRegistration() { - return accessAlarmNotificationListenerRegistration; - } - - public ListenerRegistration - getAccessDeOperationasNotificationListenerRegistration() { - return accessDeOperationasNotificationListenerRegistration; - } - - public ListenerRegistration getAccessDeviceNotificationListenerRegistration() { - return accessDeviceNotificationListenerRegistration; - } - - public ListenerRegistration getAccessLldpNotificationListenerRegistration() { - return accessLldpNotificationListenerRegistration; - } - - public ListenerRegistration getAccessTcaNotificationListenerRegistration() { - return accessTcaNotificationListenerRegistration; - } - -} diff --git a/networkmodel/src/test/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListenerTest.java b/networkmodel/src/test/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListenerTest.java index 7085174b8..4e8a5e908 100644 --- a/networkmodel/src/test/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListenerTest.java +++ b/networkmodel/src/test/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListenerTest.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -29,6 +30,7 @@ import org.opendaylight.mdsal.binding.api.DataObjectModification; import org.opendaylight.mdsal.binding.api.DataTreeModification; import org.opendaylight.transportpce.common.device.DeviceTransactionManager; import org.opendaylight.transportpce.common.mapping.PortMapping; +import org.opendaylight.transportpce.networkmodel.dto.NodeRegistration; import org.opendaylight.transportpce.networkmodel.service.NetworkModelService; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; @@ -60,12 +62,15 @@ public class NetConfTopologyListenerTest { private DeviceTransactionManager deviceTransactionManager; @Mock private PortMapping portMapping; + @Mock + private Map registrations; @Test public void testOnDataTreeChangedWhenDeleteNode() { final DataObjectModification node = mock(DataObjectModification.class); final Collection> changes = new HashSet<>(); final DataTreeModification ch = mock(DataTreeModification.class); + final NodeRegistration nodeRegistration = mock(NodeRegistration.class); changes.add(ch); when(ch.getRootNode()).thenReturn(node); @@ -73,13 +78,16 @@ public class NetConfTopologyListenerTest { OPENROADM_DEVICE_VERSION_2_2_1); when(node.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE); when(node.getDataBefore()).thenReturn(netconfNode); + when(registrations.remove(anyString())).thenReturn(nodeRegistration); + NetConfTopologyListener listener = new NetConfTopologyListener(networkModelService, dataBroker, - deviceTransactionManager, portMapping); + deviceTransactionManager, portMapping, registrations); listener.onDataTreeChanged(changes); verify(ch, times(1)).getRootNode(); verify(node, times(1)).getModificationType(); verify(node, times(3)).getDataBefore(); verify(networkModelService, times(1)).deleteOpenRoadmnode(anyString()); + verify(nodeRegistration, times(1)).unregisterListeners(); } @Test -- 2.36.6