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