2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.ovsdb.hwvtepsouthbound;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.HwvtepOperationalState;
14 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.McastMacsRemoteUpdateCommand;
15 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.UnMetDependencyGetter;
16 import org.opendaylight.ovsdb.lib.notation.UUID;
17 import org.opendaylight.ovsdb.lib.operations.Operations;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
24 import org.opendaylight.yangtools.yang.binding.Identifiable;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.powermock.core.classloader.annotations.PrepareForTest;
27 import org.powermock.modules.junit4.PowerMockRunner;
28 import org.powermock.reflect.Whitebox;
30 import java.util.List;
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertNull;
36 @RunWith(PowerMockRunner.class)
37 @PrepareForTest({HwvtepConnectionInstance.class, HwvtepConnectionManager.class, Operations.class})
38 public class UnMetDependencyGetterTest extends DataChangeListenerTestBase {
40 UnMetDependencyGetter<RemoteMcastMacs> MCAST_MAC_DATA_VALIDATOR;
41 HwvtepOperationalState opState;
43 InstanceIdentifier<LogicalSwitches> lsIid;
44 Map<Class<? extends Identifiable>, List<InstanceIdentifier>> unMetDependencies;
47 MCAST_MAC_DATA_VALIDATOR = Whitebox.getInternalState(McastMacsRemoteUpdateCommand.class, UnMetDependencyGetter.class);
48 opState = new HwvtepOperationalState(connectionInstance);
49 mac = TestBuilders.buildRemoteMcastMacs(nodeIid,"FF:FF:FF:FF:FF:FF", "ls0",
50 new String[]{"192.168.122.20", "192.168.122.30"});
51 lsIid = nodeIid.augmentation(HwvtepGlobalAugmentation.class).
52 child(LogicalSwitches.class, new LogicalSwitchesKey(new HwvtepNodeName("ls0")));
56 public void testLogicalSwitchConfigDependency() throws Exception {
58 unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getInTransitDependencies(opState, mac);
59 assertEquals(0, unMetDependencies.size());
61 unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getUnMetConfigDependencies(opState, mac);
62 assertEquals(1, unMetDependencies.get(LogicalSwitches.class).size());
63 assertEquals(2, unMetDependencies.get(TerminationPoint.class).size());
65 opState.getDeviceInfo().updateConfigData(LogicalSwitches.class, lsIid, "ls0");
66 unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getUnMetConfigDependencies(opState, mac);
67 assertNull(unMetDependencies.get(LogicalSwitches.class));
71 public void testLogicalSwitchInTransitDependency() throws Exception {
73 unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getInTransitDependencies(opState, mac);
74 assertEquals(0, unMetDependencies.size());
76 opState.getDeviceInfo().markKeyAsInTransit(LogicalSwitches.class, lsIid);
77 unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getInTransitDependencies(opState, mac);
78 assertEquals(1, unMetDependencies.size());
80 opState.getDeviceInfo().updateDeviceOpData(LogicalSwitches.class, lsIid, new UUID("ls0"), "ls0");
81 unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getInTransitDependencies(opState, mac);
82 assertEquals(0, unMetDependencies.size());