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.mockito.Mockito;
19 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
20 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
21 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
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;
38 class StatisticsContextImpMockInitiation {
39 Boolean isTable = false;
40 Boolean isFlow = false;
41 Boolean isGroup = false;
42 Boolean isMeter = false;
43 Boolean isPort = false;
44 Boolean isQueue = false;
46 protected DeviceContext mockedDeviceContext;
47 protected DeviceState mockedDeviceState;
49 StatisticsGatheringService mockedStatisticsGatheringService;
50 StatisticsGatheringOnTheFlyService mockedStatisticsOnFlyGatheringService;
51 ConnectionContext mockedConnectionContext;
53 static final KeyedInstanceIdentifier<Node, NodeKey> dummyNodeII = InstanceIdentifier.create(Nodes.class)
54 .child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
56 LifecycleConductor mockConductor;
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);
66 final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
67 final MessageSpy mockedMessageSpy = mock(MessageSpy.class);
68 final OutboundQueue mockedOutboundQueue = mock(OutboundQueue.class);
69 final DeviceManager mockedDeviceManager = mock(DeviceManager.class);
70 final GetFeaturesOutput mockedFeaturesOutput = mock(GetFeaturesOutput.class);
72 mockConductor = mock(LifecycleConductor.class);
74 when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(isTable);
75 when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(isFlow);
76 when(mockedDeviceState.isGroupAvailable()).thenReturn(isGroup);
77 when(mockedDeviceState.isMetersAvailable()).thenReturn(isMeter);
78 when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(isPort);
79 when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(isQueue);
80 when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(dummyNodeII);
81 when(mockedDeviceState.getFeatures()).thenReturn(mockedFeaturesOutput);
83 when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
84 when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
85 when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
87 when(mockedConnectionContext.getNodeId()).thenReturn(dummyNodeII.getKey().getId());
88 when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
89 when(mockedConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
90 when(mockedConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
92 when(mockedDeviceManager.getDeviceContextFromNodeId(Mockito.<NodeId>any())).thenReturn(mockedDeviceContext);
93 mockConductor.setSafelyDeviceManager(mockedDeviceManager);
94 when(mockConductor.getDeviceContext(Mockito.<NodeId>any())).thenReturn(mockedDeviceContext);