2 * Copyright (c) 2015 Cisco Systems, Inc. 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.openflowplugin.impl.device;
11 import junit.framework.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.Mock;
16 import org.mockito.Mockito;
17 import org.mockito.runners.MockitoJUnitRunner;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
20 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
23 @RunWith(MockitoJUnitRunner.class)
24 public class DeviceTransactionChainManagerProviderTest {
28 DataBroker dataBroker;
30 ConnectionContext connectionContext;
32 ConnectionContext concurrentConnectionContex;
35 DeviceManager deviceManager;
37 private static final NodeId nodeId = new NodeId("OPF:TEST");
38 private DeviceTransactionChainManagerProvider deviceTransactionChainManagerProvider;
42 deviceTransactionChainManagerProvider = new DeviceTransactionChainManagerProvider(dataBroker);
43 Mockito.when(connectionContext.getNodeId()).thenReturn(nodeId);
44 Mockito.when(concurrentConnectionContex.getNodeId()).thenReturn(nodeId);
48 * This test verifies code path for registering new connection when no {@link org.opendaylight.openflowplugin.impl.device.TransactionChainManager}
49 * is present in registry.
54 public void testProvideTransactionChainManagerOrWaitForNotification1() throws Exception {
55 DeviceTransactionChainManagerProvider.TransactionChainManagerRegistration transactionChainManagerRegistration = deviceTransactionChainManagerProvider.provideTransactionChainManager(connectionContext);
56 Assert.assertTrue(transactionChainManagerRegistration.ownedByInvokingConnectionContext());
60 * This test verifies code path for registering new connection when {@link org.opendaylight.openflowplugin.impl.device.TransactionChainManager}
61 * is present in registry.
66 public void testProvideTransactionChainManagerOrWaitForNotification2() throws Exception {
67 DeviceTransactionChainManagerProvider.TransactionChainManagerRegistration transactionChainManagerRegistration_1 = deviceTransactionChainManagerProvider.provideTransactionChainManager(connectionContext);
68 Assert.assertTrue(TransactionChainManager.TransactionChainManagerStatus.WORKING.equals(transactionChainManagerRegistration_1.getTransactionChainManager().getTransactionChainManagerStatus()));
69 DeviceTransactionChainManagerProvider.TransactionChainManagerRegistration transactionChainManagerRegistration_2 = deviceTransactionChainManagerProvider.provideTransactionChainManager(concurrentConnectionContex);
70 Assert.assertFalse(transactionChainManagerRegistration_2.ownedByInvokingConnectionContext());