aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2022-03-29 13:41:35 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-04-25 21:55:34 +0000
commit1ff5cd3de7ccc52adf0f4cbdf9c7ab511bd5c4a5 (patch)
treec1ad607be57bbd83bf4f52d1723425853fd85d20 /catalog-be/src/test
parent7ce54a98719426a32e041e5bf30c950a4b226734 (diff)
Support deletion of archived services in SDC BE
Issue-ID: SDC-3936 Change-Id: I75201007c9cf6b71b035f14864e380d78aace12b Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java4
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java4
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java40
4 files changed, 50 insertions, 3 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java
index ee37ea130d..692e8cce50 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java
@@ -67,6 +67,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
@@ -98,6 +99,7 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
private ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
private ForwardingPathOperation forwardingPathOperation = Mockito.mock(ForwardingPathOperation.class);
+ private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
User user = null;
Service serviceResponse = null;
@@ -165,7 +167,8 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
artifactsBusinessLogic, distributionEngine, componentInstanceBusinessLogic,
serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
artifactToscaOperation, componentContactIdValidator, componentNameValidator,
- componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
+ componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator,
+ modelOperation);
bl.setUserAdmin(mockUserAdmin);
bl.setGraphLockOperation(graphLockOperation);
bl.setJanusGraphDao(mockJanusGraphDao);
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 72cb51676b..0b3973e584 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
@@ -53,6 +53,7 @@ import org.openecomp.sdc.be.model.DistributionStatusEnum;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.util.ThreadLocalsHolder;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -66,6 +67,7 @@ class ServiceDistributionBLTest extends ComponentBusinessLogicMock {
private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
private final ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+ private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
@InjectMocks
private final ServiceBusinessLogic bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
@@ -74,7 +76,7 @@ class ServiceDistributionBLTest extends ComponentBusinessLogicMock {
serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
artifactToscaOperation, componentContactIdValidator,
componentNameValidator, componentTagsValidator, componentValidator, componentIconValidator,
- componentProjectCodeValidator, componentDescriptionValidator);
+ componentProjectCodeValidator, componentDescriptionValidator, modelOperation);
private Service serviceToActivate;
private ActivationRequestInformation activationRequestInformation;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
index 44daa34aeb..5b4585136f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
@@ -78,6 +78,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.resources.data.auditing.DistributionDeployEvent;
import org.openecomp.sdc.be.resources.data.auditing.DistributionNotificationEvent;
import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
@@ -110,6 +111,7 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
protected CatalogOperation catalogOperation = Mockito.mock(CatalogOperation.class);
protected ResourceAdminEvent auditArchive2 = Mockito.mock(ResourceAdminEvent.class);
protected ResourceAdminEvent auditRestore = Mockito.mock(ResourceAdminEvent.class);
+ protected ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
IElementOperation mockElementDao = new ElementOperationMock();
DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
@@ -209,7 +211,7 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
artifactToscaOperation, componentContactIdValidator,
componentNameValidator, componentTagsValidator, componentValidator,
- componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
+ componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator, modelOperation);
bl.setComponentContactIdValidator(componentContactIdValidator);
bl.setComponentIconValidator(componentIconValidator);
bl.setComponentTagsValidator(componentTagsValidator);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
index 5c074b0599..69938cd527 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
@@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;
@@ -41,7 +42,9 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.UUID;
+
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -51,16 +54,20 @@ import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInterface;
import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.Model;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ToscaOperationException;
+import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.plugins.ServiceCreationPlugin;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
@@ -659,6 +666,39 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
assertFalse(resourceIdList.contains(resourceInUse));
}
+ @Test
+ void testDeleteArchivedService_NotFound() {
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ assertThrows(StorageException.class, () -> bl.deleteServiceAllVersions("1", user));
+ }
+
+ @Test
+ void testDeleteArchivedService_NotArchived() {
+ String serviceId = "12345";
+ Either<Component, StorageOperationStatus> eitherService = Either.left(createNewService());
+ eitherService.left().value().setArchived(false);
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
+ final ComponentException actualException = assertThrows(ComponentException.class, () -> bl.deleteServiceAllVersions(serviceId, user));
+ assertEquals(actualException.getActionStatus(), ActionStatus.COMPONENT_NOT_ARCHIVED);
+ assertEquals(actualException.getParams()[0], serviceId);
+ }
+
+ @Test
+ void testDeleteArchivedService_DeleteServiceSpecificModel() throws ToscaOperationException {
+ String serviceId = "12345";
+ String model = "serviceSpecificModel";
+ List<String> deletedServcies= new ArrayList<>();
+ deletedServcies.add("54321");
+ Model normativeExtensionModel = new Model("normativeExtensionModel", ModelTypeEnum.NORMATIVE_EXTENSION);
+ Either<Component, StorageOperationStatus> eitherService = Either.left(createNewService());
+ eitherService.left().value().setArchived(true);
+ eitherService.left().value().setModel(model);
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
+ Mockito.when(toscaOperationFacade.deleteService(Mockito.anyString(), Mockito.eq(true))).thenReturn(deletedServcies);
+ Mockito.when(modelOperation.findModelByName(model)).thenReturn(Optional.of(normativeExtensionModel));
+ bl.deleteServiceAllVersions(serviceId, user);
+ Mockito.verify(modelOperation, Mockito.times(1)).deleteModel(normativeExtensionModel, false);
+ }
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test