Merge "SONAR TD - Remove unused fields, fix naming"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / SalEchoServiceImplTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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;
10
11 import static org.mockito.Mockito.verify;
12
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;
29
30 public class SalEchoServiceImplTest extends ServiceMocking {
31
32     private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes();
33     SalEchoServiceImpl salEchoService;
34
35     @Override
36     protected void setup() {
37         salEchoService = new SalEchoServiceImpl(mockedRequestContextStack, mockedDeviceContext);
38     }
39
40     @Test
41     public void testSendEcho() throws Exception {
42         final EchoOutput echoOut = new EchoOutputBuilder()
43                 .setData(DUMMY_DATA)
44                 .build();
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()
49                 .setData(DUMMY_DATA)
50                 .build();
51
52         final Future<RpcResult<SendEchoOutput>> echoOutput = salEchoService.sendEcho(sendEchoInput);
53
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());
59     }
60 }