1 package org.opendaylight.openflowplugin.impl.services;
3 import io.netty.util.HashedWheelTimer;
4 import org.junit.Before;
5 import org.junit.runner.RunWith;
6 import org.mockito.Mock;
7 import org.mockito.runners.MockitoJUnitRunner;
8 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
9 import org.opendaylight.openflowplugin.api.OFConstants;
10 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
11 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
13 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
14 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
15 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
16 import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
19 import java.math.BigInteger;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.when;
24 @RunWith(MockitoJUnitRunner.class)
25 public abstract class ServiceMocking {
26 private static final BigInteger DUMMY_DATAPATH_ID = new BigInteger("444");
27 private static final Short DUMMY_VERSION = OFConstants.OFP_VERSION_1_3;
30 RequestContextStack mockedRequestContextStack;
32 ConnectionContext mockedPrimConnectionContext;
34 FeaturesReply mockedFeatures;
36 ConnectionAdapter mockedConnectionAdapter;
38 MessageSpy mockedMessagSpy;
40 DeviceContext mockedDeviceContext;
42 DeviceState mockedDeviceState;
44 DeviceInitializationPhaseHandler mockedDevicePhaseHandler;
47 public void initialization() {
48 when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
49 when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION);
51 when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures);
52 when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
53 when(mockedPrimConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
55 when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
56 when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
57 when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl());
58 when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
59 when(mockedDeviceContext.getTimer()).thenReturn(mock(HashedWheelTimer.class));