bug 6579 added dependency queue
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / test / java / org / opendaylight / ovsdb / hwvtepsouthbound / UnMetDependencyGetterTest.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.ovsdb.hwvtepsouthbound;
10
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;
29
30 import java.util.List;
31 import java.util.Map;
32
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertNull;
35
36 @RunWith(PowerMockRunner.class)
37 @PrepareForTest({HwvtepConnectionInstance.class, HwvtepConnectionManager.class, Operations.class})
38 public class UnMetDependencyGetterTest extends DataChangeListenerTestBase {
39
40     UnMetDependencyGetter<RemoteMcastMacs> MCAST_MAC_DATA_VALIDATOR;
41     HwvtepOperationalState opState;
42     RemoteMcastMacs mac;
43     InstanceIdentifier<LogicalSwitches> lsIid;
44     Map<Class<? extends Identifiable>, List<InstanceIdentifier>> unMetDependencies;
45
46     void setupForTest() {
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")));
53     }
54
55     @Test
56     public void testLogicalSwitchConfigDependency() throws Exception {
57         setupForTest();
58         unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getInTransitDependencies(opState, mac);
59         assertEquals(0, unMetDependencies.size());
60
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());
64
65         opState.getDeviceInfo().updateConfigData(LogicalSwitches.class, lsIid, "ls0");
66         unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getUnMetConfigDependencies(opState, mac);
67         assertNull(unMetDependencies.get(LogicalSwitches.class));
68     }
69
70     @Test
71     public void testLogicalSwitchInTransitDependency() throws Exception {
72         setupForTest();
73         unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getInTransitDependencies(opState, mac);
74         assertEquals(0, unMetDependencies.size());
75
76         opState.getDeviceInfo().markKeyAsInTransit(LogicalSwitches.class, lsIid);
77         unMetDependencies = MCAST_MAC_DATA_VALIDATOR.getInTransitDependencies(opState, mac);
78         assertEquals(1, unMetDependencies.size());
79
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());
83     }
84 }