summaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp
diff options
context:
space:
mode:
authorfranciscovila <javier.paradela.vila@est.tech>2022-03-10 11:55:04 +0000
committerfranciscovila <javier.paradela.vila@est.tech>2022-03-29 12:47:29 +0100
commitf772969ac32331ce847e8193059cd39dd362c7a6 (patch)
tree9e4986f2abb174b085f7a83f84bbdf3288e3869b /openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp
parent28e7f0f13e3d7b75750a449c9bda6c0d4a1986ce (diff)
Restrict deletion of archived VSPs if used in VF
Verify if a VSP is used in a VF in SDC-BE before proceeding with the deletion of a VSP Issue-ID: SDC-3894 Signed-off-by: franciscovila <javier.paradela.vila@est.tech> Change-Id: I7c8bdd55516a51cf8693cfdb8c109a7c20e7ea84
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImplTest.java80
1 files changed, 78 insertions, 2 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImplTest.java
index 6340d0819a..f8af8df1ed 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImplTest.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImplTest.java
@@ -21,6 +21,7 @@
package org.openecomp.sdcrests.vsp.rest.services;
+import static ch.qos.logback.classic.util.ContextInitializer.CONFIG_FILE_PROPERTY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
@@ -29,9 +30,15 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.openMocks;
import static org.openecomp.sdc.common.errors.Messages.DELETE_VSP_ERROR;
+import static org.openecomp.sdc.common.errors.Messages.DELETE_VSP_ERROR_USED_BY_VF;
import static org.openecomp.sdc.common.errors.Messages.DELETE_VSP_FROM_STORAGE_ERROR;
+import java.io.FileNotFoundException;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.List;
+import java.util.Optional;
import java.util.UUID;
import javax.ws.rs.core.Response;
import org.apache.http.HttpStatus;
@@ -42,6 +49,7 @@ import org.mockito.Mock;
import org.openecomp.core.util.UniqueValueUtil;
import org.openecomp.sdc.activitylog.ActivityLogManager;
import org.openecomp.sdc.be.csar.storage.ArtifactStorageManager;
+import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.itempermissions.PermissionsManager;
import org.openecomp.sdc.notification.services.NotificationPropagationManager;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
@@ -50,12 +58,17 @@ import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.types.Item;
import org.openecomp.sdc.versioning.types.ItemStatus;
+import org.openecomp.sdcrests.vsp.rest.CatalogVspClient;
class VendorSoftwareProductsImplTest {
+ public static final String SOME_INTERNAL_ERROR = "Some internal error";
+ public static final String VF_NAME = "Vf_name";
private final String vspId = UUID.randomUUID().toString();
private final String user = "cs0008";
+ private final Path testResourcesPath = Paths.get("src", "test", "resources");
+
@Mock
private AsdcItemManager itemManager;
@Mock
@@ -72,6 +85,8 @@ class VendorSoftwareProductsImplTest {
private UniqueValueUtil uniqueValueUtil;
@Mock
private ArtifactStorageManager artifactStorageManager;
+ @Mock
+ private CatalogVspClient catalogVspClient;
@InjectMocks
private VendorSoftwareProductsImpl vendorSoftwareProducts;
@@ -82,6 +97,8 @@ class VendorSoftwareProductsImplTest {
public void setUp() {
openMocks(this);
+ System.setProperty("configuration.yaml", Paths.get(testResourcesPath.toString(), "configuration.yaml").toAbsolutePath().toString());
+
item = new Item();
item.setType("vsp");
item.setId(vspId);
@@ -89,7 +106,7 @@ class VendorSoftwareProductsImplTest {
}
@Test
- void deleteVspOk() {
+ void deleteNotCertifiedVspOk() {
Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user);
assertEquals(HttpStatus.SC_OK, rsp.getStatus());
assertNull(rsp.getEntity());
@@ -125,7 +142,9 @@ class VendorSoftwareProductsImplTest {
}
@Test
- void deleteCertifiedArchivedVsp() {
+ void deleteCertifiedArchivedVsp() throws FileNotFoundException {
+ String configPath = getConfigPath("configuration.yaml");
+ System.setProperty(CONFIG_FILE_PROPERTY, configPath);
item.setStatus(ItemStatus.ARCHIVED);
item.addVersionStatus(VersionStatus.Certified);
when(itemManager.get(vspId)).thenReturn(item);
@@ -160,4 +179,61 @@ class VendorSoftwareProductsImplTest {
assertEquals(rsp.getEntity().getClass(), Exception.class);
assertEquals(((Exception) rsp.getEntity()).getLocalizedMessage(), DELETE_VSP_FROM_STORAGE_ERROR.formatMessage(vspId));
}
+
+ @Test
+ void deleteVspUsedInVfKo() throws Exception {
+ Item item = new Item();
+ item.setType("vsp");
+ item.setId(vspId);
+ item.addVersionStatus(VersionStatus.Certified);
+ when(itemManager.get(vspId)).thenReturn(item);
+ when(catalogVspClient.findNameOfVfUsingVsp(vspId, user)).thenReturn(Optional.of(VF_NAME));
+
+ Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user);
+ assertEquals(HttpStatus.SC_FORBIDDEN, rsp.getStatus());
+ assertEquals(rsp.getEntity().getClass(), Exception.class);
+ assertEquals(((Exception)rsp.getEntity()).getLocalizedMessage(), String.format(DELETE_VSP_ERROR_USED_BY_VF.getErrorMessage(), VF_NAME, VF_NAME));
+ }
+
+ @Test
+ void deleteVspUsedInVfThrowsExceptionKo() throws Exception {
+ Item item = new Item();
+ item.setType("vsp");
+ item.setId(vspId);
+ item.addVersionStatus(VersionStatus.Certified);
+ when(itemManager.get(vspId)).thenReturn(item);
+ final String vf_name = "Vf_name";
+ when(catalogVspClient.findNameOfVfUsingVsp(vspId, user)).thenThrow(new Exception(SOME_INTERNAL_ERROR));
+
+ Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user);
+ assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, rsp.getStatus());
+ assertEquals(rsp.getEntity().getClass(), CoreException.class);
+ assertEquals(((Exception)rsp.getEntity()).getLocalizedMessage(), String.format("Vsp with id %s cannot be deleted due to error %s.", vspId, SOME_INTERNAL_ERROR));
+ }
+
+ @Test
+ void deleteCertifiedArchivedVspNotInVfOk() throws Exception {
+ String configPath = getConfigPath("configuration.yaml");
+ System.setProperty(CONFIG_FILE_PROPERTY, configPath);
+ Item item = new Item();
+ item.setType("vsp");
+ item.setId(vspId);
+ item.setStatus(ItemStatus.ARCHIVED);
+ item.addVersionStatus(VersionStatus.Certified);
+ when(itemManager.get(vspId)).thenReturn(item);
+ when(itemManager.list(any())).thenReturn(List.of(item));
+ when(catalogVspClient.findNameOfVfUsingVsp(vspId, user)).thenReturn(Optional.empty());
+ Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user);
+ assertEquals(HttpStatus.SC_OK, rsp.getStatus());
+ assertNull(rsp.getEntity());
+ }
+
+ private String getConfigPath(String classpathFile) throws FileNotFoundException {
+
+ URL resource = Thread.currentThread().getContextClassLoader().getResource(classpathFile);
+ if (resource == null) {
+ throw new FileNotFoundException("Cannot find resource: " + classpathFile);
+ }
+ return resource.getPath();
+ }
}