OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / sal / SalEchoServiceImplTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.services.sal;
10
11 import static org.mockito.ArgumentMatchers.eq;
12 import static org.mockito.Mockito.verify;
13
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;
31
32 public class SalEchoServiceImplTest extends ServiceMocking {
33
34     private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes();
35     SalEchoServiceImpl salEchoService;
36
37     @Override
38     protected void setup() {
39         salEchoService = new SalEchoServiceImpl(mockedRequestContextStack, mockedDeviceContext);
40     }
41
42     @Test
43     public void testSendEcho() throws Exception {
44         final EchoOutput echoOut = new EchoOutputBuilder()
45                 .setData(DUMMY_DATA)
46                 .build();
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()
51                 .setData(DUMMY_DATA)
52                 .build();
53
54         final Future<RpcResult<SendEchoOutput>> echoOutput = salEchoService.sendEcho(sendEchoInput);
55
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());
63     }
64 }