*/
package org.opendaylight.transportpce.servicehandler.impl;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import static org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl.LogMessages;
import com.google.common.util.concurrent.Futures;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+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.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.mdsal.binding.api.NotificationPublishService;
import org.opendaylight.transportpce.common.ResponseCodes;
import org.opendaylight.transportpce.pce.service.PathComputationService;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.Uint32;
+@ExtendWith(MockitoExtension.class)
public class ServicehandlerImplTest extends AbstractTest {
@Mock
private PathComputationService pathComputationService;
-
@Mock
private RendererServiceOperations rendererServiceOperations;
-
@Mock
private NotificationPublishService notificationPublishService;
-
@Mock
private PceListenerImpl pceListenerImpl;
-
@Mock
private RendererListenerImpl rendererListenerImpl;
-
@Mock
private NetworkModelListenerImpl networkModelListenerImpl;
private CountDownLatch endSignal;
private static final int NUM_THREADS = 5;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
endSignal = new CountDownLatch(1);
- MockitoAnnotations.openMocks(this);
this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker());
serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
}
@Test
- public void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
- ServicehandlerImpl servicehandlerImpl =
- new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
- notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
- serviceDataStoreOperations);
- ListenableFuture<RpcResult<ServiceCreateOutput>> result =
- servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build());
+ void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+ ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+ rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+ networkModelListenerImpl, serviceDataStoreOperations);
+ ListenableFuture<RpcResult<ServiceCreateOutput>> result = servicehandlerImpl
+ .serviceCreate(new ServiceCreateInputBuilder().build());
result.addListener(() -> endSignal.countDown(), executorService);
-
endSignal.await();
- Assert.assertEquals(
- ResponseCodes.RESPONSE_FAILED,
- result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_FAILED,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException,
+ void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException,
InterruptedException {
final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class);
- Mockito.when(serviceDSOperations.getService(serviceCreateInput.getServiceName()))
+ when(serviceDSOperations.getService(serviceCreateInput.getServiceName()))
.thenReturn(Optional.of(
new ServicesBuilder()
.setServiceName(serviceCreateInput.getServiceName())
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
- result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_FAILED,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void createServiceShouldBeSuccessfulWhenPerformPCESuccessful()
+ void createServiceShouldBeSuccessfulWhenPerformPCESuccessful()
throws ExecutionException, InterruptedException {
- Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
+ when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(
- ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_OK,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+ void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(
- ResponseCodes.RESPONSE_FAILED,
- result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_FAILED,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
+ void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
ServicehandlerImpl servicehandlerImpl =
new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(
- ResponseCodes.RESPONSE_FAILED,
- result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_FAILED,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
- Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
+ void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
+ when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(
- ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_OK,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+ void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
- result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_FAILED,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful()
+ void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful()
throws ExecutionException, InterruptedException {
- Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
+ when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(
- ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_OK,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+ void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
@Test
- public void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
+ void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
//action -> service reconfigure
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
}
@Test
- public void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
+ void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
// serviceReconfigure is calling service delete method in renderer
- Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
+ when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
//create service to reconfigure
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
}
@Test
- public void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+ void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
- ListenableFuture<RpcResult<ServiceRestorationOutput>> result =
- servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build());
+ ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl
+ .serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build());
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
@Test
- public void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
+ void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
//action -> service restore
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
}
@Test
- public void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
+ void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
// serviceRestoration is calling service delete method in renderer
- Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
+ when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
//create service to restore
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
}
@Test
- public void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+ void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
endSignal.await();
- Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
- result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_FAILED,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
+ void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
//action -> service reconfigure
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
- ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(
- serviceRerouteInput);
+ ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl
+ .serviceReroute(serviceRerouteInput);
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
- result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_FAILED,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
- Mockito.when(pathComputationService.pathComputationRerouteRequest(any()))
- .thenReturn(Futures.immediateFuture(new PathComputationRerouteRequestOutputBuilder()
- .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder()
- .setResponseCode(ResponseCodes.RESPONSE_OK)
- .build())
- .build()));
+ void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
+ when(pathComputationService.pathComputationRerouteRequest(any()))
+ .thenReturn(Futures.immediateFuture(new PathComputationRerouteRequestOutputBuilder()
+ .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder()
+ .setResponseCode(ResponseCodes.RESPONSE_OK)
+ .build())
+ .build()));
Map<AToZKey, AToZ> atoz = Map.of(
new AToZKey("0"),
new AToZBuilder()
endSignal.await();
- Assert.assertEquals(
- ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_OK,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+ void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
endSignal.await();
RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
- Assert.assertEquals(
- ResponseCodes.RESPONSE_FAILED,
- rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
- Assert.assertEquals(
- LogMessages.SERVICE_NON_COMPLIANT,
- rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage());
+ assertEquals(
+ ResponseCodes.RESPONSE_FAILED,
+ rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ LogMessages.SERVICE_NON_COMPLIANT,
+ rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage());
}
@Test
- public void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
+ void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
- result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_FAILED,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
- Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
+ void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
+ when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
//create temp service to delete in the temp delete action
- ServicehandlerImpl servicehandlerImpl =
- new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
- notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
- serviceDataStoreOperations);
+ ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+ rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+ networkModelListenerImpl, serviceDataStoreOperations);
TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
serviceDataStoreOperations.createTempService(createInput);
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(
- ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_OK,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
@Test
- public void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+ void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
networkModelListenerImpl, serviceDataStoreOperations);
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
- result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_FAILED,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
-
@Test
- public void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful()
+ void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful()
throws ExecutionException, InterruptedException {
- Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
+ when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
result.addListener(() -> endSignal.countDown(), executorService);
endSignal.await();
- Assert.assertEquals(
- ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+ assertEquals(
+ ResponseCodes.RESPONSE_OK,
+ result.get().getResult().getConfigurationResponseCommon().getResponseCode());
}
-
-}
+}
\ No newline at end of file