diff options
author | 2022-03-24 16:38:00 +0000 | |
---|---|---|
committer | 2022-03-28 08:37:43 +0000 | |
commit | 4307dbb5f0dc5da60e55f3473259cfd059d14770 (patch) | |
tree | acb1afb19475a772f9169ed0e8f49ea722905a6c /openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp | |
parent | 0902d2829ce984730085c816b649bed957ac0d99 (diff) |
Implement VSP deletion from Storage
Change-Id: I06d86696570b2751f152dffc06fd580ef8c0c705
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3924
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')
1 files changed, 69 insertions, 36 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 1a1d0b5650..6340d0819a 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,13 +21,27 @@ package org.openecomp.sdcrests.vsp.rest.services; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +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_FROM_STORAGE_ERROR; + +import java.util.List; +import java.util.UUID; +import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; 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.itempermissions.PermissionsManager; import org.openecomp.sdc.notification.services.NotificationPropagationManager; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; @@ -37,17 +51,6 @@ import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.types.Item; import org.openecomp.sdc.versioning.types.ItemStatus; -import javax.ws.rs.core.Response; -import java.util.List; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.openMocks; -import static org.openecomp.sdc.common.errors.Messages.DELETE_VSP_ERROR; - class VendorSoftwareProductsImplTest { private final String vspId = UUID.randomUUID().toString(); @@ -67,64 +70,94 @@ class VendorSoftwareProductsImplTest { private NotificationPropagationManager notificationPropagationManager; @Mock private UniqueValueUtil uniqueValueUtil; + @Mock + private ArtifactStorageManager artifactStorageManager; + @InjectMocks private VendorSoftwareProductsImpl vendorSoftwareProducts; + private Item item; + @BeforeEach public void setUp() { openMocks(this); - vendorSoftwareProducts = new VendorSoftwareProductsImpl( - itemManager, - permissionsManager, - versioningManager, - vendorSoftwareProductManager, - activityLogManager, - notificationPropagationManager, - uniqueValueUtil); - - Item item = new Item(); + item = new Item(); item.setType("vsp"); item.setId(vspId); - when(itemManager.get( - ArgumentMatchers.eq(vspId))).thenReturn(item); + when(itemManager.get(vspId)).thenReturn(item); } @Test void deleteVspOk() { + Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user); + assertEquals(HttpStatus.SC_OK, rsp.getStatus()); + assertNull(rsp.getEntity()); + } + @Test + void deleteVspWithS3Ok() { + when(artifactStorageManager.isEnabled()).thenReturn(true); Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user); assertEquals(HttpStatus.SC_OK, rsp.getStatus()); assertNull(rsp.getEntity()); } @Test + void deleteVspWithS3Fail() { + when(artifactStorageManager.isEnabled()).thenReturn(true); + doThrow(new RuntimeException()).when(artifactStorageManager).delete(anyString()); + Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user); + assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, rsp.getStatus()); + assertEquals(rsp.getEntity().getClass(), Exception.class); + assertEquals(((Exception) rsp.getEntity()).getLocalizedMessage(), DELETE_VSP_FROM_STORAGE_ERROR.formatMessage(vspId)); + } + + @Test void deleteCertifiedVsp() { - Item item = new Item(); - item.setType("vsp"); - item.setId(vspId); item.addVersionStatus(VersionStatus.Certified); - when(itemManager.get( - ArgumentMatchers.eq(vspId))).thenReturn(item); + when(itemManager.get(vspId)).thenReturn(item); Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user); assertEquals(HttpStatus.SC_FORBIDDEN, rsp.getStatus()); assertEquals(rsp.getEntity().getClass(), Exception.class); - assertEquals(((Exception)rsp.getEntity()).getLocalizedMessage(), DELETE_VSP_ERROR.getErrorMessage()); + assertEquals(((Exception) rsp.getEntity()).getLocalizedMessage(), DELETE_VSP_ERROR.getErrorMessage()); } @Test void deleteCertifiedArchivedVsp() { - Item item = new Item(); - item.setType("vsp"); - item.setId(vspId); item.setStatus(ItemStatus.ARCHIVED); item.addVersionStatus(VersionStatus.Certified); - when(itemManager.get( - ArgumentMatchers.eq(vspId))).thenReturn(item); + when(itemManager.get(vspId)).thenReturn(item); when(itemManager.list(any())).thenReturn(List.of(item)); Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user); assertEquals(HttpStatus.SC_OK, rsp.getStatus()); assertNull(rsp.getEntity()); } -}
\ No newline at end of file + + @Test + void deleteCertifiedArchivedVspWithS3OK() { + when(artifactStorageManager.isEnabled()).thenReturn(true); + item.setStatus(ItemStatus.ARCHIVED); + item.addVersionStatus(VersionStatus.Certified); + when(itemManager.get(vspId)).thenReturn(item); + when(itemManager.list(any())).thenReturn(List.of(item)); + Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user); + assertEquals(HttpStatus.SC_OK, rsp.getStatus()); + assertNull(rsp.getEntity()); + } + + @Test + void deleteCertifiedArchivedVspWithS3Fail() { + when(artifactStorageManager.isEnabled()).thenReturn(true); + doThrow(new RuntimeException()).when(artifactStorageManager).delete(anyString()); + item.setStatus(ItemStatus.ARCHIVED); + item.addVersionStatus(VersionStatus.Certified); + when(itemManager.get(vspId)).thenReturn(item); + when(itemManager.list(any())).thenReturn(List.of(item)); + Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user); + assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, rsp.getStatus()); + assertEquals(rsp.getEntity().getClass(), Exception.class); + assertEquals(((Exception) rsp.getEntity()).getLocalizedMessage(), DELETE_VSP_FROM_STORAGE_ERROR.formatMessage(vspId)); + } +} |