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 static org.mockito.Mockito.verify;
13 import com.google.common.util.concurrent.FutureCallback;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import java.util.concurrent.Future;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.mockito.Matchers;
20 import org.mockito.Mockito;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
30 public class SalEchoServiceImplTest extends ServiceMocking {
32 private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes();
33 SalEchoServiceImpl salEchoService;
36 protected void setup() {
37 salEchoService = new SalEchoServiceImpl(mockedRequestContextStack, mockedDeviceContext);
41 public void testSendEcho() throws Exception {
42 final EchoOutput echoOut = new EchoOutputBuilder()
45 final RpcResult<EchoOutput> replyRpcResult = RpcResultBuilder.success(echoOut).build();
46 final ListenableFuture<RpcResult<EchoOutput>> replyFt = Futures.immediateFuture(replyRpcResult);
47 Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFt);
48 SendEchoInput sendEchoInput = new SendEchoInputBuilder()
52 final Future<RpcResult<SendEchoOutput>> echoOutput = salEchoService.sendEcho(sendEchoInput);
54 Assert.assertNotNull(echoOutput);
55 Assert.assertTrue(echoOutput.isDone());
56 Assert.assertTrue(echoOutput.get().isSuccessful());
57 verify(mockedRequestContextStack).createRequestContext();
58 verify(mockedOutboundQueue).commitEntry(Matchers.eq(2121L), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());