2 * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.openflowplugin.impl.statistics;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.when;
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.LifecycleConductor;
23 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
24 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringOnTheFlyService;
25 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
35 class StatisticsContextImpMockInitiation {
36 Boolean isTable = false;
37 Boolean isFlow = false;
38 Boolean isGroup = false;
39 Boolean isMeter = false;
40 Boolean isPort = false;
41 Boolean isQueue = false;
43 protected DeviceContext mockedDeviceContext;
44 protected DeviceState mockedDeviceState;
46 StatisticsGatheringService mockedStatisticsGatheringService;
47 StatisticsGatheringOnTheFlyService mockedStatisticsOnFlyGatheringService;
48 ConnectionContext mockedConnectionContext;
49 DeviceInfo mockedDeviceInfo;
51 static final KeyedInstanceIdentifier<Node, NodeKey> dummyNodeII = InstanceIdentifier.create(Nodes.class)
52 .child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
54 LifecycleConductor mockConductor;
57 public void initialize() {
58 mockedDeviceContext = mock(DeviceContext.class);
59 mockedStatisticsGatheringService = mock(StatisticsGatheringService.class);
60 mockedStatisticsOnFlyGatheringService = mock(StatisticsGatheringOnTheFlyService.class);
61 mockedConnectionContext = mock(ConnectionContext.class);
62 mockedDeviceState = mock(DeviceState.class);
63 mockedDeviceInfo = mock(DeviceInfo.class);
65 final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
66 final MessageSpy mockedMessageSpy = mock(MessageSpy.class);
67 final OutboundQueue mockedOutboundQueue = mock(OutboundQueue.class);
68 final DeviceManager mockedDeviceManager = mock(DeviceManager.class);
70 mockConductor = mock(LifecycleConductor.class);
72 when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
73 when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
74 when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
75 when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
77 when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(isTable);
78 when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(isFlow);
79 when(mockedDeviceState.isGroupAvailable()).thenReturn(isGroup);
80 when(mockedDeviceState.isMetersAvailable()).thenReturn(isMeter);
81 when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(isPort);
82 when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(isQueue);
83 when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(dummyNodeII);
84 when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
86 when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
87 when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
88 when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
89 when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
90 when(mockedDeviceInfo.getNodeId()).thenReturn(dummyNodeII.getKey().getId());
92 when(mockedConnectionContext.getNodeId()).thenReturn(dummyNodeII.getKey().getId());
93 when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
94 when(mockedConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
95 when(mockedConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
97 mockConductor.setSafelyManager(mockedDeviceManager);
98 when(mockConductor.getDeviceContext(mockedDeviceInfo)).thenReturn(mockedDeviceContext);