aboutsummaryrefslogtreecommitdiffstats
path: root/common-be/src/test/java/org
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-03-24 16:38:00 +0000
committerMichael Morris <michael.morris@est.tech>2022-03-28 08:37:43 +0000
commit4307dbb5f0dc5da60e55f3473259cfd059d14770 (patch)
treeacb1afb19475a772f9169ed0e8f49ea722905a6c /common-be/src/test/java/org
parent0902d2829ce984730085c816b649bed957ac0d99 (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 'common-be/src/test/java/org')
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java74
1 files changed, 72 insertions, 2 deletions
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 fa577913fa..09e62841e6 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
@@ -20,17 +20,29 @@
package org.openecomp.sdc.be.csar.storage;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
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.when;
import io.minio.BucketExistsArgs;
+import io.minio.GetObjectArgs;
+import io.minio.GetObjectResponse;
+import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
+import io.minio.RemoveBucketArgs;
+import io.minio.RemoveObjectArgs;
+import io.minio.StatObjectArgs;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Path;
import javax.activation.DataHandler;
+import okhttp3.Headers;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -44,6 +56,7 @@ import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.csar.storage.MinIoStorageArtifactStorageConfig.Credentials;
import org.openecomp.sdc.be.csar.storage.MinIoStorageArtifactStorageConfig.EndPoint;
+import org.openecomp.sdc.be.csar.storage.exception.ArtifactStorageException;
@ExtendWith(MockitoExtension.class)
class MinIoStorageArtifactStorageManagerTest {
@@ -78,7 +91,7 @@ class MinIoStorageArtifactStorageManagerTest {
}
@Test
- void testUpload() throws Exception {
+ void testUploadOK() throws Exception {
when(builderBucketExistsArgs
.bucket(anyString())
@@ -95,7 +108,23 @@ class MinIoStorageArtifactStorageManagerTest {
}
@Test
- void testPersist() {
+ void testUploadFail() throws Exception {
+
+ when(builderBucketExistsArgs
+ .bucket(anyString())
+ .build()
+ ).thenReturn(new BucketExistsArgs());
+ when(minioClient.bucketExists(any(BucketExistsArgs.class))).thenReturn(false);
+
+ final Attachment attachment = mockAttachment();
+ doThrow(new RuntimeException()).when(minioClient).makeBucket(any(MakeBucketArgs.class));
+ assertThrows(ArtifactStorageException.class, () -> {
+ testSubject.upload(VSP_ID, VERSION_ID, attachment.getDataHandler().getInputStream());
+ });
+ }
+
+ @Test
+ void testPersistOK() {
final ArtifactInfo result = testSubject.persist(VSP_ID, VERSION_ID, new MinIoArtifactInfo(VSP_ID, VERSION_ID));
Assertions.assertNotNull(result);
Assertions.assertTrue(result instanceof MinIoArtifactInfo);
@@ -104,10 +133,51 @@ class MinIoStorageArtifactStorageManagerTest {
}
@Test
+ void testPersistFail() throws Exception {
+ doThrow(new RuntimeException()).when(minioClient).statObject(any(StatObjectArgs.class));
+ assertThrows(ArtifactStorageException.class, () -> {
+ testSubject.persist(VSP_ID, VERSION_ID, new MinIoArtifactInfo(VSP_ID, VERSION_ID));
+ });
+ }
+
+ @Test
void testIsEnabled() {
Assertions.assertTrue(testSubject.isEnabled());
}
+ @Test
+ void testDeleteVersionFail() throws Exception {
+ doThrow(new RuntimeException()).when(minioClient).removeObject(any(RemoveObjectArgs.class));
+ assertThrows(ArtifactStorageException.class, () -> {
+ testSubject.delete(new MinIoArtifactInfo(VSP_ID, VERSION_ID));
+ });
+ }
+
+ @Test
+ void testDeleteVspFail() throws Exception {
+ doThrow(new RuntimeException()).when(minioClient).removeBucket(any(RemoveBucketArgs.class));
+ assertThrows(ArtifactStorageException.class, () -> {
+ testSubject.delete(VSP_ID);
+ });
+ }
+
+ @Test
+ void testGetOK() throws Exception {
+ when(minioClient.getObject(any(GetObjectArgs.class))).thenReturn(
+ new GetObjectResponse(Headers.of(), "", "", "",
+ new FileInputStream(Path.of("src/test/resources/s3StoreArtifactStorageManager/dummy.csar").toFile())));
+ final InputStream inputStream = testSubject.get(new MinIoArtifactInfo(VSP_ID, VERSION_ID));
+ assertNotNull(inputStream);
+ }
+
+ @Test
+ void testGetFail() throws Exception {
+ doThrow(new RuntimeException()).when(minioClient).getObject(any(GetObjectArgs.class));
+ assertThrows(ArtifactStorageException.class, () -> {
+ final InputStream inputStream = testSubject.get(new MinIoArtifactInfo(VSP_ID, VERSION_ID));
+ });
+ }
+
private Attachment mockAttachment() throws IOException {
final Attachment attachment = Mockito.mock(Attachment.class);
final DataHandler dataHandler = Mockito.mock(DataHandler.class);