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.Captor;
18 import org.mockito.Matchers;
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(Matchers.any()));
62 when.thenReturn(multiMsgCollector);
63 multipartRequestCallback = new MultiLayerMultipartRequestCallback<>(requestContext, MultipartRequestInput.class, deviceContext, null);
72 public void testOnSuccess1() throws Exception {
73 multipartRequestCallback.onSuccess(null);
74 Mockito.verify(multiMsgCollector).endCollecting(Matchers.<EventIdentifier>any());
78 * fail adding to collection
83 public void testOnSuccess2() throws Exception {
84 multipartRequestCallback.onSuccess(new EchoOutputBuilder().build());
85 final RpcResult<List<MultipartReply>> rpcResult = rpcResultCapt.getValue();
86 Assert.assertNotNull(rpcResult);
87 Assert.assertFalse(rpcResult.isSuccessful());
91 * successfully added to collection
96 public void testOnSuccess3() throws Exception {
97 final MultipartReplyMessage replyMessage = new MultipartReplyMessageBuilder().build();
98 multipartRequestCallback.onSuccess(replyMessage);
99 Mockito.verify(multiMsgCollector).addMultipartMsg(Matchers.eq(replyMessage), Matchers.eq(false), Matchers.any());