From 1a3ddb0a21f2ab6fc3bc6607e35ea2b703192ad9 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Mon, 28 Mar 2022 12:22:31 +0100 Subject: Check if the bucket exists before deleting VSP Checks if the bucket exists before deleting VSP, ignoring the deletion if the bucket isn't present anymore. This avoids problems in case the artifact was already deleted from the artifact storage, but for some reason the VSP still present in the system. Change-Id: I7e88f227cc6786b451ca74519fa0dfe0659895c6 Issue-ID: SDC-3930 Signed-off-by: andre.schmid --- .../storage/MinIoStorageArtifactStorageManagerTest.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'common-be/src/test') diff --git a/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java b/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java index 09e62841e6..4d12a0be39 100644 --- a/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java +++ b/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java @@ -27,6 +27,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.minio.BucketExistsArgs; @@ -155,10 +156,19 @@ class MinIoStorageArtifactStorageManagerTest { @Test void testDeleteVspFail() throws Exception { + when(minioClient.bucketExists(BucketExistsArgs.builder().bucket(VSP_ID).build())).thenReturn(true); doThrow(new RuntimeException()).when(minioClient).removeBucket(any(RemoveBucketArgs.class)); - assertThrows(ArtifactStorageException.class, () -> { - testSubject.delete(VSP_ID); - }); + assertThrows(ArtifactStorageException.class, () -> testSubject.delete(VSP_ID)); + } + + @Test + void testDeleteVspBucketNotFound() throws Exception { + final BucketExistsArgs bucketExistsArgs = BucketExistsArgs.builder().bucket(VSP_ID).build(); + //when + when(minioClient.bucketExists(bucketExistsArgs)).thenReturn(false); + testSubject.delete(VSP_ID); + //then + verify(minioClient).bucketExists(bucketExistsArgs); } @Test -- cgit 1.2.3-korg