3fdd2e054cd3c559c116fa7e7195beff551ca3cc
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / StatisticsContextImpMockInitiation.java
1 /*
2  * Copyright (c) 2015 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.impl.statistics;
10
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.when;
13
14 import java.math.BigInteger;
15 import org.junit.Before;
16 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
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.device.DeviceManager;
21 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
22 import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipWatcher;
23 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
24 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
25 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringOnTheFlyService;
26 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
35
36
37 class StatisticsContextImpMockInitiation {
38     Boolean isTable = false;
39     Boolean isFlow = false;
40     Boolean isGroup = false;
41     Boolean isMeter = false;
42     Boolean isPort = false;
43     Boolean isQueue = false;
44
45     protected DeviceContext mockedDeviceContext;
46     protected DeviceState mockedDeviceState;
47
48     StatisticsGatheringService<MultipartReply> mockedStatisticsGatheringService;
49     StatisticsGatheringOnTheFlyService<MultipartReply> mockedStatisticsOnFlyGatheringService;
50     ConnectionContext mockedConnectionContext;
51     DeviceInfo mockedDeviceInfo;
52     StatisticsManager mockedStatisticsManager;
53     ContextChainMastershipWatcher mockedMastershipWatcher;
54
55     static final KeyedInstanceIdentifier<Node, NodeKey> DUMMY_NODE_ID = InstanceIdentifier.create(Nodes.class)
56             .child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
57
58     @Before
59     public void initialize() {
60         mockedDeviceContext = mock(DeviceContext.class);
61         mockedStatisticsGatheringService = mock(StatisticsGatheringService.class);
62         mockedStatisticsOnFlyGatheringService = mock(StatisticsGatheringOnTheFlyService.class);
63         mockedConnectionContext = mock(ConnectionContext.class);
64         mockedDeviceState = mock(DeviceState.class);
65         mockedDeviceInfo = mock(DeviceInfo.class);
66         mockedStatisticsManager = mock(StatisticsManager.class);
67         mockedMastershipWatcher = mock(ContextChainMastershipWatcher.class);
68
69         final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
70         final MessageSpy mockedMessageSpy = mock(MessageSpy.class);
71         final OutboundQueue mockedOutboundQueue = mock(OutboundQueue.class);
72         final DeviceManager mockedDeviceManager = mock(DeviceManager.class);
73
74         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
75         when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
76         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
77         when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
78
79         when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(isTable);
80         when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(isFlow);
81         when(mockedDeviceState.isGroupAvailable()).thenReturn(isGroup);
82         when(mockedDeviceState.isMetersAvailable()).thenReturn(isMeter);
83         when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(isPort);
84         when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(isQueue);
85         when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(DUMMY_NODE_ID);
86         when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
87
88         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
89         when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
90         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
91         when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
92         when(mockedDeviceInfo.getNodeId()).thenReturn(DUMMY_NODE_ID.getKey().getId());
93
94         when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
95         when(mockedConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
96
97     }
98 }