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.services;
11 import static org.mockito.ArgumentMatchers.any;
13 import com.google.common.util.concurrent.FutureCallback;
14 import org.junit.Before;
15 import org.junit.runner.RunWith;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.junit.MockitoJUnitRunner;
19 import org.mockito.stubbing.Answer;
20 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
21 import org.opendaylight.openflowplugin.api.OFConstants;
22 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
23 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
25 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
26 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
27 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
28 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
29 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
30 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 import org.opendaylight.yangtools.yang.common.Uint64;
43 * Created by mirehak on 7/23/15.
45 @RunWith(MockitoJUnitRunner.class)
46 public abstract class AbstractStatsServiceTest {
48 protected RequestContextStack rqContextStack;
50 protected DeviceContext deviceContext;
52 protected ConnectionContext connectionContext;
54 protected FeaturesReply features;
56 private GetFeaturesOutput getFeaturesOutput;
58 protected MessageSpy messageSpy;
60 protected OutboundQueue outboundQueueProvider;
62 protected MultiMsgCollector multiMsgCollector;
64 protected TranslatorLibrary translatorLibrary;
66 protected DeviceState deviceState;
68 protected DeviceInfo deviceInfo;
71 public static final NodeId NODE_ID = new NodeId("unit-test-node:123");
73 protected final Answer<Void> answerVoidToCallback = invocation -> {
74 final FutureCallback<OfHeader> callback = (FutureCallback<OfHeader>) invocation.getArguments()[2];
75 callback.onSuccess(null);
80 public void init() throws Exception {
81 Mockito.lenient().when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
82 Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
83 Mockito.lenient().when(deviceContext.getMultiMsgCollector(any(RequestContext.class)))
84 .thenReturn(multiMsgCollector);
85 Mockito.lenient().when(deviceContext.oook()).thenReturn(translatorLibrary);
86 Mockito.lenient().when(deviceContext.getDeviceState()).thenReturn(deviceState);
87 Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
88 Mockito.lenient().when(deviceInfo.getNodeId()).thenReturn(NODE_ID);
89 Mockito.lenient().when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
90 Mockito.lenient().when(deviceInfo.getDatapathId()).thenReturn(Uint64.valueOf(10));
91 Mockito.lenient().when(connectionContext.getFeatures()).thenReturn(features);
92 Mockito.lenient().when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
93 Mockito.lenient().when(features.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
94 Mockito.lenient().when(getFeaturesOutput.getDatapathId()).thenReturn(Uint64.valueOf(123L));
95 Mockito.lenient().when(getFeaturesOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
100 protected void setUp() {
104 protected static NodeRef createNodeRef(final String nodeIdValue) {
105 InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class)
106 .child(Node.class, new NodeKey(new NodeId(nodeIdValue)));
107 return new NodeRef(nodePath);