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/rest/services
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-03-24 13:11:04 +0000
committerMichael Morris <michael.morris@est.tech>2022-04-04 15:25:41 +0000
commitf6b81e6da9b95ec5ef2c8b2b7b50fb8de9f3dd28 (patch)
tree6503dc17a281a267dbf9e775552ac4444a6b7170 /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
parentf2e43fb0a2c36b484b686d6c22342e72da66f679 (diff)
Log partial VSP deletion
Adds entries to the VSP activity log identifying the VSP versions deleted from the MinIO client, and also if the deletion was fully complete. If the VSP deletion from the database fails, there will be registry of what happened with the MinIO deletion. Do some refactor in the VendorSoftwareProductsImpl in relation to the VSP deletion flow and responses. Issue-ID: SDC-3931 Change-Id: I75cb9d7fb74a48db01b242a5f70fefa0a88faa0d Signed-off-by: andre.schmid <andre.schmid@est.tech>
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/rest/services')
-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/OrchestrationTemplateCandidateImplTest.java18
-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.java149
2 files changed, 111 insertions, 56 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/OrchestrationTemplateCandidateImplTest.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/OrchestrationTemplateCandidateImplTest.java
index 8fd160a886..bdd70ed589 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/OrchestrationTemplateCandidateImplTest.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/OrchestrationTemplateCandidateImplTest.java
@@ -399,24 +399,6 @@ class OrchestrationTemplateCandidateImplTest {
.putUploadAsFinished(candidateId, versionId, vspUploadStatusDto.getLockId(), VspUploadStatus.ERROR, user);
}
-// @Test
-// void uploadTestWithLatestStatusComplete() {
-// final VspUploadStatusDto vspUploadStatusDto = new VspUploadStatusDto();
-// vspUploadStatusDto.setComplete(true);
-// //given
-// when(orchestrationTemplateCandidateUploadManager.findLatestStatus(candidateId, versionId, user)).thenReturn(Optional.of(vspUploadStatusDto));
-// final Attachment mock = Mockito.mock(Attachment.class);
-// when(mock.getDataHandler()).thenReturn(Mockito.mock(DataHandler.class));
-// //when
-// final CoreException actualException = assertThrows(CoreException.class,
-// () -> orchestrationTemplateCandidate.upload(candidateId, versionId, mock, user));
-// final CoreException expectedException = couldNotAcceptPackageNoUploadInProgress(candidateId, versionId).get();
-// //then
-// assertEquals(expectedException.code().id(), actualException.code().id());
-// assertEquals(expectedException.code().message(), actualException.code().message());
-// verify(orchestrationTemplateCandidateUploadManager).findLatestStatus(candidateId, versionId, user);
-// }
-
@Test
void uploadTestWithUploadInProgress() {
final VspUploadStatusDto vspUploadStatusDto = new VspUploadStatusDto();
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 1936aaa7b4..76e4910a66 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
@@ -23,14 +23,17 @@ 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.assertFalse;
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.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
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;
@@ -44,22 +47,30 @@ 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.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.openecomp.core.util.UniqueValueUtil;
import org.openecomp.sdc.activitylog.ActivityLogManager;
+import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
+import org.openecomp.sdc.activitylog.dao.type.ActivityType;
import org.openecomp.sdc.be.csar.storage.ArtifactStorageManager;
-import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.be.csar.storage.StorageFactory;
+import org.openecomp.sdc.common.errors.CatalogRestClientException;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.datatypes.model.ItemType;
import org.openecomp.sdc.itempermissions.PermissionsManager;
import org.openecomp.sdc.notification.services.NotificationPropagationManager;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
import org.openecomp.sdc.versioning.AsdcItemManager;
import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.dao.types.Version;
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;
+import org.openecomp.sdcrests.vsp.rest.exception.VendorSoftwareProductsExceptionSupplier;
class VendorSoftwareProductsImplTest {
@@ -103,7 +114,7 @@ class VendorSoftwareProductsImplTest {
System.setProperty("configuration.yaml", Paths.get(testResourcesPath.toString(), "configuration.yaml").toAbsolutePath().toString());
item = new Item();
- item.setType("vsp");
+ item.setType(ItemType.vsp.getName());
item.setId(vspId);
when(itemManager.get(vspId)).thenReturn(item);
when(storageFactory.createArtifactStorageManager()).thenReturn(artifactStorageManager);
@@ -111,9 +122,10 @@ class VendorSoftwareProductsImplTest {
@Test
void deleteNotCertifiedVspOk() {
- Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user);
- assertEquals(HttpStatus.SC_OK, rsp.getStatus());
- assertNull(rsp.getEntity());
+ when(itemManager.list(any())).thenReturn(List.of(item));
+ Response actualResponse = vendorSoftwareProducts.deleteVsp(vspId, user);
+ assertEquals(HttpStatus.SC_OK, actualResponse.getStatus());
+ assertNull(actualResponse.getEntity());
}
@Test
@@ -128,10 +140,9 @@ class VendorSoftwareProductsImplTest {
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));
+ final CoreException actualException = assertThrows(CoreException.class, () -> vendorSoftwareProducts.deleteVsp(vspId, user));
+ final CoreException expectedException = VendorSoftwareProductsExceptionSupplier.deleteVspFromStorageFailure(vspId).get();
+ assertErrorCode(actualException.code(), expectedException.code());
}
@Test
@@ -139,10 +150,9 @@ class VendorSoftwareProductsImplTest {
item.addVersionStatus(VersionStatus.Certified);
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());
+ final CoreException actualException = assertThrows(CoreException.class, () -> vendorSoftwareProducts.deleteVsp(vspId, user));
+ final CoreException expectedException = VendorSoftwareProductsExceptionSupplier.deleteNotArchivedVsp(vspId).get();
+ assertErrorCode(actualException.code(), expectedException.code());
}
@Test
@@ -159,64 +169,120 @@ class VendorSoftwareProductsImplTest {
}
@Test
+ void deleteCertifiedAndNotArchivedVsp() {
+ item.setStatus(ItemStatus.ACTIVE);
+ item.addVersionStatus(VersionStatus.Certified);
+ when(itemManager.get(vspId)).thenReturn(item);
+
+ final CoreException actualException = assertThrows(CoreException.class, () -> vendorSoftwareProducts.deleteVsp(vspId, user));
+ final CoreException expectedException = VendorSoftwareProductsExceptionSupplier.deleteNotArchivedVsp(vspId).get();
+ assertErrorCode(actualException.code(), expectedException.code());
+ }
+
+ @Test
+ void deleteVspNotFoundTest() {
+ when(itemManager.get(vspId)).thenReturn(new Item());
+ final CoreException actualException = assertThrows(CoreException.class, () -> vendorSoftwareProducts.deleteVsp(vspId, user));
+ final CoreException expectedException = VendorSoftwareProductsExceptionSupplier.vspNotFound(vspId).get();
+ assertEquals(expectedException.code().id(), actualException.code().id());
+ assertEquals(expectedException.code().message(), actualException.code().message());
+ }
+
+ @Test
void deleteCertifiedArchivedVspWithS3OK() {
when(artifactStorageManager.isEnabled()).thenReturn(true);
item.setStatus(ItemStatus.ARCHIVED);
item.addVersionStatus(VersionStatus.Certified);
when(itemManager.get(vspId)).thenReturn(item);
+
+ final Version version1 = new Version("version1Id");
+ final Version version2 = new Version("version2Id");
+ final List<Version> versionList = List.of(version1, version2);
+ when(versioningManager.list(vspId)).thenReturn(versionList);
+
when(itemManager.list(any())).thenReturn(List.of(item));
Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user);
assertEquals(HttpStatus.SC_OK, rsp.getStatus());
assertNull(rsp.getEntity());
+
+ final ArgumentCaptor<ActivityLogEntity> logActivityArgument = ArgumentCaptor.forClass(ActivityLogEntity.class);
+ verify(activityLogManager, times(2)).logActivity(logActivityArgument.capture());
+ final List<ActivityLogEntity> logActivityArgumentList = logActivityArgument.getAllValues();
+ assertEquals(versionList.size(), logActivityArgumentList.size());
+ for (int i = 0; i < versionList.size(); i++) {
+ final Version expectedVersion = versionList.get(i);
+ final ActivityLogEntity actualLogActivityArgument = logActivityArgumentList.get(i);
+ assertTrue(actualLogActivityArgument.isSuccess());
+ assertEquals(vspId, actualLogActivityArgument.getItemId());
+ assertEquals(expectedVersion.getId(), actualLogActivityArgument.getVersionId());
+ assertEquals(user, actualLogActivityArgument.getUser());
+ assertEquals(ActivityType.Delete_From_Storage, actualLogActivityArgument.getType());
+ }
}
@Test
void deleteCertifiedArchivedVspWithS3Fail() {
+ //given
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));
+
+ final Version version1 = new Version("version1Id");
+ final Version version2 = new Version("version2Id");
+ final List<Version> versionList = List.of(version1, version2);
+ when(versioningManager.list(vspId)).thenReturn(versionList);
+
+ //when
+ final CoreException actualException = assertThrows(CoreException.class, () -> vendorSoftwareProducts.deleteVsp(vspId, user));
+
+ //then
+ final CoreException expectedException = VendorSoftwareProductsExceptionSupplier.deleteVspFromStorageFailure(vspId).get();
+ assertErrorCode(actualException.code(), expectedException.code());
+
+ final ArgumentCaptor<ActivityLogEntity> logActivityArgument = ArgumentCaptor.forClass(ActivityLogEntity.class);
+ verify(activityLogManager, times(2)).logActivity(logActivityArgument.capture());
+ final List<ActivityLogEntity> logActivityArgumentList = logActivityArgument.getAllValues();
+ assertEquals(versionList.size(), logActivityArgumentList.size());
+ for (int i = 0; i < versionList.size(); i++) {
+ final Version expectedVersion = versionList.get(i);
+ final ActivityLogEntity actualLogActivityArgument = logActivityArgumentList.get(i);
+ assertFalse(actualLogActivityArgument.isSuccess());
+ assertEquals(vspId, actualLogActivityArgument.getItemId());
+ assertEquals(expectedVersion.getId(), actualLogActivityArgument.getVersionId());
+ assertEquals(user, actualLogActivityArgument.getUser());
+ assertEquals(ActivityType.Delete_From_Storage, actualLogActivityArgument.getType());
+ assertEquals(DELETE_VSP_FROM_STORAGE_ERROR.formatMessage(vspId), actualLogActivityArgument.getMessage());
+ assertEquals(DELETE_VSP_FROM_STORAGE_ERROR.formatMessage(vspId), actualLogActivityArgument.getComment());
+ }
}
@Test
- void deleteVspUsedInVfKo() throws Exception {
- Item item = new Item();
- item.setType("vsp");
- item.setId(vspId);
+ void deleteVspUsedInVfKo() {
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));
+ final CoreException actualException = assertThrows(CoreException.class, () -> vendorSoftwareProducts.deleteVsp(vspId, user));
+ final CoreException expectedException = VendorSoftwareProductsExceptionSupplier.vspInUseByVf(VF_NAME).get();
+ assertErrorCode(actualException.code(), expectedException.code());
}
@Test
- void deleteVspUsedInVfThrowsExceptionKo() throws Exception {
- Item item = new Item();
- item.setType("vsp");
- item.setId(vspId);
+ void deleteVspUsedInVfThrowsExceptionKo() {
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));
+ when(catalogVspClient.findNameOfVfUsingVsp(vspId, user)).thenThrow(new CatalogRestClientException(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));
+ final CoreException actualException = assertThrows(CoreException.class, () -> vendorSoftwareProducts.deleteVsp(vspId, user));
+ final CoreException expectedException = VendorSoftwareProductsExceptionSupplier.deleteGenericError(vspId).get();
+ assertErrorCode(actualException.code(), expectedException.code());
}
@Test
- void deleteCertifiedArchivedVspNotInVfOk() throws Exception {
+ void deleteCertifiedArchivedVspNotInVfOk() throws FileNotFoundException {
String configPath = getConfigPath("configuration.yaml");
System.setProperty(CONFIG_FILE_PROPERTY, configPath);
Item item = new Item();
@@ -240,4 +306,11 @@ class VendorSoftwareProductsImplTest {
}
return resource.getPath();
}
+
+ private void assertErrorCode(final ErrorCode actualErrorCode, final ErrorCode expectedErrorCode) {
+ assertEquals(expectedErrorCode.id(), actualErrorCode.id());
+ assertEquals(expectedErrorCode.category(), actualErrorCode.category());
+ assertEquals(expectedErrorCode.message(), actualErrorCode.message());
+ }
+
}