2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
8 package org.opendaylight.openflowplugin.impl.lifecycle;
10 import com.google.common.util.concurrent.Futures;
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.api.openflow.connection.ConnectionContext;
18 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
19 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
20 import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain;
21 import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipState;
22 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
23 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
24 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
26 @RunWith(MockitoJUnitRunner.class)
27 public class ContextChainImplTest {
30 private StatisticsContext statisticsContext;
32 private RpcContext rpcContext;
34 private DeviceContext deviceContext;
36 private LifecycleService lifecycleService;
38 private DeviceInfo deviceInfo;
40 private ConnectionContext connectionContext;
42 private ContextChain contextChain;
45 public void setUp() throws Exception {
47 Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
48 Mockito.when(deviceContext.stopClusterServices())
49 .thenReturn(Futures.immediateFuture(null));
50 Mockito.when(rpcContext.stopClusterServices()).thenReturn(Futures.immediateFuture(null));
51 Mockito.when(statisticsContext.stopClusterServices()).thenReturn(Futures.immediateFuture(null));
52 Mockito.when(statisticsContext.initialGatherDynamicData()).thenReturn(Futures.immediateFuture(null));
53 Mockito.when(connectionContext.getDeviceInfo()).thenReturn(deviceInfo);
55 contextChain = new ContextChainImpl(connectionContext);
56 contextChain.addContext(statisticsContext);
57 contextChain.addContext(rpcContext);
58 contextChain.addContext(deviceContext);
59 contextChain.addLifecycleService(lifecycleService);
64 public void stopChain() throws Exception {
65 contextChain.stopChain();
66 Mockito.verify(deviceContext).stopClusterServices();
67 Mockito.verify(rpcContext).stopClusterServices();
68 Mockito.verify(statisticsContext).stopClusterServices();
72 public void close() throws Exception {
74 Mockito.verify(statisticsContext).close();
75 Mockito.verify(deviceContext).close();
76 Mockito.verify(rpcContext).close();
77 Mockito.verify(lifecycleService).close();
81 public void connectionDropped() throws Exception {
82 contextChain.isMastered(ContextChainMastershipState.INITIAL_GATHERING);
83 contextChain.isMastered(ContextChainMastershipState.INITIAL_SUBMIT);
84 contextChain.isMastered(ContextChainMastershipState.MASTER_ON_DEVICE);
85 contextChain.isMastered(ContextChainMastershipState.INITIAL_FLOW_REGISTRY_FILL);
86 contextChain.connectionDropped();
87 Mockito.verify(deviceContext).stopClusterServices();
88 Mockito.verify(rpcContext).stopClusterServices();
89 Mockito.verify(statisticsContext).stopClusterServices();
93 public void makeDeviceSlave() throws Exception {
94 contextChain.makeDeviceSlave();
95 Mockito.verify(lifecycleService).makeDeviceSlave(Mockito.any(DeviceContext.class));