Bug 7915 - Zero flows populated in all switches when connected to Leader Node
[openflowplugin.git] / applications / forwardingrules-manager / src / test / java / org / opendaylight / openflowplugin / applications / frm / impl / DeviceMastershipTest.java
1 /**
2  * Copyright (c) 2016, 2017 Pantheon Technologies s.r.o. 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.openflowplugin.applications.frm.impl;
10
11 import org.junit.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.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
19 import org.opendaylight.openflowplugin.applications.frm.FlowNodeReconciliation;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
21
22 /**
23  * Test for {@link DeviceMastership}.
24  */
25 @RunWith(MockitoJUnitRunner.class)
26 public class DeviceMastershipTest {
27     private static final NodeId NODE_ID = new NodeId("testNode");
28     private DeviceMastership deviceMastership;
29
30     @Mock
31     private DeviceMastershipManager deviceMastershipManager;
32
33     @Mock
34     private FlowNodeReconciliation reconcliationAgent;
35
36     @Before
37     public void setUp() throws Exception {
38         deviceMastership = new DeviceMastership(NODE_ID, Mockito.mock(ClusterSingletonServiceProvider.class), reconcliationAgent);
39     }
40
41     @Test
42     public void testInstantiateServiceInstance() {
43         deviceMastership.instantiateServiceInstance();
44         Assert.assertTrue(deviceMastership.isDeviceMastered());
45     }
46
47     @Test
48     public void testCloseServiceInstance() {
49         deviceMastership.closeServiceInstance();
50         Assert.assertFalse(deviceMastership.isDeviceMastered());
51     }
52
53 }