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.junit.runner.RunWith;
21 import org.mockito.ArgumentMatchers;
22 import org.mockito.Mockito;
23 import org.mockito.runners.MockitoJUnitRunner;
24 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncInputBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncOutput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
33 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
36 * Test for {@link SalAsyncConfigServiceImpl}.
38 @RunWith(MockitoJUnitRunner.class)
39 public class SalAsyncConfigServiceImplTest extends ServiceMocking {
41 private SalAsyncConfigServiceImpl salAsyncConfigService;
44 public void setup() throws Exception {
45 salAsyncConfigService = new SalAsyncConfigServiceImpl(
46 mockedRequestContextStack, mockedDeviceContext);
50 public void testSetAsync() throws Exception {
51 final SetAsyncInput setAsyncInput = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol
52 .rev130731.SetAsyncInputBuilder().build();
53 final RpcResult<SetAsyncInput> replyRpcResult = RpcResultBuilder.success(setAsyncInput).build();
54 final ListenableFuture<RpcResult<SetAsyncInput>> replyFuture = Futures.immediateFuture(replyRpcResult);
55 Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFuture);
57 final ListenableFuture<RpcResult<SetAsyncOutput>> setAsyncResult =
58 salAsyncConfigService.setAsync(new SetAsyncInputBuilder().build());
60 Assert.assertNotNull(setAsyncResult);
61 Assert.assertTrue(setAsyncResult.isDone());
62 Assert.assertTrue(setAsyncResult.get().isSuccessful());
63 verify(mockedRequestContextStack).createRequestContext();
67 public void testGetAsyncTest() throws Exception {
68 final GetAsyncOutput getAsyncOutput = new GetAsyncOutputBuilder().build();
69 final RpcResult<GetAsyncOutput> replyRpcResult = RpcResultBuilder.success(getAsyncOutput).build();
70 final ListenableFuture<RpcResult<GetAsyncOutput>> replyFuture = Futures.immediateFuture(replyRpcResult);
71 Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFuture);
73 final Future<RpcResult<GetAsyncOutput>> getAsyncResult =
74 salAsyncConfigService.getAsync(new GetAsyncInputBuilder().build());
76 Assert.assertNotNull(getAsyncResult);
77 Assert.assertTrue(getAsyncResult.isDone());
78 Assert.assertTrue(getAsyncResult.get().isSuccessful());
79 verify(mockedRequestContextStack).createRequestContext();
80 verify(mockedOutboundQueue).commitEntry(eq(ServiceMocking.DUMMY_XID_VALUE),
81 ArgumentMatchers.<OfHeader>any(), ArgumentMatchers.<FutureCallback<OfHeader>>any());