Add pce-constraint-mode enum in pce yang model
[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.rev230925.CancelResourceReserveInputBuilder;
35
36 @ExtendWith(MockitoExtension.class)
37 public class PceServiceRPCImplTest extends AbstractTest {
38
39     private PathComputationService pathComputationService;
40     private NotificationPublishService notificationPublishService;
41     private NetworkTransactionImpl networkTransaction;
42     private PceServiceRPCImpl pceServiceRPC;
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         pceServiceRPC = new PceServiceRPCImpl(rpcProviderService, pathComputationService);
58     }
59
60     @Test
61     void testRpcRegistration() {
62         verify(rpcProviderService, times(1)).registerRpcImplementations(any());
63     }
64
65     @Test
66     void testCancelResourceReserve() {
67         CancelResourceReserveInputBuilder cancelResourceReserveInput = new CancelResourceReserveInputBuilder();
68         assertNotNull(pceServiceRPC.cancelResourceReserve(cancelResourceReserveInput.build()));
69     }
70
71     @Test
72     void testPathComputationRequest() {
73         assertNotNull(pceServiceRPC.pathComputationRequest(PceTestData.getPCERequest()));
74     }
75
76     @Test
77     void testPathComputationRerouteRequest() {
78         assertNotNull(pceServiceRPC.pathComputationRerouteRequest(PceTestData.getPCERerouteRequest()));
79     }
80
81     @Test
82     void testPathComputationRequestCoRoutingOrGeneral2() {
83         assertNotNull(
84             pceServiceRPC.pathComputationRequest(PceTestData.getPathComputationRequestInputWithCoRoutingOrGeneral2()));
85     }
86 }