FRS - sonar issues and repackage
[openflowplugin.git] / applications / forwardingrules-sync / src / test / java / org / opendaylight / openflowplugin / applications / frsync / impl / SyncReactorClusterDecoratorTest.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
9 package org.opendaylight.openflowplugin.applications.frsync.impl;
10
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.runners.MockitoJUnitRunner;
17 import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
18 import org.opendaylight.openflowplugin.applications.frsync.impl.clustering.DeviceMastershipManager;
19 import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26
27 /**
28  * Test for {@link SyncReactorClusterDecorator}.
29  */
30 @RunWith(MockitoJUnitRunner.class)
31 public class SyncReactorClusterDecoratorTest {
32
33     private static final NodeId NODE_ID = new NodeId("test-node");
34     private SyncReactorClusterDecorator reactor;
35     private InstanceIdentifier<FlowCapableNode> fcNodePath;
36
37     @Mock
38     private SyncReactor delegate;
39     @Mock
40     private DeviceMastershipManager deviceMastershipManager;
41     @Mock
42     private SyncupEntry syncupEntry;
43
44     @Before
45     public void setUp() {
46         reactor = new SyncReactorClusterDecorator(delegate, deviceMastershipManager);
47
48         InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(NODE_ID));
49         fcNodePath = nodePath.augmentation(FlowCapableNode.class);
50     }
51
52     @Test
53     public void testSyncupMaster() throws InterruptedException {
54         Mockito.when(deviceMastershipManager.isDeviceMastered(NODE_ID)).thenReturn(true);
55
56         reactor.syncup(fcNodePath, syncupEntry);
57
58         Mockito.verify(delegate).syncup(fcNodePath, syncupEntry);
59         Mockito.verifyNoMoreInteractions(delegate);
60     }
61
62     @Test
63     public void testSyncupSlave() throws InterruptedException {
64         Mockito.when(deviceMastershipManager.isDeviceMastered(NODE_ID)).thenReturn(false);
65
66         reactor.syncup(fcNodePath, syncupEntry);
67
68         Mockito.verifyZeroInteractions(delegate);
69     }
70
71 }