2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.sal;
11 import static org.mockito.ArgumentMatchers.eq;
12 import static org.mockito.Mockito.verify;
14 import com.google.common.util.concurrent.FutureCallback;
15 import com.google.common.util.concurrent.Futures;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import java.util.concurrent.Future;
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.mockito.ArgumentMatchers;
21 import org.mockito.Mockito;
22 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInputBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
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.OfHeader;
29 import org.opendaylight.yangtools.yang.common.RpcResult;
30 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
32 public class SalEchoServiceImplTest extends ServiceMocking {
34 private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes();
35 SalEchoServiceImpl salEchoService;
38 protected void setup() {
39 salEchoService = new SalEchoServiceImpl(mockedRequestContextStack, mockedDeviceContext);
43 public void testSendEcho() throws Exception {
44 final EchoOutput echoOut = new EchoOutputBuilder()
47 final RpcResult<EchoOutput> replyRpcResult = RpcResultBuilder.success(echoOut).build();
48 final ListenableFuture<RpcResult<EchoOutput>> replyFt = Futures.immediateFuture(replyRpcResult);
49 Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFt);
50 SendEchoInput sendEchoInput = new SendEchoInputBuilder()
54 final Future<RpcResult<SendEchoOutput>> echoOutput = salEchoService.sendEcho(sendEchoInput);
56 Assert.assertNotNull(echoOutput);
57 Assert.assertTrue(echoOutput.isDone());
58 Assert.assertTrue(echoOutput.get().isSuccessful());
59 verify(mockedRequestContextStack).createRequestContext();
60 verify(mockedOutboundQueue)
61 .commitEntry(eq(2121L), ArgumentMatchers.<OfHeader>any(),
62 ArgumentMatchers.<FutureCallback<OfHeader>>any());