Merge "BUG-4068: RpcContextImpl doesn't close rpcRegistrations correctly"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / ServiceMocking.java
1 package org.opendaylight.openflowplugin.impl.services;
2
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;
18
19 import java.math.BigInteger;
20
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.when;
23
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;
28
29     @Mock
30     RequestContextStack mockedRequestContextStack;
31     @Mock
32     ConnectionContext mockedPrimConnectionContext;
33     @Mock
34     FeaturesReply mockedFeatures;
35     @Mock
36     ConnectionAdapter mockedConnectionAdapter;
37     @Mock
38     MessageSpy mockedMessagSpy;
39     @Mock
40     DeviceContext mockedDeviceContext;
41     @Mock
42     DeviceState mockedDeviceState;
43     @Mock
44     DeviceInitializationPhaseHandler mockedDevicePhaseHandler;
45
46     @Before
47     public void initialization() {
48         when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
49         when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION);
50
51         when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures);
52         when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
53         when(mockedPrimConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
54
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));
60     }
61
62 }