package org.opendaylight.transportpce.networkmodel.listeners;
-import java.util.Collection;
import java.util.LinkedList;
import org.opendaylight.transportpce.common.mapping.PortMapping;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
private final PortMapping portMapping;
public DeviceListener121(String nodeId, PortMapping portMapping) {
+ super();
this.nodeId = nodeId;
this.portMapping = portMapping;
}
* @param notification ChangeNotification object
*/
@Override
+ @SuppressWarnings("unchecked")
public void onChangeNotification(ChangeNotification notification) {
if (notification.getEdit() == null) {
LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
switch (edit.getTarget().getTargetType().getSimpleName()) {
case "Ports":
LinkedList<PathArgument> path = new LinkedList<>();
- path.addAll((Collection<? extends PathArgument>) edit.getTarget().getPathArguments());
+ edit.getTarget().getPathArguments().forEach(p -> path.add(p));
InstanceIdentifier<Ports> portIID = (InstanceIdentifier<Ports>) InstanceIdentifier
.create(path);
String portName = InstanceIdentifier.keyOf(portIID).getPortName();
package org.opendaylight.transportpce.networkmodel.listeners;
-import java.util.Collection;
import java.util.LinkedList;
import org.opendaylight.transportpce.common.mapping.PortMapping;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
private final PortMapping portMapping;
public DeviceListener221(String nodeId, PortMapping portMapping) {
+ super();
this.nodeId = nodeId;
this.portMapping = portMapping;
}
* ChangeNotification object
*/
@Override
+ @SuppressWarnings("unchecked")
public void onChangeNotification(ChangeNotification notification) {
if (notification.getEdit() == null) {
LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
switch (edit.getTarget().getTargetType().getSimpleName()) {
case "Ports":
LinkedList<PathArgument> path = new LinkedList<>();
- path.addAll((Collection<? extends PathArgument>) edit.getTarget().getPathArguments());
+ edit.getTarget().getPathArguments().forEach(p -> path.add(p));
InstanceIdentifier<Ports> portIID = (InstanceIdentifier<Ports>) InstanceIdentifier
.create(path);
String portName = InstanceIdentifier.keyOf(portIID).getPortName();
package org.opendaylight.transportpce.networkmodel.listeners;
-import java.util.Collection;
import java.util.LinkedList;
import org.opendaylight.transportpce.common.mapping.PortMapping;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
private final PortMapping portMapping;
public DeviceListener710(String nodeId, PortMapping portMapping) {
+ super();
this.nodeId = nodeId;
this.portMapping = portMapping;
}
* ChangeNotification object
*/
@Override
+ @SuppressWarnings("unchecked")
public void onChangeNotification(ChangeNotification notification) {
if (notification.getEdit() == null) {
LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
switch (edit.getTarget().getTargetType().getSimpleName()) {
case "Ports":
LinkedList<PathArgument> path = new LinkedList<>();
- path.addAll((Collection<? extends PathArgument>) edit.getTarget().getPathArguments());
+ edit.getTarget().getPathArguments().forEach(p -> path.add(p));
InstanceIdentifier<Ports> portIID = (InstanceIdentifier<Ports>) InstanceIdentifier
.create(path);
String portName = InstanceIdentifier.keyOf(portIID).getPortName();
--- /dev/null
+/*
+ * Copyright © 2021 Orange. 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.listeners;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.transportpce.common.mapping.PortMapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.ChangeNotification;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.change.notification.Edit;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.change.notification.EditBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.PortsKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class DeviceListener121Test {
+ @Mock
+ private PortMapping portMapping;
+
+ @Test
+ public void testOnChangeNotificationWhenPortUpdated() throws InterruptedException {
+ ChangeNotification notification = mock(ChangeNotification.class);
+ Mapping oldMapping = mock(Mapping.class);
+ ImmutableList<Edit> editList = createEditList();
+ when(notification.getEdit()).thenReturn(editList);
+ when(portMapping.getMapping("node1", "circuit-pack1", "port1")).thenReturn(oldMapping);
+
+ DeviceListener121 listener = new DeviceListener121("node1", portMapping);
+ listener.onChangeNotification(notification);
+ verify(portMapping, times(1)).getMapping("node1", "circuit-pack1", "port1");
+ Thread.sleep(3000);
+ verify(portMapping, times(1)).updateMapping("node1", oldMapping);
+ }
+
+ @Test
+ public void testOnChangeNotificationWhenNoEditList() {
+ ChangeNotification notification = mock(ChangeNotification.class);
+ when(notification.getEdit()).thenReturn(null);
+ DeviceListener121 listener = new DeviceListener121("node1", portMapping);
+ listener.onChangeNotification(notification);
+ verify(portMapping, never()).getMapping(anyString(), anyString(), anyString());
+ verify(portMapping, never()).updateMapping(anyString(), any());
+ }
+
+ @Test
+ public void testOnChangeNotificationWhenOtherthingUpdated() {
+ ChangeNotification notification = mock(ChangeNotification.class);
+ ImmutableList<Edit> editList = createBadEditList();
+ when(notification.getEdit()).thenReturn(editList);
+ DeviceListener121 listener = new DeviceListener121("node1", portMapping);
+ listener.onChangeNotification(notification);
+ verify(portMapping, never()).getMapping(anyString(), anyString(), anyString());
+ verify(portMapping, never()).updateMapping(anyString(), any());
+ }
+
+ private ImmutableList<Edit> createEditList() {
+ InstanceIdentifier<Ports> portId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey("circuit-pack1"))
+ .child(Ports.class, new PortsKey("port1"));
+ Edit edit = new EditBuilder()
+ .setOperation(EditOperationType.Merge)
+ .setTarget(portId)
+ .build();
+ ImmutableList<Edit> editList = ImmutableList.of(edit);
+ return editList;
+ }
+
+ private ImmutableList<Edit> createBadEditList() {
+ InstanceIdentifier<CircuitPacks> cpId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey("circuit-pack1"));
+ Edit edit = new EditBuilder()
+ .setOperation(EditOperationType.Merge)
+ .setTarget(cpId)
+ .build();
+ ImmutableList<Edit> editList = ImmutableList.of(edit);
+ return editList;
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange. 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.listeners;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.transportpce.common.mapping.PortMapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.ChangeNotification;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.change.notification.Edit;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.change.notification.EditBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.Ports;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.PortsKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacks;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacksKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.OrgOpenroadmDevice;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class DeviceListener221Test {
+ @Mock
+ private PortMapping portMapping;
+
+ @Test
+ public void testOnChangeNotificationWhenPortUpdated() throws InterruptedException {
+ ChangeNotification notification = mock(ChangeNotification.class);
+ Mapping oldMapping = mock(Mapping.class);
+ ImmutableList<Edit> editList = createEditList();
+ when(notification.getEdit()).thenReturn(editList);
+ when(portMapping.getMapping("node1", "circuit-pack1", "port1")).thenReturn(oldMapping);
+
+ DeviceListener221 listener = new DeviceListener221("node1", portMapping);
+ listener.onChangeNotification(notification);
+ verify(portMapping, times(1)).getMapping("node1", "circuit-pack1", "port1");
+ Thread.sleep(3000);
+ verify(portMapping, times(1)).updateMapping("node1", oldMapping);
+ }
+
+ @Test
+ public void testOnChangeNotificationWhenNoEditList() {
+ ChangeNotification notification = mock(ChangeNotification.class);
+ when(notification.getEdit()).thenReturn(null);
+ DeviceListener221 listener = new DeviceListener221("node1", portMapping);
+ listener.onChangeNotification(notification);
+ verify(portMapping, never()).getMapping(anyString(), anyString(), anyString());
+ verify(portMapping, never()).updateMapping(anyString(), any());
+ }
+
+ @Test
+ public void testOnChangeNotificationWhenOtherthingUpdated() {
+ ChangeNotification notification = mock(ChangeNotification.class);
+ ImmutableList<Edit> editList = createBadEditList();
+ when(notification.getEdit()).thenReturn(editList);
+ DeviceListener221 listener = new DeviceListener221("node1", portMapping);
+ listener.onChangeNotification(notification);
+ verify(portMapping, never()).getMapping(anyString(), anyString(), anyString());
+ verify(portMapping, never()).updateMapping(anyString(), any());
+ }
+
+ private ImmutableList<Edit> createEditList() {
+ InstanceIdentifier<Ports> portId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey("circuit-pack1"))
+ .child(Ports.class, new PortsKey("port1"));
+ Edit edit = new EditBuilder()
+ .setOperation(EditOperationType.Merge)
+ .setTarget(portId)
+ .build();
+ ImmutableList<Edit> editList = ImmutableList.of(edit);
+ return editList;
+ }
+
+ private ImmutableList<Edit> createBadEditList() {
+ InstanceIdentifier<CircuitPacks> cpId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey("circuit-pack1"));
+ Edit edit = new EditBuilder()
+ .setOperation(EditOperationType.Merge)
+ .setTarget(cpId)
+ .build();
+ ImmutableList<Edit> editList = ImmutableList.of(edit);
+ return editList;
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Orange. 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.listeners;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.transportpce.common.mapping.PortMapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.ChangeNotification;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.change.notification.Edit;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.change.notification.EditBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.pack.Ports;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.pack.PortsKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacks;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacksKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.OrgOpenroadmDevice;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class DeviceListener710Test {
+ @Mock
+ private PortMapping portMapping;
+
+ @Test
+ public void testOnChangeNotificationWhenPortUpdated() throws InterruptedException {
+ ChangeNotification notification = mock(ChangeNotification.class);
+ Mapping oldMapping = mock(Mapping.class);
+ ImmutableList<Edit> editList = createEditList();
+ when(notification.getEdit()).thenReturn(editList);
+ when(portMapping.getMapping("node1", "circuit-pack1", "port1")).thenReturn(oldMapping);
+
+ DeviceListener710 listener = new DeviceListener710("node1", portMapping);
+ listener.onChangeNotification(notification);
+ verify(portMapping, times(1)).getMapping("node1", "circuit-pack1", "port1");
+ Thread.sleep(3000);
+ verify(portMapping, times(1)).updateMapping("node1", oldMapping);
+ }
+
+ @Test
+ public void testOnChangeNotificationWhenNoEditList() {
+ ChangeNotification notification = mock(ChangeNotification.class);
+ when(notification.getEdit()).thenReturn(null);
+ DeviceListener710 listener = new DeviceListener710("node1", portMapping);
+ listener.onChangeNotification(notification);
+ verify(portMapping, never()).getMapping(anyString(), anyString(), anyString());
+ verify(portMapping, never()).updateMapping(anyString(), any());
+ }
+
+ @Test
+ public void testOnChangeNotificationWhenOtherthingUpdated() {
+ ChangeNotification notification = mock(ChangeNotification.class);
+ ImmutableList<Edit> editList = createBadEditList();
+ when(notification.getEdit()).thenReturn(editList);
+ DeviceListener710 listener = new DeviceListener710("node1", portMapping);
+ listener.onChangeNotification(notification);
+ verify(portMapping, never()).getMapping(anyString(), anyString(), anyString());
+ verify(portMapping, never()).updateMapping(anyString(), any());
+ }
+
+ private ImmutableList<Edit> createEditList() {
+ InstanceIdentifier<Ports> portId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey("circuit-pack1"))
+ .child(Ports.class, new PortsKey("port1"));
+ Edit edit = new EditBuilder()
+ .setOperation(EditOperationType.Merge)
+ .setTarget(portId)
+ .build();
+ ImmutableList<Edit> editList = ImmutableList.of(edit);
+ return editList;
+ }
+
+ private ImmutableList<Edit> createBadEditList() {
+ InstanceIdentifier<CircuitPacks> cpId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey("circuit-pack1"));
+ Edit edit = new EditBuilder()
+ .setOperation(EditOperationType.Merge)
+ .setTarget(cpId)
+ .build();
+ ImmutableList<Edit> editList = ImmutableList.of(edit);
+ return editList;
+ }
+}