2 * Copyright (c) 2016 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.applications.frsync.impl;
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;
28 * Test for {@link SyncReactorClusterDecorator}.
30 @RunWith(MockitoJUnitRunner.class)
31 public class SyncReactorClusterDecoratorTest {
33 private static final NodeId NODE_ID = new NodeId("test-node");
34 private SyncReactorClusterDecorator reactor;
35 private InstanceIdentifier<FlowCapableNode> fcNodePath;
38 private SyncReactor delegate;
40 private DeviceMastershipManager deviceMastershipManager;
42 private SyncupEntry syncupEntry;
46 reactor = new SyncReactorClusterDecorator(delegate, deviceMastershipManager);
48 InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(NODE_ID));
49 fcNodePath = nodePath.augmentation(FlowCapableNode.class);
53 public void testSyncupMaster() {
54 Mockito.when(deviceMastershipManager.isDeviceMastered(NODE_ID)).thenReturn(true);
56 reactor.syncup(fcNodePath, syncupEntry);
58 Mockito.verify(delegate).syncup(fcNodePath, syncupEntry);
59 Mockito.verifyNoMoreInteractions(delegate);
63 public void testSyncupSlave() {
64 Mockito.when(deviceMastershipManager.isDeviceMastered(NODE_ID)).thenReturn(false);
66 reactor.syncup(fcNodePath, syncupEntry);
68 Mockito.verifyZeroInteractions(delegate);