/*
- * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ * Copyright (c) 2016 CableLabs 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,
List<UniDest> unisDest = evcAugmentation.getUniDest();
if (unisSource != null && !unisSource.isEmpty()) {
for (UniSource source: unisSource) {
- if (unisSource != null) {
+ if (source != null) {
Optional<Node> optionalSourceUniNode =
UnimgrUtils.readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
EvcAugmentation formerEvc;
try {
formerEvc = (EvcAugmentation) ((Optional<EvcAugmentation>) retFormerEvc.checkedGet()).get();
- final Ipv4Address formerUni1ip = formerEvc.getUniDest().iterator().next().getIpAddress().getIpv4Address();
+ final Ipv4Address formerUni1ip = formerEvc.getUniSource().iterator().next().getIpAddress().getIpv4Address();
final Ipv4Address formerUni2ip = formerEvc.getUniDest().iterator().next().getIpAddress().getIpv4Address();
if (formerUni1ip.equals(laterUni1Ip)) {
} else if (formerUni2ip.equals(laterUni2Ip)) {
// do nothing
} else {
- LOG.info("{} is not part of the EVC, removing configuration", formerUni1ip);
- final InstanceIdentifier<?> formerUniIID = UnimgrMapper.getUniIid(dataBroker, new IpAddress(formerUni1ip), LogicalDatastoreType.OPERATIONAL);
+ LOG.info("{} is not part of the EVC, removing configuration", formerUni2ip);
+ final InstanceIdentifier<?> formerUniIID = UnimgrMapper.getUniIid(dataBroker, new IpAddress(formerUni2ip), LogicalDatastoreType.OPERATIONAL);
final Optional<Node> formerUni = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, formerUniIID);
UnimgrUtils.deleteEvcData(dataBroker, formerUni);
- }
- } catch (ReadFailedException e) {
+ }
+ } catch (final ReadFailedException e) {
LOG.error("Failed to retrieve former EVC {}", evcKey, e);
}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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.unimgr.command;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.impl.UnimgrConstants;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.unimgr.impl.UnimgrUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.google.common.base.Optional;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({UnimgrUtils.class,
+ UnimgrMapper.class})
+public class EvcCreateCommandTest {
+
+ private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
+
+ private EvcCreateCommand evcCreateCommand;
+ private Map<InstanceIdentifier<?>, DataObject> changes;
+ private DataBroker dataBroker;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp(){
+ PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UnimgrMapper.class);
+ changes = mock(Map.class);
+ dataBroker = mock(DataBroker.class);
+ evcCreateCommand = new EvcCreateCommand(dataBroker, changes);
+ }
+
+ /**
+ * Test method for {@link org.opendaylight.unimgr.command.EvcCreateCommand#execute()}.
+ * @throws Exception
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test
+ public void testExecute() throws Exception {
+ final UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ final EvcAugmentation evcAugmentation = mock(EvcAugmentation.class);
+ final List<UniSource> unisSource = new ArrayList<UniSource>();
+ final UniSource uniSource = mock(UniSource.class);
+ final List<UniDest> unisDest = new ArrayList<UniDest>();
+ final UniDest uniDest = mock(UniDest.class);
+ final IpAddress ipAddress = mock(IpAddress.class);
+ final Ipv4Address ipv4Address = mock(Ipv4Address.class);
+ final Optional<Node> optionalOvsdbNode = mock(Optional.class);
+ final Node node = mock(Node.class);
+ final OvsdbNodeRef ovsNodedRef = mock(OvsdbNodeRef.class);
+ final InstanceIdentifier evcKey = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
+ .child(Node.class, new NodeKey(OVSDB_NODE_ID));
+ final Set<Entry<InstanceIdentifier<?>, DataObject>> setCreated = new HashSet<Map.Entry<InstanceIdentifier<?>,DataObject>>();
+ final Entry<InstanceIdentifier<?>, DataObject> created = new Entry<InstanceIdentifier<?>, DataObject>() {
+ @Override
+ public DataObject setValue(DataObject value) { return null; }
+ @Override
+ public DataObject getValue() { return evcAugmentation; }
+ @Override
+ public InstanceIdentifier getKey() { return evcKey; }
+ };
+
+ setCreated.add(created);
+ unisSource.add(uniSource);
+ unisDest.add(uniDest);
+
+ when(changes.entrySet()).thenReturn(setCreated);
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
+ when(evcAugmentation.getUniSource()).thenReturn(unisSource);
+ when(evcAugmentation.getUniDest()).thenReturn(unisDest);
+ when(uniSource.getIpAddress()).thenReturn(ipAddress);
+ when(uniDest.getIpAddress()).thenReturn(ipAddress);
+ when(uniSource.getUni()).thenReturn(evcKey);
+ when(uniDest.getUni()).thenReturn(evcKey);
+ when(ipAddress.getIpv4Address()).thenReturn(ipv4Address);
+ when(ipv4Address.toString()).thenReturn("ipv4Address_test");
+ when(ipv4Address.getValue()).thenReturn("ipv4AddressValue_test");
+ when(optionalOvsdbNode.isPresent()).thenReturn(true);
+ when(optionalOvsdbNode.get()).thenReturn(node);
+ when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation);
+ when(ovsNodedRef.getValue()).thenReturn(evcKey);
+
+ when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
+ PowerMockito.doNothing().when(UnimgrUtils.class, "updateMaxRate", dataBroker, uniAugmentation,
+ uniAugmentation, evcAugmentation);
+ PowerMockito.doNothing().when(UnimgrUtils.class, "createTerminationPointNode", dataBroker,
+ uniAugmentation, node, UnimgrConstants.DEFAULT_BRIDGE_NAME, UnimgrConstants.DEFAULT_TUNNEL_IFACE);
+ PowerMockito.doNothing().when(UnimgrUtils.class, "createGreTunnel", dataBroker, uniAugmentation,
+ uniAugmentation, node, UnimgrConstants.DEFAULT_BRIDGE_NAME, UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
+ when(UnimgrUtils.createOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ .thenReturn(node);
+ when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(evcKey);
+ when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
+ any(LogicalDatastoreType.class))).thenReturn(evcKey);
+
+ evcCreateCommand.execute();
+ PowerMockito.verifyStatic(times(2));
+ UnimgrUtils.createTerminationPointNode(any(DataBroker.class), any(UniAugmentation.class),
+ any(Node.class), any(String.class), any(String.class));
+ PowerMockito.verifyStatic(times(2));
+ UnimgrUtils.createGreTunnel(any(DataBroker.class), any(UniAugmentation.class),
+ any(UniAugmentation.class), any(Node.class), any(String.class), any(String.class));
+ PowerMockito.verifyStatic(times(2));
+ UnimgrUtils.updateEvcNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ any(EvcAugmentation.class), any(InstanceIdentifier.class),
+ any(InstanceIdentifier.class), any(DataBroker.class));
+
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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.unimgr.command;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.unimgr.impl.UnimgrUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.google.common.base.Optional;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({UnimgrUtils.class})
+public class EvcDeleteCommandTest {
+
+ private EvcDeleteCommand evcDeleteCommand;
+ private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes;
+ private DataBroker dataBroker;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp(){
+ PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UnimgrMapper.class);
+ changes = mock(AsyncDataChangeEvent.class);
+ dataBroker = mock(DataBroker.class);
+ evcDeleteCommand = new EvcDeleteCommand(dataBroker, changes);
+ }
+ /**
+ * Test method for {@link org.opendaylight.unimgr.command.EvcDeleteCommand#EvcDeleteCommand(org.opendaylight.controller.md.sal.binding.api.DataBroker, org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent)}.
+ * @throws Exception
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testEvcDeleteCommand() throws Exception {
+ final Set<InstanceIdentifier<EvcAugmentation>> removedEvcs =
+ new HashSet<InstanceIdentifier<EvcAugmentation>>();
+ final List<UniSource> unisSource = new ArrayList<UniSource>();
+ final UniSource uniSource = mock(UniSource.class);
+ final List<UniDest> unisDest = new ArrayList<UniDest>();
+ final UniDest uniDest = mock(UniDest.class);
+ final EvcAugmentation evcAugmentation = mock(EvcAugmentation.class);
+ final Optional<Node> optionalNode = mock(Optional.class);
+ final InstanceIdentifier instanceOfNode = mock(InstanceIdentifier.class);
+ removedEvcs.add(mock(InstanceIdentifier.class));
+ unisSource.add(uniSource);
+ unisDest.add(uniDest);
+
+ when(evcAugmentation.getUniSource()).thenReturn(unisSource);
+ when(evcAugmentation.getUniDest()).thenReturn(unisDest);
+ when(uniSource.getUni()).thenReturn(instanceOfNode);
+ when(uniDest.getUni()).thenReturn(instanceOfNode);
+ when(UnimgrUtils.extractRemoved(any(AsyncDataChangeEvent.class), any(Class.class)))
+ .thenReturn(removedEvcs);
+ when(UnimgrUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(evcAugmentation);
+ when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(optionalNode);
+ PowerMockito.doNothing().when(UnimgrUtils.class, "deleteEvcData",
+ any(DataBroker.class), any(Optional.class));
+ when(UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ any(LogicalDatastoreType.class))).thenReturn(true);
+
+ evcDeleteCommand.execute();
+ PowerMockito.verifyStatic(times(2));
+ UnimgrUtils.deleteEvcData(any(DataBroker.class), any(Optional.class));
+ PowerMockito.verifyStatic(times(1));
+ UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ any(LogicalDatastoreType.class));
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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.unimgr.command;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.unimgr.impl.UnimgrConstants;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.unimgr.impl.UnimgrUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({UnimgrUtils.class,
+ UnimgrMapper.class})
+public class EvcUpdateCommandTest {
+ private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
+
+ private EvcUpdateCommand evcUpdateCommand;
+ private Map<InstanceIdentifier<?>, DataObject> changes;
+ private DataBroker dataBroker;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp(){
+ PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UnimgrMapper.class);
+ changes = mock(Map.class);
+ dataBroker = mock(DataBroker.class);
+ evcUpdateCommand = new EvcUpdateCommand(dataBroker, changes);
+ }
+ /**
+ * Test method for {@link org.opendaylight.unimgr.command.EvcUpdateCommand#execute()}.
+ * @throws Exception
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test//(expected = ReadFailedException.class)
+ public void testExecute() throws Exception {
+ final ReadTransaction readTransac = mock(ReadOnlyTransaction.class);
+ final CheckedFuture retFormerEvc = mock(CheckedFuture.class);
+ final UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ final EvcAugmentation evcAugmentation = mock(EvcAugmentation.class);
+ final EvcAugmentation formerEvc = mock(EvcAugmentation.class);
+ final List<UniSource> unisSource = new ArrayList<UniSource>();
+ final List<UniDest> unisDest = new ArrayList<UniDest>();
+ final UniSource uniSource = mock(UniSource.class);
+ final UniDest uniDest = mock(UniDest.class);
+ final List<UniSource> formerUnisSource = new ArrayList<UniSource>();
+ final List<UniDest> formerUnisDest = new ArrayList<UniDest>();
+ final UniSource formerUniSource = mock(UniSource.class);
+ final UniDest formerUniDest = mock(UniDest.class);
+ final IpAddress ipAddressSource = mock(IpAddress.class);
+ final IpAddress ipAddressDest = mock(IpAddress.class);
+ final IpAddress formerIpAddressSource = mock(IpAddress.class);
+ final IpAddress formerIpAddressDest = mock(IpAddress.class);
+ final Ipv4Address ipv4AddressSource = mock(Ipv4Address.class);
+ final Ipv4Address ipv4AddressDest = mock(Ipv4Address.class);
+ final Ipv4Address formerIpv4AddressSource = mock(Ipv4Address.class);
+ final Ipv4Address formerIpv4AddressDest = mock(Ipv4Address.class);
+ final Optional<Node> optionalOvsdbNode = mock(Optional.class);
+ final Optional<EvcAugmentation> optionalEvcAugm = mock(Optional.class);
+ final Node node = mock(Node.class);
+ final OvsdbNodeRef ovsNodedRef = mock(OvsdbNodeRef.class);
+ final InstanceIdentifier evcKey = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
+ .child(Node.class, new NodeKey(OVSDB_NODE_ID));
+ final Set<Entry<InstanceIdentifier<?>, DataObject>> setCreated = new HashSet<Map.Entry<InstanceIdentifier<?>,DataObject>>();
+ final Entry<InstanceIdentifier<?>, DataObject> created = new Entry<InstanceIdentifier<?>, DataObject>() {
+ @Override
+ public DataObject setValue(DataObject value) { return null; }
+ @Override
+ public DataObject getValue() { return evcAugmentation; }
+ @Override
+ public InstanceIdentifier getKey() { return evcKey; }
+ };
+
+ setCreated.add(created);
+ unisSource.add(uniSource);
+ unisDest.add(uniDest);
+ formerUnisSource.add(formerUniSource);
+ formerUnisDest.add(formerUniDest);
+
+ // Case EVC1 : formerUni1ip.equals(laterUni1Ip), formerUni2ip.equals(laterUni2Ip)
+ // iidSource != null, iidDest != null
+ when(changes.entrySet()).thenReturn(setCreated);
+ when(dataBroker.newReadOnlyTransaction()).thenReturn((ReadOnlyTransaction) readTransac);
+ when(readTransac.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
+ .thenReturn(retFormerEvc);
+ when(retFormerEvc.checkedGet()).thenReturn(optionalEvcAugm);
+ when(optionalEvcAugm.get()).thenReturn(formerEvc);
+ when(formerEvc.getUniSource()).thenReturn(formerUnisSource);
+ when(formerEvc.getUniDest()).thenReturn(formerUnisDest);
+ when(formerUniSource.getIpAddress()).thenReturn(ipAddressSource);
+ when(formerUniDest.getIpAddress()).thenReturn(ipAddressDest);
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
+ when(evcAugmentation.getUniSource()).thenReturn(unisSource);
+ when(evcAugmentation.getUniDest()).thenReturn(unisDest);
+ when(uniSource.getIpAddress()).thenReturn(ipAddressSource);
+ when(uniDest.getIpAddress()).thenReturn(ipAddressDest);
+ when(uniSource.getUni()).thenReturn(evcKey);
+ when(uniDest.getUni()).thenReturn(evcKey);
+ when(formerIpAddressSource.getIpv4Address()).thenReturn(formerIpv4AddressSource);
+ when(formerIpAddressDest.getIpv4Address()).thenReturn(formerIpv4AddressDest);
+ when(formerIpv4AddressSource.toString()).thenReturn("formerIpv4AddressSource_test");
+ when(formerIpv4AddressSource.getValue()).thenReturn("formerIpv4AddressValueSource_test");
+ when(formerIpv4AddressDest.toString()).thenReturn("formerIpv4AddressDest_test");
+ when(formerIpv4AddressDest.getValue()).thenReturn("formerIpv4AddressValueDest_test");
+ when(ipAddressSource.getIpv4Address()).thenReturn(ipv4AddressSource);
+ when(ipAddressDest.getIpv4Address()).thenReturn(ipv4AddressDest);
+ when(optionalOvsdbNode.isPresent()).thenReturn(true);
+ when(optionalOvsdbNode.get()).thenReturn(node);
+ when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation);
+ when(ovsNodedRef.getValue()).thenReturn(evcKey);
+
+ PowerMockito.doNothing().when(UnimgrUtils.class, "deleteEvcData", dataBroker, optionalOvsdbNode);
+ when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
+ PowerMockito.doNothing().when(UnimgrUtils.class, "updateMaxRate", dataBroker, uniAugmentation,
+ uniAugmentation, evcAugmentation);
+ PowerMockito.doNothing().when(UnimgrUtils.class, "createTerminationPointNode", dataBroker,
+ uniAugmentation, node, UnimgrConstants.DEFAULT_BRIDGE_NAME, UnimgrConstants.DEFAULT_TUNNEL_IFACE);
+ PowerMockito.doNothing().when(UnimgrUtils.class, "createGreTunnel", dataBroker, uniAugmentation,
+ uniAugmentation, node, UnimgrConstants.DEFAULT_BRIDGE_NAME, UnimgrConstants.DEFAULT_GRE_TUNNEL_NAME);
+ when(UnimgrUtils.createOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ .thenReturn(node);
+ when(UnimgrMapper.getOvsdbBridgeNodeIid(any(Node.class))).thenReturn(evcKey);
+ when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
+ any(LogicalDatastoreType.class))).thenReturn(evcKey);
+ verifyExecute(0, 0, 6, 2);
+
+
+ // Case EVC2 : formerUni1ip.equals(laterUni1Ip), formerUni2ip.equals(laterUni2Ip)
+ // iidSource != null, iidDest != null
+ when(formerUniSource.getIpAddress()).thenReturn(formerIpAddressSource);
+ when(formerUniDest.getIpAddress()).thenReturn(formerIpAddressDest);
+ when(uniSource.getUni()).thenReturn(null);
+ when(uniDest.getUni()).thenReturn(null);
+ verifyExecute(4, 2, 14, 4);
+
+ // Case EVC3 : EVC2 with ReadFailedError
+ when(retFormerEvc.checkedGet()).thenThrow(
+ new ReadFailedException("Test ReadFailedException", (RpcError[]) null));
+ verifyExecute(6, 2, 20, 6);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void verifyExecute(int getUniTimes, int deleteTimes, int readNodeTimes, int updateEvcTime){
+ evcUpdateCommand.execute();
+ PowerMockito.verifyStatic(times(getUniTimes));
+ UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
+ any(LogicalDatastoreType.class));
+ PowerMockito.verifyStatic(times(deleteTimes));
+ UnimgrUtils.deleteEvcData(any(DataBroker.class), any(Optional.class));
+ PowerMockito.verifyStatic(times(readNodeTimes));
+ UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class));
+ PowerMockito.verifyStatic(times(updateEvcTime));
+ UnimgrMapper.getOvsdbBridgeNodeIid(any(Node.class));
+ PowerMockito.verifyStatic(times(updateEvcTime));
+ UnimgrUtils.createTerminationPointNode(any(DataBroker.class), any(UniAugmentation.class),
+ any(Node.class), any(String.class), any(String.class));
+ PowerMockito.verifyStatic(times(updateEvcTime));
+ UnimgrUtils.createGreTunnel(any(DataBroker.class), any(UniAugmentation.class),
+ any(UniAugmentation.class), any(Node.class), any(String.class), any(String.class));
+ PowerMockito.verifyStatic(times(updateEvcTime));
+ UnimgrUtils.updateEvcNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ any(EvcAugmentation.class), any(InstanceIdentifier.class),
+ any(InstanceIdentifier.class), any(DataBroker.class));
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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.unimgr.command;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.impl.UnimgrConstants;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.unimgr.impl.UnimgrUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.Speed;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.google.common.base.Optional;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({UnimgrUtils.class,
+ UnimgrMapper.class})
+public class UniCreateCommandTest {
+
+ private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
+
+ private UniCreateCommand uniCreateCommand;
+ private Map<InstanceIdentifier<?>, DataObject> changes;
+ private DataBroker dataBroker;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp(){
+ PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UnimgrMapper.class);
+ changes = mock(Map.class);
+ dataBroker = mock(DataBroker.class);
+ uniCreateCommand = new UniCreateCommand(dataBroker, changes);
+ }
+
+ /**
+ * Test method for {@link org.opendaylight.unimgr.command.UniCreateCommand#execute()}.
+ * @throws Exception
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testExecute() throws Exception {
+ final Optional<Node> optionalOvsdbNode = mock(Optional.class);
+ final UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ final OvsdbNodeAugmentation ovsdbNodeAugmentation = mock(OvsdbNodeAugmentation.class);
+ final ConnectionInfo connectionInfo = mock(ConnectionInfo.class);
+ final IpAddress ipAddress = mock(IpAddress.class);
+ final Ipv4Address ipv4Address = mock(Ipv4Address.class);
+ final OvsdbNodeRef ovsNodedRef = mock(OvsdbNodeRef.class);
+ final Node node = mock(Node.class);
+ final NodeId nodeId = mock(NodeId.class);
+ final List<Node> nodes = new ArrayList<Node>();
+ final InstanceIdentifier uniKey = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class, new NodeKey(OVSDB_NODE_ID));
+ final Set<Entry<InstanceIdentifier<?>, DataObject>> setCreated = new HashSet<Map.Entry<InstanceIdentifier<?>,DataObject>>();
+ Entry<InstanceIdentifier<?>, DataObject> created = new Entry<InstanceIdentifier<?>, DataObject>() {
+ @Override
+ public DataObject setValue(DataObject value) { return null; }
+ @Override
+ public DataObject getValue() { return uniAugmentation; }
+ @Override
+ public InstanceIdentifier getKey() { return uniKey; }
+ };
+ nodes.add(node);
+ setCreated.add(created);
+
+ // Case UNI1 : uni.getOvsdbNodeRef() != null, !optionalNode.isPresent()
+ when(changes.entrySet()).thenReturn(setCreated);
+ when(optionalOvsdbNode.isPresent()).thenReturn(false).thenReturn(true);
+ when(optionalOvsdbNode.get()).thenReturn(node);
+ when(uniAugmentation.getIpAddress()).thenReturn(ipAddress);
+ when(uniAugmentation.getSpeed()).thenReturn(mock(Speed.class));
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
+ when(ovsdbNodeAugmentation.getConnectionInfo()).thenReturn(connectionInfo);
+ when(connectionInfo.getRemoteIp()).thenReturn(ipAddress);
+ when(ipAddress.getIpv4Address()).thenReturn(ipv4Address);
+ when(ipv4Address.toString()).thenReturn("ipv4Address_test");
+ when(ipv4Address.getValue()).thenReturn("ipv4AddressValue_test");
+ when(ovsNodedRef.getValue()).thenReturn(uniKey);
+ when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation);
+ when(node.getNodeId()).thenReturn(nodeId);
+ when(nodeId.toString()).thenReturn("ovsdbNodeId_test");
+ when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
+ when(UnimgrUtils.findOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ .thenReturn(optionalOvsdbNode);
+ when(UnimgrUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ .thenReturn(null);
+ when(UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ any(UniAugmentation.class), any(Node.class), any(DataBroker.class))).thenReturn(true);
+ when(UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ any(UniAugmentation.class), any(InstanceIdentifier.class), any(DataBroker.class)))
+ .thenReturn(true);
+ when(UnimgrUtils.createOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ .thenReturn(node);
+ PowerMockito.doNothing().when(UnimgrUtils.class, "createBridgeNode",
+ dataBroker, uniKey,
+ uniAugmentation, UnimgrConstants.DEFAULT_BRIDGE_NAME);
+ when(UnimgrUtils.getUniNodes(any(DataBroker.class))).thenReturn(nodes);
+ when(UnimgrMapper.getOvsdbNodeIid(any(NodeId.class))).thenReturn(uniKey);
+ when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
+ any(LogicalDatastoreType.class))).thenReturn(uniKey);
+ verifyExecute(1, 0, 1, 0);
+
+ // Case UNI2 : optionalNode.isPresent()
+ when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
+ verifyExecute(1, 0, 1, 0);
+
+ // Case UNI3 : uni.getOvsdbNodeRef() == null, optionalNode.isPresent()
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(null);
+ verifyExecute(2, 1, 3, 0);
+
+ // Case UNI4 : uni.getOvsdbNodeRef() == null, !optionalNode.isPresent()
+ when(optionalOvsdbNode.isPresent()).thenReturn(false);
+ verifyExecute(2, 1, 4, 0);
+
+ // Case OVSDB0 ovsdbNodeAugmentation == null
+ created = new Entry<InstanceIdentifier<?>, DataObject>() {
+ @Override
+ public DataObject setValue(DataObject value) { return null; }
+ @Override
+ public DataObject getValue() { return null; }
+ @Override
+ public InstanceIdentifier getKey() { return uniKey; }
+ };
+ setCreated.clear();
+ setCreated.add(created);
+ verifyExecute(2, 1, 4, 0);
+
+ // Case OVSDB1 : uniNodes != null && !uniNodes.isEmpty(),
+ // uniAugmentation.getOvsdbNodeRef() != null &&
+ // uniAugmentation.getOvsdbNodeRef().getValue() != null
+ created = new Entry<InstanceIdentifier<?>, DataObject>() {
+ @Override
+ public DataObject setValue(DataObject value) { return null; }
+ @Override
+ public DataObject getValue() { return ovsdbNodeAugmentation; }
+ @Override
+ public InstanceIdentifier getKey() { return uniKey; }
+ };
+ setCreated.clear();
+ setCreated.add(created);
+
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
+ when(optionalOvsdbNode.isPresent()).thenReturn(true);
+ verifyExecute(3, 2, 4, 1);
+
+ // Case OVSDB2 : uniNodes != null && !uniNodes.isEmpty(),
+ // ovsdbNodeAugmentation.getConnectionInfo().getRemoteIp()
+ // .equals(uniAugmentation.getIpAddress())
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(null);
+ verifyExecute(3, 3, 4, 2);
+ }
+
+ private void verifyExecute(int qosTimes, int bridgeTimes, int updateNodeTime, int updateIIDTimes){
+ uniCreateCommand.execute();
+ PowerMockito.verifyStatic(times(qosTimes));
+ UnimgrUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class));
+ PowerMockito.verifyStatic(times(bridgeTimes));
+ UnimgrUtils.createBridgeNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ any(UniAugmentation.class), any(String.class));
+ PowerMockito.verifyStatic(times(updateNodeTime));
+ UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ any(UniAugmentation.class), any(Node.class), any(DataBroker.class));
+ PowerMockito.verifyStatic(times(updateIIDTimes));
+ UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ any(UniAugmentation.class), any(InstanceIdentifier.class), any(DataBroker.class));
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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.unimgr.command;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.powermock.api.support.membermodification.MemberMatcher.method;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.impl.UnimgrConstants;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.unimgr.impl.UnimgrUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.api.support.membermodification.MemberMatcher;
+import org.powermock.api.support.membermodification.MemberModifier;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.google.common.base.Optional;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({UnimgrUtils.class,
+ UnimgrMapper.class})
+public class UniDeleteCommandTest {
+
+ private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
+ private static final String NODE_ID = "uni://10.0.0.1";
+
+ private UniDeleteCommand uniDeleteCommand;
+ private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes;
+ private DataBroker dataBroker;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp(){
+ PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UnimgrMapper.class);
+ changes = mock(AsyncDataChangeEvent.class);
+ dataBroker = mock(DataBroker.class);
+ uniDeleteCommand = new UniDeleteCommand(dataBroker, changes);
+ }
+
+ /**
+ * Test method for {@link org.opendaylight.unimgr.command.UniDeleteCommand#execute()}.
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes", "deprecation" })
+ @Test
+ public void testExecute() {
+ final Set<InstanceIdentifier<UniAugmentation>> removedUnis =
+ new HashSet<InstanceIdentifier<UniAugmentation>>();
+ removedUnis.add(mock(InstanceIdentifier.class));
+ final UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ final OvsdbNodeRef ovsNodedRef = mock(OvsdbNodeRef.class);
+ final Optional<Node> optionalNode = mock(Optional.class);
+ final InstanceIdentifier instanceOfNode = mock(InstanceIdentifier.class);
+ final InstanceIdentifier uniKey = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class, new NodeKey(OVSDB_NODE_ID));
+
+ when(uniAugmentation.getIpAddress()).thenReturn(mock(IpAddress.class));
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
+ when(ovsNodedRef.getValue()).thenReturn(uniKey);
+ when(optionalNode.isPresent()).thenReturn(true);
+ when(optionalNode.get()).thenReturn(mock(Node.class));
+ when(UnimgrUtils.extractRemoved(any(AsyncDataChangeEvent.class), any(Class.class)))
+ .thenReturn(removedUnis);
+ when(UnimgrUtils.read(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(uniAugmentation);
+ when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(optionalNode);
+ when(UnimgrUtils.readNode(any(DataBroker.class), any(InstanceIdentifier.class)))
+ .thenReturn(optionalNode);
+ when(UnimgrMapper.getOvsdbBridgeNodeIid(any(Node.class))).thenReturn(instanceOfNode);
+ when(UnimgrMapper.getTerminationPointIid(any(Node.class), any(String.class)))
+ .thenReturn(instanceOfNode);
+ when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
+ any(LogicalDatastoreType.class))).thenReturn(instanceOfNode);
+ when(UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ any(LogicalDatastoreType.class))).thenReturn(true);
+ uniDeleteCommand.execute();
+
+ PowerMockito.verifyStatic(times(3));
+ UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ any(LogicalDatastoreType.class));
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 CableLabs 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.unimgr.command;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.unimgr.impl.UnimgrConstants;
+import org.opendaylight.unimgr.impl.UnimgrMapper;
+import org.opendaylight.unimgr.impl.UnimgrUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.Speed;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.google.common.base.Optional;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({UnimgrUtils.class,
+ UnimgrMapper.class})
+public class UniUpdateCommandTest {
+
+ private static final NodeId OVSDB_NODE_ID = new NodeId("ovsdb://7011db35-f44b-4aab-90f6-d89088caf9d8");
+
+ private UniUpdateCommand uniUpdateCommand;
+ private Map<InstanceIdentifier<?>, DataObject> changes;
+ private DataBroker dataBroker;
+ private ManagedNodeEntry managedNodeEntry;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp(){
+ PowerMockito.mockStatic(UnimgrUtils.class);
+ PowerMockito.mockStatic(UnimgrMapper.class);
+ changes = mock(Map.class);
+ dataBroker = mock(DataBroker.class);
+ uniUpdateCommand = new UniUpdateCommand(dataBroker, changes);
+ }
+
+ /**
+ * Test method for {@link org.opendaylight.unimgr.command.UniUpdateCommand#execute()}.
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test
+ public void testExecute() {
+ final Optional<Node> optionalOvsdbNode = mock(Optional.class);
+ final UniAugmentation uniAugmentation = mock(UniAugmentation.class);
+ final OvsdbNodeAugmentation ovsdbNodeAugmentation = mock(OvsdbNodeAugmentation.class);
+ managedNodeEntry = mock(ManagedNodeEntry.class);
+ final ManagedNodeEntryKey managedNodeEntryKey = mock(ManagedNodeEntryKey.class);
+ final List<ManagedNodeEntry> managedNodeEntries = new ArrayList<ManagedNodeEntry>();
+ final ConnectionInfo connectionInfo = mock(ConnectionInfo.class);
+ final IpAddress ipAddress = mock(IpAddress.class);
+ final Ipv4Address ipv4Address = mock(Ipv4Address.class);
+ final OvsdbNodeRef ovsNodedRef = mock(OvsdbNodeRef.class);
+ final Node node = mock(Node.class);
+ final NodeId nodeId = mock(NodeId.class);
+ final InstanceIdentifier uniKey = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class, new NodeKey(OVSDB_NODE_ID));
+ final Set<Entry<InstanceIdentifier<?>, DataObject>> setCreated = new HashSet<Map.Entry<InstanceIdentifier<?>,DataObject>>();
+ Entry<InstanceIdentifier<?>, DataObject> created = new Entry<InstanceIdentifier<?>, DataObject>() {
+ @Override
+ public DataObject setValue(DataObject value) { return null; }
+ @Override
+ public DataObject getValue() { return uniAugmentation; }
+ @Override
+ public InstanceIdentifier getKey() { return uniKey; }
+ };
+ setCreated.add(created);
+ managedNodeEntries.add(managedNodeEntry);
+
+ // Case UNI1 : updatedUni.getOvsdbNodeRef() != null, optOvsdbNode.isPresent()
+ when(changes.entrySet()).thenReturn(setCreated);
+ when(optionalOvsdbNode.isPresent()).thenReturn(true);
+ when(optionalOvsdbNode.get()).thenReturn(node);
+ when(uniAugmentation.getIpAddress()).thenReturn(ipAddress);
+ when(uniAugmentation.getSpeed()).thenReturn(mock(Speed.class));
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
+ when(ovsdbNodeAugmentation.getConnectionInfo()).thenReturn(connectionInfo);
+ when(ovsdbNodeAugmentation.getManagedNodeEntry()).thenReturn(managedNodeEntries);
+ when(managedNodeEntry.getKey()).thenReturn(managedNodeEntryKey);
+ when(connectionInfo.getRemoteIp()).thenReturn(ipAddress);
+ when(ipAddress.getIpv4Address()).thenReturn(ipv4Address);
+ when(ipv4Address.toString()).thenReturn("ipv4Address_test");
+ when(ipv4Address.getValue()).thenReturn("ipv4AddressValue_test");
+ when(ovsNodedRef.getValue()).thenReturn(uniKey);
+ when(node.getAugmentation(any(Class.class))).thenReturn(uniAugmentation);
+ when(node.getNodeId()).thenReturn(nodeId);
+ when(nodeId.toString()).thenReturn("ovsdbNodeId_test");
+
+ when(UnimgrUtils.getUni(any(DataBroker.class), any(LogicalDatastoreType.class), any(IpAddress.class)))
+ .thenReturn(uniAugmentation);
+ when(UnimgrUtils.readNode(any(DataBroker.class), any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class))).thenReturn(optionalOvsdbNode);
+ when(UnimgrUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ .thenReturn(null);
+ when(UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ any(UniAugmentation.class), any(Node.class), any(DataBroker.class))).thenReturn(true);
+ when(UnimgrUtils.findOvsdbNode(any(DataBroker.class), any(UniAugmentation.class)))
+ .thenReturn(optionalOvsdbNode);
+ when(UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ any(LogicalDatastoreType.class))).thenReturn(true);
+ when(UnimgrMapper.getUniIid(any(DataBroker.class), any(IpAddress.class),
+ any(LogicalDatastoreType.class))).thenReturn(uniKey);
+ verifyExecute(1, 1, 2, 0);
+
+ // Case UNI2 : updatedUni.getOvsdbNodeRef() != null, !optOvsdbNode.isPresent()
+ when(optionalOvsdbNode.isPresent()).thenReturn(false);
+ verifyExecute(1, 1, 2, 0);
+
+ // Case UNI3 : updatedUni.getOvsdbNodeRef() == null, !optOvsdbNode.isPresent()
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(null);
+ verifyExecute(1, 1, 2, 0);
+
+ // Case UNI4 : updatedUni.getOvsdbNodeRef() == null, optOvsdbNode.isPresent()
+ when(optionalOvsdbNode.isPresent()).thenReturn(true);
+ verifyExecute(2, 2, 4, 0);
+
+ // Case OVSDB
+ created = new Entry<InstanceIdentifier<?>, DataObject>() {
+ @Override
+ public DataObject setValue(DataObject value) { return null; }
+ @Override
+ public DataObject getValue() { return ovsdbNodeAugmentation; }
+ @Override
+ public InstanceIdentifier getKey() { return uniKey; }
+ };
+ setCreated.clear();
+ setCreated.add(created);
+
+ when(uniAugmentation.getOvsdbNodeRef()).thenReturn(ovsNodedRef);
+ when(optionalOvsdbNode.isPresent()).thenReturn(true);
+ verifyExecute(2, 2, 4, 1);
+ }
+
+ private void verifyExecute(int qosTimes, int deleteTimes, int updateNodeTime, int getKeyTimes){
+ uniUpdateCommand.execute();
+ PowerMockito.verifyStatic(times(qosTimes));
+ UnimgrUtils.createQoSForOvsdbNode(any(DataBroker.class), any(UniAugmentation.class));
+ PowerMockito.verifyStatic(times(deleteTimes));
+ UnimgrUtils.deleteNode(any(DataBroker.class), any(InstanceIdentifier.class),
+ any(LogicalDatastoreType.class));
+ PowerMockito.verifyStatic(times(updateNodeTime));
+ UnimgrUtils.updateUniNode(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ any(UniAugmentation.class), any(Node.class), any(DataBroker.class));
+ verify(managedNodeEntry, times(getKeyTimes)).getKey();
+ }
+
+}