package org.opendaylight.transportpce.pce.impl;
-import static org.junit.Assert.assertNotNull;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.concurrent.ExecutionException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.transportpce.common.mapping.PortMapping;
import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
-import org.opendaylight.transportpce.common.network.RequestProcessor;
import org.opendaylight.transportpce.pce.service.PathComputationService;
import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
+import org.opendaylight.transportpce.pce.utils.PceTestData;
+import org.opendaylight.transportpce.pce.utils.PceTestUtils;
+import org.opendaylight.transportpce.pce.utils.TransactionUtils;
import org.opendaylight.transportpce.test.AbstractTest;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveInputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInputBuilder;
-
-
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.CancelResourceReserveInputBuilder;
+@ExtendWith(MockitoExtension.class)
public class PceServiceRPCImplTest extends AbstractTest {
private PathComputationService pathComputationService;
private NotificationPublishService notificationPublishService;
private NetworkTransactionImpl networkTransaction;
- private RequestProcessor requestProcessor;
- private PceServiceRPCImpl pceServiceRPC;
+ @Mock
+ private PortMapping portMapping;
+ @Mock
+ private RpcProviderService rpcProviderService;
- @Before
- public void setUp() {
+
+ @BeforeEach
+ void setUp() throws ExecutionException, InterruptedException {
+ PceTestUtils.writeNetworkIntoDataStore(getDataBroker(), getDataStoreContextUtil(),
+ TransactionUtils.getNetworkForSpanLoss());
notificationPublishService = new NotificationPublishServiceMock();
- requestProcessor = Mockito.mock(RequestProcessor.class);
- networkTransaction = new NetworkTransactionImpl(requestProcessor);
- pathComputationService = new PathComputationServiceImpl(networkTransaction, notificationPublishService);
- pceServiceRPC = new PceServiceRPCImpl(pathComputationService);
+ networkTransaction = new NetworkTransactionImpl(getDataBroker());
+ pathComputationService = new PathComputationServiceImpl(networkTransaction, notificationPublishService,
+ null, portMapping);
+ }
+
+ @Test
+ void testRpcRegistration() {
+ new PceServiceRPCImpl(rpcProviderService, pathComputationService);
+ verify(rpcProviderService, times(1)).registerRpcImplementations(
+ any(CancelResourceReserveImpl.class), any(PathComputationRequestImpl.class),
+ any(PathComputationRerouteRequestImpl.class));
+ }
+
+ @Test
+ void testCancelResourceReserve() {
+ assertNotNull(new CancelResourceReserveImpl(pathComputationService)
+ .invoke(new CancelResourceReserveInputBuilder().build()));
}
@Test
- public void testCancelResourceReserve() {
- CancelResourceReserveInputBuilder cancelResourceReserveInput = new CancelResourceReserveInputBuilder();
- assertNotNull(pceServiceRPC.cancelResourceReserve(cancelResourceReserveInput.build()));
+ void testPathComputationRequest() {
+ assertNotNull(new PathComputationRequestImpl(pathComputationService)
+ .invoke(PceTestData.getPCERequest()));
}
@Test
- public void testPathComputationRequest() {
- PathComputationRequestInput pathComputationRequestInput =
- new PathComputationRequestInputBuilder().build();
- assertNotNull(pceServiceRPC.pathComputationRequest(pathComputationRequestInput));
+ void testPathComputationRerouteRequest() {
+ assertNotNull(new PathComputationRerouteRequestImpl(pathComputationService)
+ .invoke(PceTestData.getPCERerouteRequest()));
}
+ @Test
+ void testPathComputationRequestCoRoutingOrGeneral2() {
+ assertNotNull(new PathComputationRequestImpl(pathComputationService)
+ .invoke(PceTestData.getPathComputationRequestInputWithCoRoutingOrGeneral2()));
+ }
}