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