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.services;
11 import java.util.List;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.ArgumentCaptor;
17 import org.mockito.ArgumentMatchers;
18 import org.mockito.Captor;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.runners.MockitoJUnitRunner;
22 import org.mockito.stubbing.OngoingStubbing;
23 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
25 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
26 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
27 import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerMultipartRequestCallback;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
33 import org.opendaylight.yangtools.yang.common.RpcResult;
36 * Test for {@link org.opendaylight.openflowplugin.impl.services.AbstractMultipartRequestCallback}.
38 @RunWith(MockitoJUnitRunner.class)
39 public class MultipartRequestCallbackTest {
42 private DeviceContext deviceContext;
44 private RequestContext<List<MultipartReply>> requestContext;
46 private MessageSpy spy;
48 private MultiMsgCollector<MultipartReply> multiMsgCollector;
50 private ArgumentCaptor<RpcResult<List<MultipartReply>>> rpcResultCapt;
52 private AbstractMultipartRequestCallback<MultipartReply> multipartRequestCallback;
56 Mockito.doNothing().when(requestContext).setResult(rpcResultCapt.capture());
57 Mockito.when(deviceContext.getMessageSpy()).thenReturn(spy);
59 final OngoingStubbing<MultiMsgCollector<MultipartReply>> when =
60 Mockito.when(deviceContext.getMultiMsgCollector(ArgumentMatchers.any()));
61 when.thenReturn(multiMsgCollector);
62 multipartRequestCallback = new MultiLayerMultipartRequestCallback<>(requestContext,
63 MultipartRequestInput.class,
72 public void testOnSuccess1() {
73 multipartRequestCallback.onSuccess(null);
74 Mockito.verify(multiMsgCollector).endCollecting(ArgumentMatchers.any());
78 * Fail adding to collection.
81 public void testOnSuccess2() {
82 multipartRequestCallback.onSuccess(new EchoOutputBuilder().build());
83 final RpcResult<List<MultipartReply>> rpcResult = rpcResultCapt.getValue();
84 Assert.assertNotNull(rpcResult);
85 Assert.assertFalse(rpcResult.isSuccessful());
89 * Successfully added to collection.
92 public void testOnSuccess3() {
93 final MultipartReplyMessage replyMessage = new MultipartReplyMessageBuilder().build();
94 multipartRequestCallback.onSuccess(replyMessage);
95 Mockito.verify(multiMsgCollector)
96 .addMultipartMsg(ArgumentMatchers.eq(replyMessage), ArgumentMatchers.eq(false), ArgumentMatchers.any());