Spec: OFPGC_ADD_OR_MOD support in openflowplugin
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / sal / SalAsyncConfigServiceImplTest.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.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.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Matchers;
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.openflow.protocol.rev130731.OfHeader;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
33
34 /**
35  * Test for {@link SalAsyncConfigServiceImpl}.
36  */
37 @RunWith(MockitoJUnitRunner.class)
38 public class SalAsyncConfigServiceImplTest extends ServiceMocking {
39
40     private SalAsyncConfigServiceImpl salAsyncConfigService;
41
42     @Before
43     public void setUp() throws Exception {
44         salAsyncConfigService = new SalAsyncConfigServiceImpl(
45                 mockedRequestContextStack, mockedDeviceContext);
46     }
47
48     @Test
49     public void testSetAsync() throws Exception {
50         final SetAsyncInput setAsyncInput = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol
51                 .rev130731.SetAsyncInputBuilder().build();
52         final RpcResult<SetAsyncInput> replyRpcResult = RpcResultBuilder.success(setAsyncInput).build();
53         final ListenableFuture<RpcResult<SetAsyncInput>> replyFuture = Futures.immediateFuture(replyRpcResult);
54         Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFuture);
55
56         final Future<RpcResult<Void>> setAsyncResult =
57                 salAsyncConfigService.setAsync(new SetAsyncInputBuilder().build());
58
59         Assert.assertNotNull(setAsyncResult);
60         Assert.assertTrue(setAsyncResult.isDone());
61         Assert.assertTrue(setAsyncResult.get().isSuccessful());
62         verify(mockedRequestContextStack).createRequestContext();
63     }
64
65     @Test
66     public void testGetAsyncTest() throws Exception {
67         final GetAsyncOutput getAsyncOutput = new GetAsyncOutputBuilder().build();
68         final RpcResult<GetAsyncOutput> replyRpcResult = RpcResultBuilder.success(getAsyncOutput).build();
69         final ListenableFuture<RpcResult<GetAsyncOutput>> replyFuture = Futures.immediateFuture(replyRpcResult);
70         Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFuture);
71
72         final Future<RpcResult<GetAsyncOutput>> getAsyncResult =
73                 salAsyncConfigService.getAsync(new GetAsyncInputBuilder().build());
74
75         Assert.assertNotNull(getAsyncResult);
76         Assert.assertTrue(getAsyncResult.isDone());
77         Assert.assertTrue(getAsyncResult.get().isSuccessful());
78         verify(mockedRequestContextStack).createRequestContext();
79         verify(mockedOutboundQueue).commitEntry(Matchers.eq(ServiceMocking.DUMMY_XID_VALUE),
80                 Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
81     }
82 }