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