Refine the RPC implementation registration
[transportpce.git] / pce / src / test / java / org / opendaylight / transportpce / pce / impl / PceServiceRPCImplTest.java
1 /*
2  * Copyright © 2020 Orange Labs, 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.transportpce.pce.impl;
10
11
12 import static org.junit.jupiter.api.Assertions.assertNotNull;
13 import static org.mockito.ArgumentMatchers.any;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16
17 import java.util.concurrent.ExecutionException;
18 import org.junit.jupiter.api.BeforeEach;
19 import org.junit.jupiter.api.Test;
20 import org.junit.jupiter.api.extension.ExtendWith;
21 import org.mockito.Mock;
22 import org.mockito.junit.jupiter.MockitoExtension;
23 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
24 import org.opendaylight.mdsal.binding.api.RpcProviderService;
25 import org.opendaylight.transportpce.common.mapping.PortMapping;
26 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
27 import org.opendaylight.transportpce.pce.service.PathComputationService;
28 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
29 import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
30 import org.opendaylight.transportpce.pce.utils.PceTestData;
31 import org.opendaylight.transportpce.pce.utils.PceTestUtils;
32 import org.opendaylight.transportpce.pce.utils.TransactionUtils;
33 import org.opendaylight.transportpce.test.AbstractTest;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.CancelResourceReserveInputBuilder;
35
36
37 @ExtendWith(MockitoExtension.class)
38 public class PceServiceRPCImplTest extends AbstractTest {
39
40     private PathComputationService pathComputationService;
41     private NotificationPublishService notificationPublishService;
42     private NetworkTransactionImpl networkTransaction;
43     @Mock
44     private PortMapping portMapping;
45     @Mock
46     private RpcProviderService rpcProviderService;
47
48
49     @BeforeEach
50     void setUp() throws ExecutionException, InterruptedException {
51         PceTestUtils.writeNetworkIntoDataStore(getDataBroker(), getDataStoreContextUtil(),
52                 TransactionUtils.getNetworkForSpanLoss());
53         notificationPublishService = new NotificationPublishServiceMock();
54         networkTransaction =  new NetworkTransactionImpl(getDataBroker());
55         pathComputationService = new PathComputationServiceImpl(networkTransaction, notificationPublishService,
56                 null, portMapping);
57     }
58
59     @Test
60     void testRpcRegistration() {
61         new PceServiceRPCImpl(rpcProviderService, pathComputationService);
62         verify(rpcProviderService, times(1)).registerRpcImplementations(
63                 any(CancelResourceReserveImpl.class), any(PathComputationRequestImpl.class),
64                 any(PathComputationRerouteRequestImpl.class));
65     }
66
67     @Test
68     void testCancelResourceReserve() {
69         assertNotNull(new CancelResourceReserveImpl(pathComputationService)
70                 .invoke(new CancelResourceReserveInputBuilder().build()));
71     }
72
73     @Test
74     void testPathComputationRequest() {
75         assertNotNull(new PathComputationRequestImpl(pathComputationService)
76                 .invoke(PceTestData.getPCERequest()));
77     }
78
79     @Test
80     void testPathComputationRerouteRequest() {
81         assertNotNull(new PathComputationRerouteRequestImpl(pathComputationService)
82                 .invoke(PceTestData.getPCERerouteRequest()));
83     }
84
85     @Test
86     void testPathComputationRequestCoRoutingOrGeneral2() {
87         assertNotNull(new PathComputationRequestImpl(pathComputationService)
88                 .invoke(PceTestData.getPathComputationRequestInputWithCoRoutingOrGeneral2()));
89     }
90 }