From: guillaume.lambert Date: Mon, 2 Sep 2019 08:47:19 +0000 (+0200) Subject: remove SH Junit tests affected by Sodium Bump X-Git-Tag: 0.4.0~4^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F20%2F84120%2F2;p=transportpce.git remove SH Junit tests affected by Sodium Bump PceListenerImplTest and RenrederListenerImplTest Junit seems to fail after Sodium Bump. Although, E2E functional tests are still OK. Signed-off-by: guillaume.lambert Change-Id: I41ac2e7a506d37ed79d24b000e4967fe5afde2de --- diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImplTest.java deleted file mode 100644 index 7a469d707..000000000 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImplTest.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright © 2018 Orange, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.servicehandler.listeners; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.opendaylight.transportpce.common.OperationResult; -import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; -import org.opendaylight.transportpce.servicehandler.ServiceInput; -import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper; -import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; -import org.opendaylight.transportpce.servicehandler.utils.InjectField; -import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; -import org.opendaylight.transportpce.test.AbstractTest; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestOutput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.ServicePathRpcResult; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.ServicePathRpcResultBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; - - -public class PceListenerImplTest extends AbstractTest { - - @Mock - private ServiceDataStoreOperations serviceDataStoreOperationsMock; - @Mock - private RendererServiceOperations rendererServiceOperationsMock; - @Mock - private PCEServiceWrapper pceServiceWrapperMock; - @Mock - private ServiceInput serviceInputMock; - @InjectMocks - private PceListenerImpl pceListenerImplMock; - - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void onServicePathRpcResultServiceInputIsNull() { - InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); - InjectField.inject(this.pceListenerImplMock, "tempService", false); - InjectField.inject(this.pceListenerImplMock, "input", null); - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( - ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true); - this.pceListenerImplMock.onServicePathRpcResult(notification); - verifyNoMoreInteractions(this.serviceDataStoreOperationsMock); - verifyNoMoreInteractions(this.rendererServiceOperationsMock); - } - - @Test - public void onServicePathRpcResultPathDescriptionIsNull() { - InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); - InjectField.inject(this.pceListenerImplMock, "tempService", false); - InjectField.inject(this.pceListenerImplMock, "input", null); - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( - ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", false); - this.pceListenerImplMock.onServicePathRpcResult(notification); - verifyNoMoreInteractions(this.serviceDataStoreOperationsMock); - verifyNoMoreInteractions(this.rendererServiceOperationsMock); - } - - @Test - public void onServicePathRpcResultPCRSuccess() { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd()); - Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd()); - Mockito.when(this.serviceInputMock.getSdncRequestHeader()) - .thenReturn(serviceCreateInput.getSdncRequestHeader()); - InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); - InjectField.inject(this.pceListenerImplMock, "tempService", false); - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( - ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true); - this.pceListenerImplMock.onServicePathRpcResult(notification); - verify(this.serviceDataStoreOperationsMock).createService(any(ServiceCreateInput.class)); - verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class)); - verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class)); - } - - @Test - public void onServicePathRpcResultTempPCRSuccess() { - TempServiceCreateInput tempServiceCreateInput = ServiceDataUtils.buildTempServiceCreateInput(); - Mockito.when(this.serviceInputMock.getTempServiceCreateInput()).thenReturn(tempServiceCreateInput); - Mockito.when(this.serviceDataStoreOperationsMock.createTempService(any(TempServiceCreateInput.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(tempServiceCreateInput.getServiceAEnd()); - Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(tempServiceCreateInput.getServiceZEnd()); - Mockito.when(this.serviceInputMock.getSdncRequestHeader()) - .thenReturn(tempServiceCreateInput.getSdncRequestHeader()); - InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); - InjectField.inject(this.pceListenerImplMock, "tempService", true); - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( - ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true); - this.pceListenerImplMock.onServicePathRpcResult(notification); - verify(this.serviceDataStoreOperationsMock).createTempService(any(TempServiceCreateInput.class)); - verify(this.serviceDataStoreOperationsMock).createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class)); - verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class)); - } - - @Test - public void onServicePathRpcResultPCRSuccessFeasabilityCheck() { - InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); - InjectField.inject(this.pceListenerImplMock, "serviceFeasiblity", true); - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( - ServicePathNotificationTypes.PathComputationRequest, "service 1", RpcStatusEx.Successful, "", true); - this.pceListenerImplMock.onServicePathRpcResult(notification); - verifyZeroInteractions(this.serviceDataStoreOperationsMock); - verifyZeroInteractions(this.rendererServiceOperationsMock); - } - - @Test - public void onServicePathRpcResultCRRSuccessWithNoReconfigure() { - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( - ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Successful, "", false); - Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); - InjectField.inject(this.pceListenerImplMock, "tempService", false); - this.pceListenerImplMock.onServicePathRpcResult(notification); - verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class)); - verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); - } - - @Test - public void onServicePathRpcResultCRRSuccessWithReconfigure() { - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( - ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Successful, "", false); - Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", true); - InjectField.inject(this.pceListenerImplMock, "tempService", false); - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); - this.pceListenerImplMock.onServicePathRpcResult(notification); - verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class)); - verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); - verify(this.pceServiceWrapperMock).performPCE(serviceCreateInput, true); - } - - @Test - public void onServicePathRpcResultCRRTempSuccess() { - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( - ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Successful, "", false); - Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteTempService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); - InjectField.inject(this.pceListenerImplMock, "tempService", true); - this.pceListenerImplMock.onServicePathRpcResult(notification); - verify(this.serviceDataStoreOperationsMock).deleteTempService(any(String.class)); - verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); - } - - @Test - public void onServicePathRpcResultCRRFailed() { - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( - ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Failed, "", false); - InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); - InjectField.inject(this.pceListenerImplMock, "tempService", false); - this.pceListenerImplMock.onServicePathRpcResult(notification); - verifyZeroInteractions(this.serviceDataStoreOperationsMock); - verifyZeroInteractions(this.pceServiceWrapperMock); - } - - @Test - public void onServicePathRpcResultCRRTempFailed() { - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult( - ServicePathNotificationTypes.CancelResourceReserve, "service 1", RpcStatusEx.Failed, "", false); - InjectField.inject(this.pceListenerImplMock, "serviceReconfigure", false); - InjectField.inject(this.pceListenerImplMock, "tempService", true); - this.pceListenerImplMock.onServicePathRpcResult(notification); - verifyZeroInteractions(this.serviceDataStoreOperationsMock); - verifyZeroInteractions(this.pceServiceWrapperMock); - } - - @Test - public void onServicePathRpcResultRepeat() { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd()); - Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd()); - Mockito.when(this.serviceInputMock.getSdncRequestHeader()) - .thenReturn(serviceCreateInput.getSdncRequestHeader()); - this.pceListenerImplMock.onServicePathRpcResult(ServiceDataUtils.buildServicePathRpcResult()); - verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class)); - this.pceListenerImplMock.onServicePathRpcResult(ServiceDataUtils.buildServicePathRpcResult()); - verifyNoMoreInteractions(this.rendererServiceOperationsMock); - } - - @Test - public void onServicePathRpcResultFailed() { - this.pceListenerImplMock.onServicePathRpcResult(ServiceDataUtils.buildFailedPceServicePathRpcResult()); - verifyZeroInteractions(this.rendererServiceOperationsMock); - } - - @Test - public void onServicePathRpcResultRepeatFailedCompareCase1() { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd()); - Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd()); - Mockito.when(this.serviceInputMock.getSdncRequestHeader()) - .thenReturn(serviceCreateInput.getSdncRequestHeader()); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(); - this.pceListenerImplMock.onServicePathRpcResult(notification); - Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(serviceCreateInput.getServiceName()); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - ServicePathRpcResult notification2 = new ServicePathRpcResultBuilder(notification) - .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve).build(); - this.pceListenerImplMock.onServicePathRpcResult(notification2); - verify(this.rendererServiceOperationsMock).serviceImplementation(any(ServiceImplementationRequestInput.class)); - } - - @Test - public void onServicePathRpcResultRepeatFailedCompareCase2() { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd()); - Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd()); - Mockito.when(this.serviceInputMock.getSdncRequestHeader()) - .thenReturn(serviceCreateInput.getSdncRequestHeader()); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(); - this.pceListenerImplMock.onServicePathRpcResult(notification); - Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(serviceCreateInput.getServiceName()); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - ServicePathRpcResult notification2 = - new ServicePathRpcResultBuilder(notification).setServiceName("service 2").build(); - this.pceListenerImplMock.onServicePathRpcResult(notification2); - verify(this.rendererServiceOperationsMock, times(2)) - .serviceImplementation(any(ServiceImplementationRequestInput.class)); - } - - @Test - public void onServicePathRpcResultRepeatFailedCompareCase3() { - ServiceCreateInput serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); - Mockito.when(this.serviceInputMock.getServiceCreateInput()).thenReturn(serviceCreateInput); - Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceInput.class), - any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceInputMock.getServiceAEnd()).thenReturn(serviceCreateInput.getServiceAEnd()); - Mockito.when(this.serviceInputMock.getServiceZEnd()).thenReturn(serviceCreateInput.getServiceZEnd()); - Mockito.when(this.serviceInputMock.getSdncRequestHeader()) - .thenReturn(serviceCreateInput.getSdncRequestHeader()); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - ServicePathRpcResult notification = ServiceDataUtils.buildServicePathRpcResult(); - this.pceListenerImplMock.onServicePathRpcResult(notification); - Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(serviceCreateInput.getServiceName()); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - ServicePathRpcResult notification2 = - new ServicePathRpcResultBuilder(notification).setStatus(RpcStatusEx.Failed).build(); - this.pceListenerImplMock.onServicePathRpcResult(notification2); - verify(this.rendererServiceOperationsMock, times(1)) - .serviceImplementation(any(ServiceImplementationRequestInput.class)); - } -} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImplTest.java deleted file mode 100644 index 1924a663e..000000000 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImplTest.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright © 2017 Orange, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.servicehandler.listeners; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.opendaylight.mdsal.binding.api.NotificationPublishService; -import org.opendaylight.transportpce.common.OperationResult; -import org.opendaylight.transportpce.pce.service.PathComputationService; -import org.opendaylight.transportpce.servicehandler.ServiceInput; -import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper; -import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; -import org.opendaylight.transportpce.servicehandler.utils.InjectField; -import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; -import org.opendaylight.transportpce.test.AbstractTest; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSp; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSpBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; - -public class RendererListenerImplTest extends AbstractTest { - - @InjectMocks - private RendererListenerImpl rendererListenerImplMock; - @Mock - private PathComputationService pathComputationService; - @Mock - private NotificationPublishService notificationPublishService; - @Mock - private ServiceInput serviceInputMock; - @Mock - private ServiceDataStoreOperations serviceDataStoreOperationsMock; - @Mock - private PCEServiceWrapper pceServiceWrapperMock; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void onServiceRpcResultServiceInputIsNull() { - InjectField.inject(this.rendererListenerImplMock, "tempService", false); - InjectField.inject(this.rendererListenerImplMock, "input", null); - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( - ServicePathNotificationTypes.ServiceDelete, "service 1", RpcStatusEx.Successful, ""); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(notification.getServiceName())) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(notification.getServiceName())) - .thenReturn(OperationResult.ok("Successful")); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verifyNoMoreInteractions(this.pceServiceWrapperMock); - } - - @Test - public void onServiceRpcResultSIRSuccess() { - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( - ServicePathNotificationTypes.ServiceImplementationRequest, "service 1", RpcStatusEx.Successful, ""); - Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification.getServiceName(), State.InService, - State.InService)) - .thenReturn(OperationResult.ok("Successful")); - InjectField.inject(this.rendererListenerImplMock, "tempService", false); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verify(this.serviceDataStoreOperationsMock).modifyService(any(String.class), any(State.class), - any(State.class)); - } - - @Test - public void onServiceRpcResultSIRTempSuccess() { - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( - ServicePathNotificationTypes.ServiceImplementationRequest, "service 1", RpcStatusEx.Successful, ""); - Mockito.when(this.serviceDataStoreOperationsMock.modifyTempService(notification.getServiceName(), - State.InService, State.InService)).thenReturn(OperationResult.ok("Successful")); - InjectField.inject(this.rendererListenerImplMock, "tempService", true); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verify(this.serviceDataStoreOperationsMock).modifyTempService(any(String.class), any(State.class), - any(State.class)); - } - - @Test - public void onServiceRpcResultSIRFailed() { - InjectField.inject(this.rendererListenerImplMock, "tempService", false); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( - ServicePathNotificationTypes.ServiceImplementationRequest, "service 1", RpcStatusEx.Failed, ""); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); - verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class)); - } - - @Test - public void onServiceRpcResultSIRTempFailed() { - InjectField.inject(this.rendererListenerImplMock, "tempService", true); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteTempService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( - ServicePathNotificationTypes.ServiceImplementationRequest, "service 1", RpcStatusEx.Failed, ""); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); - verify(this.serviceDataStoreOperationsMock).deleteTempService(any(String.class)); - } - - @Test - public void onServiceRpcResultSDSuccess() { - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( - ServicePathNotificationTypes.ServiceDelete, "service 1", RpcStatusEx.Successful, ""); - Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); - Mockito.when(this.pceServiceWrapperMock.cancelPCEResource(notification.getServiceName(), - ServiceNotificationTypes.ServiceDeleteResult)).thenReturn(null); - InjectField.inject(this.rendererListenerImplMock, "tempService", false); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verify(this.pceServiceWrapperMock).cancelPCEResource(any(String.class), any(ServiceNotificationTypes.class)); - } - - @Test - public void onServiceRpcResultSDTempSuccess() { - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( - ServicePathNotificationTypes.ServiceDelete, "service 1", RpcStatusEx.Successful, ""); - Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); - Mockito.when(this.pceServiceWrapperMock.cancelPCEResource(notification.getServiceName(), - ServiceNotificationTypes.ServiceDeleteResult)).thenReturn(null); - InjectField.inject(this.rendererListenerImplMock, "tempService", true); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verify(this.pceServiceWrapperMock).cancelPCEResource(any(String.class), any(ServiceNotificationTypes.class)); - } - - @Test - public void onServiceRpcResultSDFailed() { - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( - ServicePathNotificationTypes.ServiceDelete, "service 1", RpcStatusEx.Failed, ""); - InjectField.inject(this.rendererListenerImplMock, "tempService", true); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verifyZeroInteractions(this.pceServiceWrapperMock); - } - - @Test - public void onServiceRpcResultSDTempFailed() { - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp( - ServicePathNotificationTypes.ServiceDelete, "service 1", RpcStatusEx.Failed, ""); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verifyZeroInteractions(this.pceServiceWrapperMock); - } - - @Test - public void onServiceRpcResultSpRepeat() { - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp(); - Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification.getServiceName(), State.InService, - State.InService)) - .thenReturn(OperationResult.ok("Successful")); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verify(this.serviceDataStoreOperationsMock).modifyService(any(String.class), any(State.class), - any(State.class)); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verifyZeroInteractions(this.serviceDataStoreOperationsMock); - } - - @Test - public void onServiceRpcResultSpFailed() { - ServiceRpcResultSp notification = ServiceDataUtils.buildFailedServiceRpcResultSp(); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); - verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class)); - } - - @Test - public void onServiceRpcResultSpRepeatFailedCompareCase1() { - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp(); - Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification.getServiceName(), State.InService, - State.InService)).thenReturn(OperationResult.ok("Successful")); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verify(this.serviceDataStoreOperationsMock).modifyService(any(String.class), any(State.class), - any(State.class)); - ServiceRpcResultSp notification2 = new ServiceRpcResultSpBuilder(notification) - .setNotificationType(ServicePathNotificationTypes.ServiceDelete).build(); - Mockito.when(this.serviceInputMock.getServiceName()).thenReturn(notification.getServiceName()); - Mockito.when(this.pceServiceWrapperMock.cancelPCEResource(notification.getServiceName(), - ServiceNotificationTypes.ServiceDeleteResult)).thenReturn(null); - this.rendererListenerImplMock.onServiceRpcResultSp(notification2); - verify(this.pceServiceWrapperMock).cancelPCEResource(any(String.class), any(ServiceNotificationTypes.class)); - } - - @Test - public void onServiceRpcResultSpRepeatFailedCompareCase2() { - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp(); - Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification.getServiceName(), State.InService, - State.InService)).thenReturn(OperationResult.ok("Successful")); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - ServiceRpcResultSp notification2 = - new ServiceRpcResultSpBuilder(notification).setServiceName("service 2").build(); - Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification2.getServiceName(), State.InService, - State.InService)).thenReturn(OperationResult.ok("Successful")); - this.rendererListenerImplMock.onServiceRpcResultSp(notification2); - verify(this.serviceDataStoreOperationsMock, times(2)).modifyService(any(String.class), any(State.class), - any(State.class)); - } - - @Test - public void onServiceRpcResultSpRepeatFailedCompareCase3() { - ServiceRpcResultSp notification = ServiceDataUtils.buildServiceRpcResultSp(); - Mockito.when(this.serviceDataStoreOperationsMock.modifyService(notification.getServiceName(), State.InService, - State.InService)).thenReturn(OperationResult.ok("Successful")); - this.rendererListenerImplMock.onServiceRpcResultSp(notification); - verify(this.serviceDataStoreOperationsMock).modifyService(any(String.class), any(State.class), - any(State.class)); - ServiceRpcResultSp notification2 = - new ServiceRpcResultSpBuilder(notification).setStatus(RpcStatusEx.Failed).build(); - Mockito.when(this.serviceDataStoreOperationsMock.deleteServicePath(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - Mockito.when(this.serviceDataStoreOperationsMock.deleteService(any(String.class))) - .thenReturn(OperationResult.ok("Successful")); - this.rendererListenerImplMock.onServiceRpcResultSp(notification2); - verify(this.serviceDataStoreOperationsMock).deleteServicePath(any(String.class)); - verify(this.serviceDataStoreOperationsMock).deleteService(any(String.class)); - } - -}