1ecb23fa6e6613b67cac5fdf5ea474fae263107d
[transportpce.git] / pce / src / test / java / org / opendaylight / transportpce / pce / impl / PceProviderTest.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 import static org.mockito.ArgumentMatchers.eq;
12
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
18 import org.opendaylight.mdsal.binding.api.RpcProviderService;
19 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
20 import org.opendaylight.transportpce.common.network.RequestProcessor;
21 import org.opendaylight.transportpce.pce.service.PathComputationService;
22 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
23 import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
24 import org.opendaylight.transportpce.test.AbstractTest;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.TransportpcePceService;
26 import org.opendaylight.yangtools.concepts.ObjectRegistration;
27
28 public class PceProviderTest extends AbstractTest {
29
30     private RpcProviderService rpcService;
31     private PathComputationService pathComputationService;
32     private NotificationPublishService notificationPublishService;
33     private NetworkTransactionImpl networkTransaction;
34     private RequestProcessor requestProcessor;
35     private ObjectRegistration<TransportpcePceService> rpcRegistration;
36     private PceProvider pceProvider;
37
38     @Before
39     public void setUp() {
40         rpcService = Mockito.mock(RpcProviderService.class);
41         notificationPublishService = new NotificationPublishServiceMock();
42         requestProcessor = Mockito.mock(RequestProcessor.class);
43         networkTransaction = new NetworkTransactionImpl(requestProcessor);
44         pathComputationService = new PathComputationServiceImpl(networkTransaction, notificationPublishService,
45                 null, null);
46         pceProvider = new PceProvider(rpcService, pathComputationService);
47     }
48
49     @Test
50     public void testInit() {
51         this.rpcRegistration = new ObjectRegistration<TransportpcePceService>() {
52             @NonNull
53             @Override
54             public TransportpcePceService getInstance() {
55                 return new PceServiceRPCImpl(pathComputationService);
56             }
57
58             @Override
59             public void close() {
60
61             }
62         };
63         Mockito
64                 .when(rpcService
65                         .registerRpcImplementation(eq(TransportpcePceService.class), Mockito.any()))
66                 .thenReturn(rpcRegistration);
67         pceProvider.init();
68         pceProvider.close();
69     }
70
71 }