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 com.google.common.util.concurrent.Futures;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.Matchers;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.runners.MockitoJUnitRunner;
19 import org.opendaylight.openflowplugin.applications.frsync.util.SemaphoreKeeperGuavaImpl;
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 SyncReactorGuardDecorator}.
30 @RunWith(MockitoJUnitRunner.class)
31 public class SyncReactorGuardDecoratorTest {
33 private static final NodeId NODE_ID = new NodeId("test-node");
34 private SyncReactorGuardDecorator reactor;
35 private InstanceIdentifier<FlowCapableNode> fcNodePath;
38 private SyncReactorImpl delegate;
40 private FlowCapableNode fcConfigNode;
42 private FlowCapableNode fcOperationalNode;
45 public void setUp() throws Exception {
46 reactor = new SyncReactorGuardDecorator(delegate, new SemaphoreKeeperGuavaImpl<InstanceIdentifier<FlowCapableNode>>(1, true));
47 InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(NODE_ID));
48 fcNodePath = nodePath.augmentation(FlowCapableNode.class);
50 final Node operationalNode = Mockito.mock(Node.class);
51 Mockito.when(operationalNode.getId()).thenReturn(NODE_ID);
52 Mockito.when(operationalNode.getAugmentation(FlowCapableNode.class)).thenReturn(fcOperationalNode);
56 public void testSyncupSuccess() throws Exception {
57 Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(),Matchers.<FlowCapableNode>any(),
58 Matchers.<FlowCapableNode>any())).thenReturn(Futures.immediateFuture(Boolean.TRUE));
59 reactor.syncup(fcNodePath, fcConfigNode, fcOperationalNode);
60 Mockito.verify(delegate).syncup(fcNodePath, fcConfigNode, fcOperationalNode);
65 public void testSyncupFail() throws Exception {
66 Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(),Matchers.<FlowCapableNode>any(),
67 Matchers.<FlowCapableNode>any())).thenReturn(Futures.immediateFailedFuture(new Exception()));
68 reactor.syncup(fcNodePath, fcConfigNode, fcOperationalNode);
69 Mockito.verify(delegate).syncup(fcNodePath, fcConfigNode, fcOperationalNode);