4fade11b2254ac1b19d6a8100886ce748b122391
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / lifecycle / ContextChainHolderImplTest.java
1 /**
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.impl.lifecycle;
9
10 import com.google.common.util.concurrent.Futures;
11 import io.netty.util.HashedWheelTimer;
12 import java.util.concurrent.ExecutorService;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
21 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
22 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
23 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
25 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
26 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
27 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
28 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
29 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
30
31 @RunWith(MockitoJUnitRunner.class)
32 public class ContextChainHolderImplTest {
33
34     @Mock
35     private HashedWheelTimer timer;
36     @Mock
37     private StatisticsManager statisticsManager;
38     @Mock
39     private RpcManager rpcManager;
40     @Mock
41     private DeviceManager deviceManager;
42     @Mock
43     private StatisticsContext statisticsContext;
44     @Mock
45     private RpcContext rpcContext;
46     @Mock
47     private DeviceContext deviceContext;
48     @Mock
49     private ConnectionContext connectionContext;
50     @Mock
51     private DeviceInfo deviceInfo;
52     @Mock
53     private ClusterSingletonServiceProvider singletonServicesProvider;
54     @Mock
55     private ExecutorService executorService;
56     @Mock
57     private ClusterSingletonServiceRegistration clusterSingletonServiceRegistration;
58
59     private ContextChainHolderImpl contextChainHolder;
60
61     @Before
62     public void setUp() throws Exception {
63         Mockito.doAnswer(invocation -> {
64             invocation.getArgumentAt(0, Runnable.class).run();
65             return null;
66         }).when(executorService).submit(Mockito.<Runnable>any());
67
68
69         Mockito.when(connectionContext.getDeviceInfo()).thenReturn(deviceInfo);
70         Mockito.when(deviceManager.createContext(connectionContext)).thenReturn(deviceContext);
71         Mockito.when(rpcManager.createContext(
72                 deviceInfo,
73                 deviceContext))
74                 .thenReturn(rpcContext);
75         Mockito.when(statisticsManager.createContext(deviceContext)).thenReturn(statisticsContext);
76         Mockito.when(deviceContext.makeDeviceSlave()).thenReturn(Futures.immediateFuture(null));
77         Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
78
79         Mockito.when(singletonServicesProvider.registerClusterSingletonService(Mockito.any()))
80                 .thenReturn(clusterSingletonServiceRegistration);
81         contextChainHolder = new ContextChainHolderImpl(timer, executorService);
82         contextChainHolder.addManager(statisticsManager);
83         contextChainHolder.addManager(rpcManager);
84         contextChainHolder.addManager(deviceManager);
85         contextChainHolder.addSingletonServicesProvider(singletonServicesProvider);
86     }
87
88     @Test
89     public void addManager() throws Exception {
90         Assert.assertTrue(contextChainHolder.checkAllManagers());
91     }
92
93     @Test
94     public void createContextChain() throws Exception {
95         contextChainHolder.createContextChain(connectionContext);
96         Mockito.verify(deviceManager).createContext(Mockito.any(ConnectionContext.class));
97         Mockito.verify(rpcManager).createContext(Mockito.any(DeviceInfo.class), Mockito.any(DeviceContext.class));
98         Mockito.verify(statisticsManager).createContext(Mockito.any(DeviceContext.class));
99     }
100
101     @Test
102     public void destroyContextChain() throws Exception {
103
104     }
105
106     @Test
107     public void pairConnection() throws Exception {
108
109     }
110
111     @Test
112     public void deviceConnected() throws Exception {
113
114     }
115
116     @Test
117     public void onNotAbleToStartMastership() throws Exception {
118
119     }
120
121     @Test
122     public void onMasterRoleAcquired() throws Exception {
123
124     }
125
126     @Test
127     public void onSlaveRoleAcquired() throws Exception {
128
129     }
130
131     @Test
132     public void onSlaveRoleNotAcquired() throws Exception {
133
134     }
135
136     @Test
137     public void onDeviceDisconnected() throws Exception {
138
139     }
140
141 }