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.EventIdentifier;
27 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
28 import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerMultipartRequestCallback;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
34 import org.opendaylight.yangtools.yang.common.RpcResult;
37 * Test for {@link org.opendaylight.openflowplugin.impl.services.AbstractMultipartRequestCallback}.
39 @RunWith(MockitoJUnitRunner.class)
40 public class MultipartRequestCallbackTest {
43 private DeviceContext deviceContext;
45 private RequestContext<List<MultipartReply>> requestContext;
47 private MessageSpy spy;
49 private MultiMsgCollector<MultipartReply> multiMsgCollector;
51 private ArgumentCaptor<RpcResult<List<MultipartReply>>> rpcResultCapt;
53 private AbstractMultipartRequestCallback<MultipartReply> multipartRequestCallback;
56 public void setUp() throws Exception {
57 Mockito.doNothing().when(requestContext).setResult(rpcResultCapt.capture());
58 Mockito.when(deviceContext.getMessageSpy()).thenReturn(spy);
60 final OngoingStubbing<MultiMsgCollector<MultipartReply>> when =
61 Mockito.when(deviceContext.getMultiMsgCollector(ArgumentMatchers.any()));
62 when.thenReturn(multiMsgCollector);
63 multipartRequestCallback = new MultiLayerMultipartRequestCallback<>(requestContext,
64 MultipartRequestInput.class,
73 public void testOnSuccess1() throws Exception {
74 multipartRequestCallback.onSuccess(null);
75 Mockito.verify(multiMsgCollector).endCollecting(ArgumentMatchers.<EventIdentifier>any());
79 * Fail adding to collection.
82 public void testOnSuccess2() throws Exception {
83 multipartRequestCallback.onSuccess(new EchoOutputBuilder().build());
84 final RpcResult<List<MultipartReply>> rpcResult = rpcResultCapt.getValue();
85 Assert.assertNotNull(rpcResult);
86 Assert.assertFalse(rpcResult.isSuccessful());
90 * Successfully added to collection.
93 public void testOnSuccess3() throws Exception {
94 final MultipartReplyMessage replyMessage = new MultipartReplyMessageBuilder().build();
95 multipartRequestCallback.onSuccess(replyMessage);
96 Mockito.verify(multiMsgCollector)
97 .addMultipartMsg(ArgumentMatchers.eq(replyMessage), ArgumentMatchers.eq(false), ArgumentMatchers.any());