f4f2ab6af870c0356e1ac63fb6cc608c7a99ffe4
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / direct / AbstractDirectStatisticsServiceTest.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.services.direct;
10
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.mockito.Mock;
15 import org.mockito.runners.MockitoJUnitRunner;
16 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
17 import org.opendaylight.openflowplugin.api.OFConstants;
18 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
19 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
20 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
21 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
22 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
23 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
24 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
25 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
26 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
27 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
28 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
39
40 import java.math.BigInteger;
41
42 import static org.mockito.Matchers.any;
43 import static org.mockito.Mockito.when;
44
45 @RunWith(MockitoJUnitRunner.class)
46 public abstract class AbstractDirectStatisticsServiceTest {
47     protected static final Long PORT_NO = 1L;
48     protected static final BigInteger DATAPATH_ID = BigInteger.TEN;
49     protected static final short OF_VERSION = OFConstants.OFP_VERSION_1_3;
50     protected static final String NODE_ID = "openflow:1";
51
52     @Mock
53     protected RequestContextStack requestContextStack;
54     @Mock
55     protected DeviceContext deviceContext;
56     @Mock
57     protected ConnectionContext connectionContext;
58     @Mock
59     protected FeaturesReply features;
60     @Mock
61     protected MessageSpy messageSpy;
62     @Mock
63     protected OutboundQueue outboundQueueProvider;
64     @Mock
65     protected MultiMsgCollector multiMsgCollector;
66     @Mock
67     protected TranslatorLibrary translatorLibrary;
68     @Mock
69     protected DeviceState deviceState;
70     @Mock
71     protected DeviceInfo deviceInfo;
72     @Mock
73     protected GetFeaturesOutput getFeaturesOutput;
74
75     protected NodeConnectorId nodeConnectorId;
76     protected KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
77
78     protected static NodeRef createNodeRef(String nodeIdValue) {
79         InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class)
80                 .child(Node.class, new NodeKey(new NodeId(nodeIdValue)));
81
82         return new NodeRef(nodePath);
83     }
84
85     @Before
86     public void init() throws Exception {
87         OpenflowPortsUtil.init();
88
89         nodeConnectorId = InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(
90                 DATAPATH_ID, PORT_NO, OpenflowVersion.get(OF_VERSION));
91
92         nodeInstanceIdentifier = InstanceIdentifier
93                 .create(Nodes.class)
94                 .child(Node.class, new NodeKey(new NodeId(NODE_ID)));
95
96         when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
97         when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
98         when(deviceContext.getMultiMsgCollector(any())).thenReturn(multiMsgCollector);
99         when(deviceContext.oook()).thenReturn(translatorLibrary);
100         when(deviceContext.getDeviceState()).thenReturn(deviceState);
101         when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
102         when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
103         when(deviceInfo.getNodeId()).thenReturn(new NodeId(NODE_ID));
104         when(deviceInfo.getVersion()).thenReturn(OF_VERSION);
105         when(deviceInfo.getDatapathId()).thenReturn(DATAPATH_ID);
106         when(getFeaturesOutput.getVersion()).thenReturn(OF_VERSION);
107         when(getFeaturesOutput.getDatapathId()).thenReturn(DATAPATH_ID);
108         when(connectionContext.getFeatures()).thenReturn(features);
109         when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
110         when(features.getVersion()).thenReturn(OF_VERSION);
111         when(features.getDatapathId()).thenReturn(DATAPATH_ID);
112         setUp();
113     }
114
115     protected abstract void setUp() throws Exception;
116
117     @Test
118     public abstract void testBuildRequestBody() throws Exception;
119
120     @Test
121     public abstract void testBuildReply() throws Exception;
122
123     @Test
124     public abstract void testStoreStatistics() throws Exception;
125 }