fa0fcbf38da13736ed7d5f421156358072cdf6ba
[openflowplugin.git] / applications / forwardingrules-sync / src / test / java / org / opendaylight / openflowplugin / applications / frsync / impl / SyncReactorGuardDecoratorTest.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 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.SyncReactor;
20 import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27
28 /**
29  * Test for {@link SyncReactorGuardDecorator}.
30  */
31 @RunWith(MockitoJUnitRunner.class)
32 public class SyncReactorGuardDecoratorTest {
33
34     private static final NodeId NODE_ID = new NodeId("test-node");
35     private SyncReactorGuardDecorator reactor;
36     private InstanceIdentifier<FlowCapableNode> fcNodePath;
37
38     @Mock
39     private SyncReactor delegate;
40     @Mock
41     private FlowCapableNode fcConfigNode;
42     @Mock
43     private FlowCapableNode fcOperationalNode;
44     @Mock
45     private SyncupEntry syncupEntry;
46
47     @Before
48     public void setUp() throws Exception {
49         reactor = new SyncReactorGuardDecorator(delegate);
50         InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class)
51                 .child(Node.class, new NodeKey(NODE_ID));
52         fcNodePath = nodePath.augmentation(FlowCapableNode.class);
53
54         final Node operationalNode = Mockito.mock(Node.class);
55         Mockito.when(operationalNode.getId()).thenReturn(NODE_ID);
56         Mockito.when(operationalNode.getAugmentation(FlowCapableNode.class)).thenReturn(fcOperationalNode);
57     }
58
59     @Test
60     public void testSyncupSuccess() {
61         Mockito.when(delegate.syncup(Matchers.any(), Matchers.any()))
62                 .thenReturn(Futures.immediateFuture(Boolean.TRUE));
63
64         reactor.syncup(fcNodePath, syncupEntry);
65
66         Mockito.verify(delegate).syncup(fcNodePath, syncupEntry);
67         Mockito.verifyNoMoreInteractions(delegate);
68     }
69
70     @Test
71     public void testSyncupFail() {
72         Mockito.when(delegate.syncup(Matchers.any(), Matchers.any()))
73                 .thenReturn(Futures.immediateFailedFuture(new Exception()));
74
75         reactor.syncup(fcNodePath, syncupEntry);
76
77         Mockito.verify(delegate).syncup(fcNodePath, syncupEntry);
78         Mockito.verifyNoMoreInteractions(delegate);
79     }
80 }