3 * * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
5 * * This program and the accompanying materials are made available under the
6 * * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * * and is available at http://www.eclipse.org/legal/epl-v10.html
12 package org.opendaylight.openflowplugin.impl.statistics;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
17 import org.junit.Before;
18 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
19 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
20 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
21 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
22 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
23 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
24 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
25 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
26 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringOnTheFlyService;
27 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
37 import java.math.BigInteger;
40 class StatisticsContextImpMockInitiation {
41 Boolean isTable = false;
42 Boolean isFlow = false;
43 Boolean isGroup = false;
44 Boolean isMeter = false;
45 Boolean isPort = false;
46 Boolean isQueue = false;
48 protected DeviceContext mockedDeviceContext;
49 protected DeviceState mockedDeviceState;
51 StatisticsGatheringService mockedStatisticsGatheringService;
52 StatisticsGatheringOnTheFlyService mockedStatisticsOnFlyGatheringService;
53 ConnectionContext mockedConnectionContext;
54 DeviceInfo mockedDeviceInfo;
56 static final KeyedInstanceIdentifier<Node, NodeKey> dummyNodeII = InstanceIdentifier.create(Nodes.class)
57 .child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
59 LifecycleConductor mockConductor;
62 public void initialize() {
63 mockedDeviceContext = mock(DeviceContext.class);
64 mockedStatisticsGatheringService = mock(StatisticsGatheringService.class);
65 mockedStatisticsOnFlyGatheringService = mock(StatisticsGatheringOnTheFlyService.class);
66 mockedConnectionContext = mock(ConnectionContext.class);
67 mockedDeviceState = mock(DeviceState.class);
68 mockedDeviceInfo = mock(DeviceInfo.class);
70 final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
71 final MessageSpy mockedMessageSpy = mock(MessageSpy.class);
72 final OutboundQueue mockedOutboundQueue = mock(OutboundQueue.class);
73 final DeviceManager mockedDeviceManager = mock(DeviceManager.class);
74 final GetFeaturesOutput mockedFeaturesOutput = mock(GetFeaturesOutput.class);
76 mockConductor = mock(LifecycleConductor.class);
78 when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(isTable);
79 when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(isFlow);
80 when(mockedDeviceState.isGroupAvailable()).thenReturn(isGroup);
81 when(mockedDeviceState.isMetersAvailable()).thenReturn(isMeter);
82 when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(isPort);
83 when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(isQueue);
84 when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(dummyNodeII);
85 when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
87 when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
88 when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
89 when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
90 when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
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 when(mockedDeviceManager.getDeviceContextFromNodeId(mockedDeviceInfo)).thenReturn(mockedDeviceContext);
98 mockConductor.setSafelyDeviceManager(mockedDeviceManager);
99 when(mockConductor.getDeviceContext(mockedDeviceInfo)).thenReturn(mockedDeviceContext);