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.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
23 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
25 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
26 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
35 * Test for {@link MultipartRequestCallback}.
37 @RunWith(MockitoJUnitRunner.class)
38 public class MultipartRequestCallbackTest {
41 private DeviceContext deviceContext;
43 private RequestContext<List<MultipartReply>> requestContext;
45 private MessageSpy spy;
47 private MultiMsgCollector multiMsgCollector;
49 private ArgumentCaptor<RpcResult<List<MultipartReply>>> rpcResultCapt;
51 private MultipartRequestCallback multipartRequestCallback;
54 public void setUp() throws Exception {
55 Mockito.doNothing().when(requestContext).setResult(rpcResultCapt.capture());
56 Mockito.when(deviceContext.getMessageSpy()).thenReturn(spy);
57 Mockito.when(deviceContext.getMultiMsgCollector(Matchers.<RequestContext>any())).thenReturn(multiMsgCollector);
58 multipartRequestCallback = new MultipartRequestCallback(requestContext, MultipartRequestInput.class, deviceContext);
67 public void testOnSuccess1() throws Exception {
68 multipartRequestCallback.onSuccess(null);
69 Mockito.verify(multiMsgCollector).endCollecting(Matchers.<EventIdentifier>any());
73 * fail adding to collection
78 public void testOnSuccess2() throws Exception {
79 multipartRequestCallback.onSuccess(new EchoOutputBuilder().build());
80 final RpcResult<List<MultipartReply>> rpcResult = rpcResultCapt.getValue();
81 Assert.assertNotNull(rpcResult);
82 Assert.assertFalse(rpcResult.isSuccessful());
86 * successfully added to collection
91 public void testOnSuccess3() throws Exception {
92 final MultipartReplyMessage replyMessage = new MultipartReplyMessageBuilder().build();
93 multipartRequestCallback.onSuccess(replyMessage);
94 Mockito.verify(multiMsgCollector).addMultipartMsg(Matchers.eq(replyMessage), Matchers.<EventIdentifier>any());