77ad5c4d2bdc316d1998423511b74e3d42a51995
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / test / java / org / opendaylight / ovsdb / hwvtepsouthbound / HwvtepOperationalStateTest.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.controller.md.sal.binding.test.AbstractDataBrokerTest;
14 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.HwvtepOperationalState;
15 import org.opendaylight.ovsdb.lib.notation.UUID;
16 import org.opendaylight.ovsdb.lib.operations.Operations;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.powermock.core.classloader.annotations.PrepareForTest;
24 import org.powermock.modules.junit4.PowerMockRunner;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.assertNotNull;
31 import static org.mockito.Mockito.when;
32 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
33
34 @RunWith(PowerMockRunner.class)
35 @PrepareForTest({HwvtepConnectionInstance.class, HwvtepConnectionManager.class, Operations.class})
36 public class HwvtepOperationalStateTest extends DataChangeListenerTestBase {
37
38     UUID uuid = new UUID("ls0");
39
40     @Test
41     public void testUpdateCurrentTxData() throws Exception {
42         InstanceIdentifier<LogicalSwitches> lsIid = nodeIid.augmentation(HwvtepGlobalAugmentation.class).
43                 child(LogicalSwitches.class, new LogicalSwitchesKey(new HwvtepNodeName("ls0")));
44
45         HwvtepOperationalState opState = new HwvtepOperationalState(connectionInstance);
46
47         UUID resultUuid = opState.getUUIDFromCurrentTx(LogicalSwitches.class, lsIid);
48         assertNull(resultUuid);
49
50         opState.updateCurrentTxData(LogicalSwitches.class, lsIid, uuid);
51         resultUuid = opState.getUUIDFromCurrentTx(LogicalSwitches.class, lsIid);
52         assertEquals(uuid, resultUuid);
53
54         boolean result = opState.getDeviceInfo().isKeyInTransit(LogicalSwitches.class, lsIid);
55         assertTrue(result);
56
57         opState.getDeviceInfo().updateDeviceOpData(LogicalSwitches.class, lsIid, uuid, lsIid);
58         result = opState.getDeviceInfo().isKeyInTransit(LogicalSwitches.class, lsIid);
59         assertFalse(result);
60
61         result = opState.getDeviceInfo().isConfigDataAvailable(LogicalSwitches.class, lsIid);
62         assertFalse(result);
63
64         opState.getDeviceInfo().updateConfigData(LogicalSwitches.class, lsIid, null);
65         result = opState.getDeviceInfo().isConfigDataAvailable(LogicalSwitches.class, lsIid);
66         assertTrue(result);
67     }
68 }