Merge "BUG-5020 Handling exception while submission"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / util / DeviceInitializationUtilsTest.java
1 /*
2  * Copyright (c) 2016 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.util;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.eq;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16 import static org.mockito.Mockito.when;
17
18 import java.math.BigInteger;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Set;
24
25 import com.google.common.collect.Lists;
26 import com.google.common.util.concurrent.CheckedFuture;
27 import com.google.common.util.concurrent.FutureCallback;
28 import com.google.common.util.concurrent.Futures;
29 import com.google.common.util.concurrent.ListenableFuture;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Matchers;
34 import org.mockito.Mock;
35 import org.mockito.Mockito;
36 import org.mockito.invocation.InvocationOnMock;
37 import org.mockito.runners.MockitoJUnitRunner;
38 import org.mockito.stubbing.Answer;
39 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
40 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
41 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
42 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
43 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandler;
44 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
45 import org.opendaylight.openflowplugin.api.OFConstants;
46 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
47 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
48 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
49 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
50 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
51 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
52 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
53 import org.opendaylight.openflowplugin.impl.device.DeviceContextImpl;
54 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeatures;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeatures;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCaseBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesCaseBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCaseBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescCaseBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesCaseBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDesc;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDescBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeatures;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeaturesBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeaturesBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.MultipartReplyPortDescBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.MultipartReplyTableFeatures;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.MultipartReplyTableFeaturesBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.multipart.reply.table.features.TableFeatures;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.multipart.reply.table.features.TableFeaturesBuilder;
96 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
97 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
98 import org.opendaylight.yangtools.yang.common.RpcError;
99 import org.opendaylight.yangtools.yang.common.RpcResult;
100 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
101
102 @RunWith(MockitoJUnitRunner.class)
103 public class DeviceInitializationUtilsTest {
104
105     private static final boolean TEST_VALUE_SWITCH_FEATURE_MANDATORY = true;
106     private static final long TEST_VALUE_GLOBAL_NOTIFICATION_QUOTA = 2000l;
107     private static final KeyedInstanceIdentifier<Node, NodeKey> DUMMY_NODE_II = InstanceIdentifier.create(Nodes.class)
108             .child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
109     private static final Short DUMMY_TABLE_ID = 1;
110     private static final Long DUMMY_MAX_METER = 544L;
111     private static final String DUMMY_DATAPATH_ID = "44";
112     private static final Long DUMMY_PORT_NUMBER = 21L;
113
114     @Mock
115     CheckedFuture<Void, TransactionCommitFailedException> mockedFuture;
116     @Mock
117     private FeaturesReply mockFeatures;
118     @Mock
119     private OutboundQueue outboundQueueProvider;
120     @Mock
121     private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
122     @Mock
123     private TranslatorLibrary translatorLibrary;
124     @Mock
125     private ConnectionContext mockConnectionContext;
126     @Mock
127     private ConnectionAdapter mockedConnectionAdapter;
128     @Mock
129     private DeviceContextImpl mockedDeviceContext;
130     @Mock
131     private DeviceInitializationUtils deviceInitializationUtils;
132
133     @Before
134     public void setUp() throws Exception {
135         OpenflowPortsUtil.init();
136
137         when(mockConnectionContext.getNodeId()).thenReturn(new NodeId("dummyNodeId"));
138         when(mockConnectionContext.getFeatures()).thenReturn(mockFeatures);
139         when(mockConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
140         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockConnectionContext);
141
142         final Capabilities capabilitiesV13 = Mockito.mock(Capabilities.class);
143         final CapabilitiesV10 capabilitiesV10 = Mockito.mock(CapabilitiesV10.class);
144         when(mockFeatures.getCapabilities()).thenReturn(capabilitiesV13);
145         when(mockFeatures.getCapabilitiesV10()).thenReturn(capabilitiesV10);
146         when(mockFeatures.getDatapathId()).thenReturn(BigInteger.valueOf(21L));
147     }
148     @Test
149     public void chainTableTrunkWriteOF10Test() {
150         DeviceState mockedDeviceState = mock(DeviceState.class);
151
152         GetFeaturesOutput mockedFeatures = mock(GetFeaturesOutput.class);
153         when(mockedFeatures.getTables()).thenReturn((short) 2);
154         when(mockedDeviceState.getFeatures()).thenReturn(mockedFeatures);
155
156         when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(DUMMY_NODE_II);
157         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
158
159         RpcResult<List<MultipartReply>> mockedRpcResult = mock(RpcResult.class);
160         when(mockedRpcResult.isSuccessful()).thenReturn(true);
161         List<RpcResult<List<MultipartReply>>> data = new ArrayList<RpcResult<List<MultipartReply>>>();
162         data.add(mockedRpcResult);
163         data.add(mockedRpcResult);
164
165         DeviceInitializationUtils.chainTableTrunkWriteOF10(mockedDeviceContext, Futures.immediateFuture(data));
166         verify(mockedDeviceContext, times(3))
167                 .writeToTransaction(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(FlowCapableNode.class));
168     }
169
170     @Test
171     public void testTranslateAndWriteReplyTypeDesc() {
172         final ConnectionContext connectionContext = buildMockConnectionContext(OFConstants.OFP_VERSION_1_3);
173         Mockito.when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
174         DeviceState deviceState = Mockito.mock(DeviceState.class);
175         Mockito.when(mockedDeviceContext.getDeviceState()).thenReturn(deviceState);
176
177         Collection<MultipartReply> multipartReplyMessages = prepareDataforTypeDesc(mockedDeviceContext);
178
179         DeviceInitializationUtils.translateAndWriteReply(MultipartType.OFPMPDESC, mockedDeviceContext, DUMMY_NODE_II, multipartReplyMessages);
180         verify(mockedDeviceContext)
181                 .writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), eq(DUMMY_NODE_II.augmentation(FlowCapableNode.class)), any(FlowCapableNode.class));
182     }
183
184     @Test
185     public void translateAndWriteReplyTypeTableFeatures() {
186         TableFeaturesBuilder tableFeature = new TableFeaturesBuilder();
187         tableFeature.setTableId(DUMMY_TABLE_ID);
188         List<TableFeatures> tableFeatures = new ArrayList<>();
189         tableFeatures.add(tableFeature.build());
190
191         MultipartReplyTableFeatures multipartReplyTableFeatures = new MultipartReplyTableFeaturesBuilder().setTableFeatures(tableFeatures).build();
192         MultipartReplyTableFeaturesCaseBuilder multipartReplyTableFeaturesCaseBuilder = new MultipartReplyTableFeaturesCaseBuilder();
193         multipartReplyTableFeaturesCaseBuilder.setMultipartReplyTableFeatures(multipartReplyTableFeatures);
194
195         MultipartReplyMessage multipartReplyMessage = new MultipartReplyMessageBuilder().setMultipartReplyBody(multipartReplyTableFeaturesCaseBuilder.build()).build();
196         Set<MultipartReply> multipartReplyMessages = Collections.<MultipartReply>singleton(multipartReplyMessage);
197         DeviceInitializationUtils.translateAndWriteReply(MultipartType.OFPMPTABLEFEATURES, mockedDeviceContext, DUMMY_NODE_II, multipartReplyMessages);
198         verify(mockedDeviceContext)
199                 .writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL),
200                         eq(DUMMY_NODE_II.augmentation(FlowCapableNode.class).child(Table.class, new TableKey(DUMMY_TABLE_ID))), any(Table.class));
201
202     }
203
204     @Test
205     public void translateAndWriteReplyTypeMeterFeatures() {
206         DeviceState mockedDeviceState = mock(DeviceState.class);
207         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
208
209         MultipartReplyMeterFeaturesBuilder multipartReplyMeterFeaturesBuilder = new MultipartReplyMeterFeaturesBuilder();
210         multipartReplyMeterFeaturesBuilder.setBandTypes(new MeterBandTypeBitmap(true, true));
211         multipartReplyMeterFeaturesBuilder.setCapabilities(new MeterFlags(true, true, true, true));
212         multipartReplyMeterFeaturesBuilder.setMaxMeter(DUMMY_MAX_METER);
213
214         MultipartReplyMeterFeaturesCaseBuilder multipartReplyMeterFeaturesCaseBuilder = new MultipartReplyMeterFeaturesCaseBuilder();
215         multipartReplyMeterFeaturesCaseBuilder.setMultipartReplyMeterFeatures(multipartReplyMeterFeaturesBuilder.build());
216
217         MultipartReplyMessage multipartReplyMessage = new MultipartReplyMessageBuilder().setMultipartReplyBody(multipartReplyMeterFeaturesCaseBuilder.build()).build();
218         Set<MultipartReply> multipartReplyMessages = Collections.<MultipartReply>singleton(multipartReplyMessage);
219         DeviceInitializationUtils.translateAndWriteReply(MultipartType.OFPMPMETERFEATURES, mockedDeviceContext, DUMMY_NODE_II, multipartReplyMessages);
220         verify(mockedDeviceContext)
221                 .writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), eq(DUMMY_NODE_II.augmentation(NodeMeterFeatures.class)), any(NodeMeterFeatures.class));
222         verify(mockedDeviceState).setMeterAvailable(eq(true));
223     }
224
225     @Test
226     public void translateAndWriteReplyTypeGroupFeatures() {
227         MultipartReplyGroupFeaturesBuilder multipartReplyGroupFeaturesBuilder = new MultipartReplyGroupFeaturesBuilder();
228         multipartReplyGroupFeaturesBuilder.setTypes(new GroupTypes(true, true, true, true));
229         multipartReplyGroupFeaturesBuilder.setCapabilities(new GroupCapabilities(true, true, true, true));
230         ActionType actionType = new ActionType(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
231         multipartReplyGroupFeaturesBuilder.setActionsBitmap(Lists.newArrayList(actionType));
232
233         MultipartReplyGroupFeatures multipartReplyGroupFeatures = multipartReplyGroupFeaturesBuilder.build();
234
235         MultipartReplyGroupFeaturesCaseBuilder multipartReplyGroupFeaturesCaseBuilder = new MultipartReplyGroupFeaturesCaseBuilder();
236         multipartReplyGroupFeaturesCaseBuilder.setMultipartReplyGroupFeatures(multipartReplyGroupFeatures);
237
238         MultipartReplyMessage multipartReplyMessage = new MultipartReplyMessageBuilder().setMultipartReplyBody(multipartReplyGroupFeaturesCaseBuilder.build()).build();
239         Set<MultipartReply> multipartReplyMessages = Collections.<MultipartReply>singleton(multipartReplyMessage);
240
241         DeviceInitializationUtils.translateAndWriteReply(MultipartType.OFPMPGROUPFEATURES, mockedDeviceContext, DUMMY_NODE_II, multipartReplyMessages);
242         verify(mockedDeviceContext)
243                 .writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), eq(DUMMY_NODE_II.augmentation(NodeGroupFeatures.class)), any(NodeGroupFeatures.class));
244     }
245
246
247     @Test
248     public void translateAndWriteReplyTypePortDesc() {
249         ConnectionContext mockedPrimaryConnectionContext = mock(ConnectionContext.class);
250         FeaturesReply mockedFeatures = mock(FeaturesReply.class);
251         when(mockedFeatures.getDatapathId()).thenReturn(new BigInteger(DUMMY_DATAPATH_ID));
252         when(mockedPrimaryConnectionContext.getFeatures()).thenReturn(mockedFeatures);
253         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimaryConnectionContext);
254         DeviceState mockedDeviceState = mock(DeviceState.class);
255         when(mockedDeviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0);
256         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
257         MessageTranslator mockedTranslator = mock(MessageTranslator.class);
258         when(translatorLibrary.lookupTranslator(any(TranslatorKey.class))).thenReturn(mockedTranslator);
259         when(mockedDeviceContext.oook()).thenReturn(translatorLibrary);
260
261         MultipartReplyPortDescBuilder multipartReplyPortDescBuilder = new MultipartReplyPortDescBuilder();
262
263         PortsBuilder portsBuilder = new PortsBuilder();
264         portsBuilder.setPortNo(DUMMY_PORT_NUMBER);
265
266         multipartReplyPortDescBuilder.setPorts(Lists.newArrayList(portsBuilder.build()));
267
268         MultipartReplyPortDescCaseBuilder multipartReplyPortDescCaseBuilder = new MultipartReplyPortDescCaseBuilder();
269         multipartReplyPortDescCaseBuilder.setMultipartReplyPortDesc(multipartReplyPortDescBuilder.build());
270
271         MultipartReplyMessage multipartReplyMessage = new MultipartReplyMessageBuilder().setMultipartReplyBody(multipartReplyPortDescCaseBuilder.build()).build();
272         Set<MultipartReply> multipartReplyMessages = Collections.<MultipartReply>singleton(multipartReplyMessage);
273
274         OpenflowPortsUtil.init();
275         DeviceInitializationUtils.translateAndWriteReply(MultipartType.OFPMPPORTDESC, mockedDeviceContext, DUMMY_NODE_II, multipartReplyMessages);
276         verify(mockedDeviceContext)
277                 .writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(NodeConnector.class));
278     }
279
280     @Test
281     public void createSuccessProcessingCallbackTest() {
282         DeviceState mockedDeviceState = mock(DeviceState.class);
283         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
284
285         final ConnectionContext connectionContext = buildMockConnectionContext(OFConstants.OFP_VERSION_1_3);
286
287         List<MultipartReply> multipartReplies = new ArrayList<>(prepareDataforTypeDesc(mockedDeviceContext));
288         RpcResult<List<MultipartReply>> result = RpcResultBuilder.<List<MultipartReply>>success(multipartReplies).build();
289         ListenableFuture<RpcResult<List<MultipartReply>>> mockedRequestContextFuture = Futures.immediateFuture(result);
290
291         DeviceInitializationUtils.createSuccessProcessingCallback(MultipartType.OFPMPDESC, mockedDeviceContext, DUMMY_NODE_II, mockedRequestContextFuture);
292         verify(mockedDeviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), eq(DUMMY_NODE_II.augmentation(FlowCapableNode.class)), any(FlowCapableNode.class));
293
294         RpcResult<List<MultipartReply>> rpcResult = RpcResultBuilder.<List<MultipartReply>>failed().withError(RpcError.ErrorType.PROTOCOL, "dummy error").build();
295         mockedRequestContextFuture = Futures.immediateFuture(rpcResult);
296         DeviceInitializationUtils.createSuccessProcessingCallback(MultipartType.OFPMPDESC, mockedDeviceContext, DUMMY_NODE_II, mockedRequestContextFuture);
297         verify(mockedDeviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), eq(DUMMY_NODE_II.augmentation(FlowCapableNode.class)), any(FlowCapableNode.class));
298     }
299
300     private Collection<MultipartReply> prepareDataforTypeDesc(final DeviceContext mockedDeviceContext) {
301         MultipartReplyDesc multipartReplyDesc = new MultipartReplyDescBuilder().build();
302
303         MultipartReplyDescCaseBuilder multipartReplyDescCaseBuilder = new MultipartReplyDescCaseBuilder();
304         multipartReplyDescCaseBuilder.setMultipartReplyDesc(multipartReplyDesc);
305
306         MultipartReplyMessage multipartReplyMessage = new MultipartReplyMessageBuilder().setMultipartReplyBody(multipartReplyDescCaseBuilder.build()).build();
307         return Collections.<MultipartReply>singleton(multipartReplyMessage);
308
309     }
310
311     protected ConnectionContext buildMockConnectionContext(short ofpVersion) {
312         when(mockFeatures.getVersion()).thenReturn(ofpVersion);
313         when(outboundQueueProvider.reserveEntry()).thenReturn(43L);
314         Mockito.doAnswer(new Answer<Void>() {
315             @Override
316             public Void answer(InvocationOnMock invocation) throws Throwable {
317                 final FutureCallback<OfHeader> callBack = (FutureCallback<OfHeader>) invocation.getArguments()[2];
318                 callBack.onSuccess(null);
319                 return null;
320             }
321         })
322                 .when(outboundQueueProvider)
323                 .commitEntry(Matchers.anyLong(), Matchers.<MultipartRequestInput>any(), Matchers.<FutureCallback<OfHeader>>any());
324
325         when(mockedConnectionAdapter.registerOutboundQueueHandler(Matchers.<OutboundQueueHandler>any(), Matchers.anyInt(), Matchers.anyLong()))
326                 .thenAnswer(new Answer<OutboundQueueHandlerRegistration<OutboundQueueHandler>>() {
327                     @Override
328                     public OutboundQueueHandlerRegistration<OutboundQueueHandler> answer(InvocationOnMock invocation) throws Throwable {
329                         OutboundQueueHandler handler = (OutboundQueueHandler) invocation.getArguments()[0];
330                         handler.onConnectionQueueChanged(outboundQueueProvider);
331                         return null;
332                     }
333                 });
334
335         when(mockConnectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
336         return mockConnectionContext;
337     }
338
339
340
341 }