diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-02-22 09:50:07 +0000 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2021-02-22 11:57:03 +0000 |
commit | 086406a3af88a1f77e2be783e6f458dc3c66d4ca (patch) | |
tree | f677da1b183d54729c6f9cffe3ae2a85f238c85f /catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java | |
parent | 2b609a313cfa4ab4b523f20627541264ad1e30f5 (diff) |
Fix locally failing TCs in catalog-be
Migrate to Junit 5 TCs that extends JerseyTest
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I4c81e70836ee5e634291d74cd1773d221dce3702
Issue-ID: SDC-3377
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java')
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java | 83 |
1 files changed, 37 insertions, 46 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java index 68fa486270..9b6a26d5e3 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java @@ -28,8 +28,8 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; import fj.data.Either; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -57,10 +57,7 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration; import org.openecomp.sdc.common.util.ThreadLocalsHolder; import org.openecomp.sdc.exception.ResponseFormat; -/** - * Created by chaya on 10/26/2017. - */ -public class ServiceDistributionBLTest extends ComponentBusinessLogicMock { +class ServiceDistributionBLTest extends ComponentBusinessLogicMock { private final ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class); private final DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class); @@ -70,9 +67,8 @@ public class ServiceDistributionBLTest extends ComponentBusinessLogicMock { private final ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class); private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class); - @InjectMocks - ServiceBusinessLogic bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, + private final ServiceBusinessLogic bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, distributionEngine, componentInstanceBusinessLogic, serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter, @@ -80,8 +76,6 @@ public class ServiceDistributionBLTest extends ComponentBusinessLogicMock { componentNameValidator, componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator); - ComponentsUtils componentsUtils; - private Service serviceToActivate; private ActivationRequestInformation activationRequestInformation; private String WORKLOAD_CONTEXT = "vnfContext"; @@ -89,46 +83,42 @@ public class ServiceDistributionBLTest extends ComponentBusinessLogicMock { private String DID = "distributionId"; private User modifier; - - public ServiceDistributionBLTest() { - } - - @Before + @BeforeEach public void setup() { ExternalConfiguration.setAppName("catalog-be"); MockitoAnnotations.initMocks(this); - componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); + final ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); bl.setComponentsUtils(componentsUtils); serviceToActivate = new Service(); serviceToActivate.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED); activationRequestInformation = new ActivationRequestInformation(serviceToActivate, WORKLOAD_CONTEXT, TENANT); when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))) - .thenReturn(Either.left(serviceToActivate)); + .thenReturn(Either.left(serviceToActivate)); when(distributionEngine.buildServiceForDistribution(any(Service.class), anyString(), anyString())) - .thenReturn(new NotificationDataImpl()); + .thenReturn(new NotificationDataImpl()); modifier = new User(); modifier.setUserId("uid"); modifier.setFirstName("user"); } @Test - public void testActivateServiceOnTenantValidationFails() { + void testActivateServiceOnTenantValidationFails() { int VALIDATION_FAIL_STATUS = 666; when(serviceDistributionValidation.validateActivateServiceRequest - (anyString(), anyString(),any(User.class), any(ServiceDistributionReqInfo.class))) - .thenReturn(Either.right(new ResponseFormat(VALIDATION_FAIL_STATUS))); + (anyString(), anyString(), any(User.class), any(ServiceDistributionReqInfo.class))) + .thenReturn(Either.right(new ResponseFormat(VALIDATION_FAIL_STATUS))); Either<String, ResponseFormat> stringResponseFormatEither = callActivateServiceOnTenantWIthDefaults(); assertTrue(stringResponseFormatEither.isRight()); assertEquals((int) stringResponseFormatEither.right().value().getStatus(), VALIDATION_FAIL_STATUS); } //TODO see if we want to add ActionStatus.AUTHENTICATION_ERROR to error-configuration.yaml - @Test - public void testDistributionAuthenticationFails() { + @Test() + void testDistributionAuthenticationFails() { mockAllMethodsUntilDENotification(); - when(distributionEngine.notifyService(anyString(),any(Service.class), any(INotificationData.class), anyString(),any(User.class))) - .thenReturn(ActionStatus.AUTHENTICATION_ERROR); + when(distributionEngine.notifyService(anyString(), any(Service.class), any(INotificationData.class), anyString(), any(User.class))) + .thenReturn(ActionStatus.AUTHENTICATION_ERROR); Either<String, ResponseFormat> stringResponseFormatEither = callActivateServiceOnTenantWIthDefaults(); assertTrue(stringResponseFormatEither.isRight()); assertEquals(502, (int) stringResponseFormatEither.right().value().getStatus()); @@ -136,11 +126,11 @@ public class ServiceDistributionBLTest extends ComponentBusinessLogicMock { } //TODO see if we want to add ActionStatus.AUTHENTICATION_ERROR to error-configuration.yaml - @Test - public void testDistributionUnknownHostFails() { + @Test() + void testDistributionUnknownHostFails() { mockAllMethodsUntilDENotification(); - when(distributionEngine.notifyService(anyString(),any(Service.class), any(INotificationData.class), anyString(), any(User.class))) - .thenReturn(ActionStatus.UNKNOWN_HOST); + when(distributionEngine.notifyService(anyString(), any(Service.class), any(INotificationData.class), anyString(), any(User.class))) + .thenReturn(ActionStatus.UNKNOWN_HOST); Either<String, ResponseFormat> stringResponseFormatEither = callActivateServiceOnTenantWIthDefaults(); assertTrue(stringResponseFormatEither.isRight()); assertEquals(502, (int) stringResponseFormatEither.right().value().getStatus()); @@ -148,11 +138,11 @@ public class ServiceDistributionBLTest extends ComponentBusinessLogicMock { } //TODO see if we want to add ActionStatus.AUTHENTICATION_ERROR to error-configuration.yaml - @Test - public void testDistributionConnectionErrorFails() { + @Test() + void testDistributionConnectionErrorFails() { mockAllMethodsUntilDENotification(); - when(distributionEngine.notifyService(anyString(),any(Service.class), any(INotificationData.class), anyString(), any(User.class))) - .thenReturn(ActionStatus.CONNNECTION_ERROR); + when(distributionEngine.notifyService(anyString(), any(Service.class), any(INotificationData.class), anyString(), any(User.class))) + .thenReturn(ActionStatus.CONNNECTION_ERROR); Either<String, ResponseFormat> stringResponseFormatEither = callActivateServiceOnTenantWIthDefaults(); assertTrue(stringResponseFormatEither.isRight()); assertEquals(502, (int) stringResponseFormatEither.right().value().getStatus()); @@ -160,22 +150,22 @@ public class ServiceDistributionBLTest extends ComponentBusinessLogicMock { } //TODO see if we want to add ActionStatus.AUTHENTICATION_ERROR to error-configuration.yaml - @Test - public void testDistributionObjectNotFoundFails() { + @Test() + void testDistributionObjectNotFoundFails() { mockAllMethodsUntilDENotification(); - when(distributionEngine.notifyService(anyString(),any(Service.class), any(INotificationData.class), anyString(), any(User.class))) - .thenReturn(ActionStatus.OBJECT_NOT_FOUND); + when(distributionEngine.notifyService(anyString(), any(Service.class), any(INotificationData.class), anyString(), any(User.class))) + .thenReturn(ActionStatus.OBJECT_NOT_FOUND); Either<String, ResponseFormat> stringResponseFormatEither = callActivateServiceOnTenantWIthDefaults(); assertTrue(stringResponseFormatEither.isRight()); assertEquals(502, (int) stringResponseFormatEither.right().value().getStatus()); assertEquals("SVC4676", stringResponseFormatEither.right().value().getMessageId()); } - @Test - public void testDistributionGeneralFails() { + @Test() + void testDistributionGeneralFails() { mockAllMethodsUntilDENotification(); - when(distributionEngine.notifyService(anyString(),any(Service.class), any(INotificationData.class), anyString(), any(User.class))) - .thenReturn(ActionStatus.GENERAL_ERROR); + when(distributionEngine.notifyService(anyString(), any(Service.class), any(INotificationData.class), anyString(), any(User.class))) + .thenReturn(ActionStatus.GENERAL_ERROR); Either<String, ResponseFormat> stringResponseFormatEither = callActivateServiceOnTenantWIthDefaults(); assertTrue(stringResponseFormatEither.isRight()); assertEquals(502, (int) stringResponseFormatEither.right().value().getStatus()); @@ -183,11 +173,12 @@ public class ServiceDistributionBLTest extends ComponentBusinessLogicMock { } @Test - public void testDistributionOk() { + void testDistributionOk() { mockAllMethodsUntilDENotification(); ThreadLocalsHolder.setUuid(DID); - when(distributionEngine.notifyService(anyString(),any(Service.class), any(INotificationData.class), anyString(), anyString(), any(User.class))) - .thenReturn(ActionStatus.OK); + when(distributionEngine + .notifyService(anyString(), any(Service.class), any(INotificationData.class), anyString(), anyString(), any(User.class))) + .thenReturn(ActionStatus.OK); Either<String, ResponseFormat> stringResponseFormatEither = callActivateServiceOnTenantWIthDefaults(); assertTrue(stringResponseFormatEither.isLeft()); assertEquals(stringResponseFormatEither.left().value(), DID); @@ -195,8 +186,8 @@ public class ServiceDistributionBLTest extends ComponentBusinessLogicMock { private void mockAllMethodsUntilDENotification() { when(serviceDistributionValidation.validateActivateServiceRequest - (anyString(), anyString(),any(User.class), any(ServiceDistributionReqInfo.class))) - .thenReturn(Either.left(activationRequestInformation)); + (anyString(), anyString(), any(User.class), any(ServiceDistributionReqInfo.class))) + .thenReturn(Either.left(activationRequestInformation)); when(healthCheckBusinessLogic.isDistributionEngineUp()).thenReturn(true); } |