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