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
8 package org.opendaylight.openflowplugin.impl.services.sal;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.ArgumentMatchers.eq;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.when;
17 import com.google.common.util.concurrent.Futures;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
22 import org.opendaylight.openflowplugin.impl.services.singlelayer.GetAsyncImpl;
23 import org.opendaylight.openflowplugin.impl.services.singlelayer.SetAsyncImpl;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncInputBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncInputBuilder;
27 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
30 * Test for {@link SalAsyncConfigServiceImpl}.
32 @RunWith(MockitoJUnitRunner.class)
33 public class SalAsyncConfigServiceImplTest extends ServiceMocking {
35 public void testSetAsync() throws Exception {
36 final var setAsync = new SetAsyncImpl(mockedRequestContextStack, mockedDeviceContext);
38 final var setAsyncInput = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol
39 .rev130731.SetAsyncInputBuilder().build();
40 final var replyRpcResult = RpcResultBuilder.success(setAsyncInput).build();
41 final var replyFuture = Futures.immediateFuture(replyRpcResult);
42 when(mockedRequestContext.getFuture()).thenReturn(replyFuture);
44 final var setAsyncResult = setAsync.invoke(new SetAsyncInputBuilder().build());
46 assertNotNull(setAsyncResult);
47 assertTrue(setAsyncResult.isDone());
48 assertTrue(setAsyncResult.get().isSuccessful());
49 verify(mockedRequestContextStack).createRequestContext();
53 public void testGetAsyncTest() throws Exception {
54 final var getAsync = new GetAsyncImpl(mockedRequestContextStack, mockedDeviceContext);
56 final var getAsyncOutput = new GetAsyncOutputBuilder().build();
57 final var replyRpcResult = RpcResultBuilder.success(getAsyncOutput).build();
58 final var replyFuture = Futures.immediateFuture(replyRpcResult);
59 when(mockedRequestContext.getFuture()).thenReturn(replyFuture);
61 final var getAsyncResult = getAsync.invoke(new GetAsyncInputBuilder().build());
63 assertNotNull(getAsyncResult);
64 assertTrue(getAsyncResult.isDone());
65 assertTrue(getAsyncResult.get().isSuccessful());
66 verify(mockedRequestContextStack).createRequestContext();
67 verify(mockedOutboundQueue).commitEntry(eq(ServiceMocking.DUMMY_XID_VALUE), any(), any());