Bump upstreams
[openflowplugin.git] / applications / forwardingrules-sync / src / test / java / org / opendaylight / openflowplugin / applications / frsync / impl / clustering / DeviceMastershipTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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 package org.opendaylight.openflowplugin.applications.frsync.impl.clustering;
9
10 import org.junit.Assert;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.mockito.Mock;
15 import org.mockito.Mockito;
16 import org.mockito.junit.MockitoJUnitRunner;
17 import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
18 import org.opendaylight.openflowplugin.applications.frsync.util.ReconciliationRegistry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
20
21 /**
22  * Test for {@link DeviceMastership}.
23  */
24 @RunWith(MockitoJUnitRunner.class)
25 public class DeviceMastershipTest {
26     private static final NodeId NODE_ID = new NodeId("testNode");
27     private DeviceMastership deviceMastership;
28
29     @Mock
30     private DeviceMastershipManager deviceMastershipManager;
31     @Mock
32     private ReconciliationRegistry reconciliationRegistry;
33
34     @Before
35     public void setUp() {
36         deviceMastership = new DeviceMastership(NODE_ID, reconciliationRegistry,
37                 Mockito.mock(ClusterSingletonServiceProvider.class));
38     }
39
40     @Test
41     public void testInstantiateServiceInstance() {
42         deviceMastership.instantiateServiceInstance();
43         Mockito.verify(reconciliationRegistry).register(NODE_ID);
44         Assert.assertTrue(deviceMastership.isDeviceMastered());
45     }
46
47     @Test
48     public void testCloseServiceInstance() {
49         deviceMastership.closeServiceInstance();
50         Mockito.verify(reconciliationRegistry).unregisterIfRegistered(NODE_ID);
51         Assert.assertFalse(deviceMastership.isDeviceMastered());
52     }
53
54 }