OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[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.ArgumentMatchers.any;
12 import static org.mockito.Mockito.lenient;
13 import static org.mockito.Mockito.when;
14
15 import java.math.BigInteger;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
22 import org.opendaylight.openflowplugin.api.OFConstants;
23 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
25 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
26 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
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.md.util.OpenflowVersion;
31 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
32 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
33 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
34 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
35 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
36 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory;
37 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
38 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
39 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
48 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
49 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
50
51 @RunWith(MockitoJUnitRunner.class)
52 public abstract class AbstractDirectStatisticsServiceTest {
53     protected static final Long PORT_NO = 1L;
54     protected static final BigInteger DATAPATH_ID = BigInteger.TEN;
55     protected static final short OF_VERSION = OFConstants.OFP_VERSION_1_3;
56     protected static final String NODE_ID = "openflow:10";
57
58     @Mock
59     protected RequestContextStack requestContextStack;
60     @Mock
61     protected DeviceFlowRegistry deviceFlowRegistry;
62     @Mock
63     protected DeviceGroupRegistry deviceGroupRegistry;
64     @Mock
65     protected DeviceMeterRegistry deviceMeterRegistry;
66     @Mock
67     protected DeviceContext deviceContext;
68     @Mock
69     protected ConnectionContext connectionContext;
70     @Mock
71     protected FeaturesReply features;
72     @Mock
73     protected MessageSpy messageSpy;
74     @Mock
75     protected OutboundQueue outboundQueueProvider;
76     @Mock
77     protected MultiMsgCollector multiMsgCollector;
78     @Mock
79     protected TranslatorLibrary translatorLibrary;
80     @Mock
81     protected DeviceState deviceState;
82     @Mock
83     protected DeviceInfo deviceInfo;
84     @Mock
85     protected GetFeaturesOutput getFeaturesOutput;
86
87     protected NodeConnectorId nodeConnectorId;
88     protected KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
89     protected ConvertorManager convertorManager;
90     protected MultipartWriterProvider multipartWriterProvider;
91
92     protected static NodeRef createNodeRef(String nodeIdValue) {
93         InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class)
94                 .child(Node.class, new NodeKey(new NodeId(nodeIdValue)));
95
96         return new NodeRef(nodePath);
97     }
98
99     @Before
100     public void init() throws Exception {
101         nodeConnectorId = InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(
102                 DATAPATH_ID, PORT_NO, OpenflowVersion.get(OF_VERSION));
103
104         nodeInstanceIdentifier = InstanceIdentifier
105                 .create(Nodes.class)
106                 .child(Node.class, new NodeKey(new NodeId(NODE_ID)));
107
108         convertorManager = ConvertorManagerFactory.createDefaultManager();
109         lenient().when(deviceContext.getDeviceFlowRegistry()).thenReturn(deviceFlowRegistry);
110         lenient().when(deviceContext.getDeviceGroupRegistry()).thenReturn(deviceGroupRegistry);
111         lenient().when(deviceContext.getDeviceMeterRegistry()).thenReturn(deviceMeterRegistry);
112         when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
113         when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
114         lenient().when(deviceContext.getMultiMsgCollector(any())).thenReturn(multiMsgCollector);
115         lenient().when(deviceContext.oook()).thenReturn(translatorLibrary);
116         lenient().when(deviceContext.getDeviceState()).thenReturn(deviceState);
117         when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
118         when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
119         lenient().when(deviceInfo.getNodeId()).thenReturn(new NodeId(NODE_ID));
120         when(deviceInfo.getVersion()).thenReturn(OF_VERSION);
121         when(deviceInfo.getDatapathId()).thenReturn(DATAPATH_ID);
122         lenient().when(getFeaturesOutput.getVersion()).thenReturn(OF_VERSION);
123         lenient().when(getFeaturesOutput.getDatapathId()).thenReturn(DATAPATH_ID);
124         when(connectionContext.getFeatures()).thenReturn(features);
125         lenient().when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
126         lenient().when(features.getVersion()).thenReturn(OF_VERSION);
127         lenient().when(features.getDatapathId()).thenReturn(DATAPATH_ID);
128         multipartWriterProvider = MultipartWriterProviderFactory.createDefaultProvider(deviceContext);
129         setUp();
130     }
131
132     protected abstract void setUp() throws Exception;
133
134     @Test
135     public abstract void testBuildRequestBody() throws Exception;
136
137     @Test
138     public abstract void testBuildReply() throws Exception;
139
140     @Test
141     public abstract void testStoreStatistics() throws Exception;
142 }