Fix context chain initialization and SLAVE change
[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.statistics.StatisticsManager;
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.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
34
35
36 class StatisticsContextImpMockInitiation {
37     Boolean isTable = false;
38     Boolean isFlow = false;
39     Boolean isGroup = false;
40     Boolean isMeter = false;
41     Boolean isPort = false;
42     Boolean isQueue = false;
43
44     protected DeviceContext mockedDeviceContext;
45     protected DeviceState mockedDeviceState;
46
47     StatisticsGatheringService<MultipartReply> mockedStatisticsGatheringService;
48     StatisticsGatheringOnTheFlyService<MultipartReply> mockedStatisticsOnFlyGatheringService;
49     ConnectionContext mockedConnectionContext;
50     DeviceInfo mockedDeviceInfo;
51     StatisticsManager mockedStatisticsManager;
52
53     static final KeyedInstanceIdentifier<Node, NodeKey> dummyNodeII = InstanceIdentifier.create(Nodes.class)
54             .child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
55
56     @Before
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);
64         mockedStatisticsManager = mock(StatisticsManager.class);
65
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
71         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
72         when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
73         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
74         when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
75
76         when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(isTable);
77         when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(isFlow);
78         when(mockedDeviceState.isGroupAvailable()).thenReturn(isGroup);
79         when(mockedDeviceState.isMetersAvailable()).thenReturn(isMeter);
80         when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(isPort);
81         when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(isQueue);
82         when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(dummyNodeII);
83         when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
84
85         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
86         when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
87         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
88         when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
89         when(mockedDeviceInfo.getNodeId()).thenReturn(dummyNodeII.getKey().getId());
90
91         when(mockedConnectionContext.getNodeId()).thenReturn(dummyNodeII.getKey().getId());
92         when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
93         when(mockedConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
94         when(mockedConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
95
96     }
97 }