aboutsummaryrefslogtreecommitdiffstats
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
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-01-18 10:16:37 +0000
committerMichael Morris <michael.morris@est.tech>2022-01-25 09:57:30 +0000
commit3ba359e291789363ce2670c72da8eaa9caa5f956 (patch)
treebc3358369990f40b7ce994ab454094fc5b062270 /openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest
parentd77bdf472a4fb5b6cf8e17f2d0d8e8d2bababeaf (diff)
Update onboarding upload status during processing
Updates the onboarding upload status during the VSP package processing Change-Id: Idc705220ad26e62577b52c6f9126aeae51a33fe0 Issue-ID: SDC-3848 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')
-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.java27
-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/OrchestrationTemplateCandidateUploadManagerImplTest.java121
2 files changed, 148 insertions, 0 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 6e0231aaf7..758505f583 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
@@ -25,10 +25,12 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
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.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
@@ -67,6 +69,7 @@ import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspUploadStatus;
import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileStatus;
@@ -152,6 +155,8 @@ class OrchestrationTemplateCandidateImplTest {
final String vspId = "vspId";
final String versionId = "versionId";
when(orchestrationTemplateCandidateUploadManager.putUploadInProgress(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
+ when(orchestrationTemplateCandidateUploadManager.putUploadInValidation(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
+ when(orchestrationTemplateCandidateUploadManager.putUploadInProcessing(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
Response response = orchestrationTemplateCandidate
.upload(vspId, versionId, mockAttachment("filename.zip", this.getClass().getResource("/files/sample-signed.zip")), user);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -163,6 +168,8 @@ class OrchestrationTemplateCandidateImplTest {
final String vspId = "vspId";
final String versionId = "versionId";
when(orchestrationTemplateCandidateUploadManager.putUploadInProgress(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
+ when(orchestrationTemplateCandidateUploadManager.putUploadInValidation(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
+ when(orchestrationTemplateCandidateUploadManager.putUploadInProcessing(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
Response response = orchestrationTemplateCandidate.upload(vspId, versionId,
mockAttachment("filename.csar", this.getClass().getResource("/files/sample-not-signed.csar")), user);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -183,6 +190,8 @@ class OrchestrationTemplateCandidateImplTest {
when(packageSizeReducer.reduce(any())).thenReturn(bytes);
when(orchestrationTemplateCandidateUploadManager.putUploadInProgress(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
+ when(orchestrationTemplateCandidateUploadManager.putUploadInValidation(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
+ when(orchestrationTemplateCandidateUploadManager.putUploadInProcessing(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
Response response = orchestrationTemplateCandidate.upload(vspId, versionId,
mockAttachment("filename.csar", this.getClass().getResource("/files/sample-not-signed.csar")), user);
@@ -296,4 +305,22 @@ class OrchestrationTemplateCandidateImplTest {
}
}
+ @Test
+ void finishUploadMustBeCalledWhenExceptionHappensTest() {
+ //given
+ final VspUploadStatusDto vspUploadStatusDto = new VspUploadStatusDto();
+ vspUploadStatusDto.setLockId(UUID.randomUUID());
+ when(orchestrationTemplateCandidateUploadManager.putUploadInProgress(candidateId, versionId, user)).thenReturn(vspUploadStatusDto);
+ final RuntimeException forcedException = new RuntimeException();
+ when(artifactStorageManager.isEnabled()).thenThrow(forcedException);
+ final Attachment mock = Mockito.mock(Attachment.class);
+ when(mock.getDataHandler()).thenReturn(Mockito.mock(DataHandler.class));
+ //when
+ final RuntimeException actualException = assertThrows(RuntimeException.class,
+ () -> orchestrationTemplateCandidate.upload(candidateId, versionId, mock, user));
+ //then
+ assertEquals(forcedException, actualException);
+ verify(orchestrationTemplateCandidateUploadManager)
+ .putUploadAsFinished(candidateId, versionId, vspUploadStatusDto.getLockId(), VspUploadStatus.ERROR, user);
+ }
}
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/OrchestrationTemplateCandidateUploadManagerImplTest.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/OrchestrationTemplateCandidateUploadManagerImplTest.java
index 9a7629f563..c156085d1b 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/OrchestrationTemplateCandidateUploadManagerImplTest.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/OrchestrationTemplateCandidateUploadManagerImplTest.java
@@ -24,13 +24,19 @@ package org.openecomp.sdcrests.vsp.rest.services;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
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.Mockito.doThrow;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.alreadyInStatusBeingUpdated;
+import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.couldNotFindStatus;
+import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.couldNotUpdateStatus;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Optional;
@@ -309,4 +315,119 @@ class OrchestrationTemplateCandidateUploadManagerImplTest {
assertEquals(expectedCoreException.code().message(), actualCoreException.code().message());
}
+ @Test
+ void startValidationSuccessTest() throws ParseException {
+ //given
+ final String vspId = "vspId";
+ final String vspVersionId = "vspVersionId";
+ final UUID lockId = UUID.randomUUID();
+ final String username = "username";
+ final Date created = new SimpleDateFormat("dd/MM/yyyy").parse("01/01/1900");
+ final Date updated = new SimpleDateFormat("dd/MM/yyyy").parse("02/01/1900");
+ final VspUploadStatusRecord vspUploadStatusRecord = new VspUploadStatusRecord();
+ vspUploadStatusRecord.setVspId(vspId);
+ vspUploadStatusRecord.setVspVersionId(vspVersionId);
+ vspUploadStatusRecord.setLockId(lockId);
+ vspUploadStatusRecord.setCreated(created);
+ vspUploadStatusRecord.setUpdated(updated);
+ vspUploadStatusRecord.setStatus(VspUploadStatus.UPLOADING);
+ when(vspUploadStatusRecordDao.findLatest(vspId, vspVersionId)).thenReturn(Optional.of(vspUploadStatusRecord));
+ //when
+ final VspUploadStatusDto vspUploadStatusDto = packageUploadManagerImpl.putUploadInValidation(vspId, vspVersionId, username);
+ //then
+ assertEquals(VspUploadStatus.VALIDATING, vspUploadStatusDto.getStatus());
+ assertNotEquals(updated, vspUploadStatusDto.getUpdated());
+ assertEquals(vspId, vspUploadStatusDto.getVspId());
+ assertEquals(vspVersionId, vspUploadStatusDto.getVspVersionId());
+ assertEquals(lockId, vspUploadStatusDto.getLockId());
+ assertEquals(created, vspUploadStatusDto.getCreated());
+ assertFalse(vspUploadStatusDto.isComplete());
+ }
+
+ @Test
+ void startProcessingSuccessTest() throws ParseException {
+ //given
+ final String vspId = "vspId";
+ final String vspVersionId = "vspVersionId";
+ final UUID lockId = UUID.randomUUID();
+ final String username = "username";
+ final Date created = new SimpleDateFormat("dd/MM/yyyy").parse("01/01/1900");
+ final Date updated = new SimpleDateFormat("dd/MM/yyyy").parse("02/01/1900");
+ final VspUploadStatusRecord vspUploadStatusRecord = new VspUploadStatusRecord();
+ vspUploadStatusRecord.setVspId(vspId);
+ vspUploadStatusRecord.setVspVersionId(vspVersionId);
+ vspUploadStatusRecord.setLockId(lockId);
+ vspUploadStatusRecord.setCreated(created);
+ vspUploadStatusRecord.setUpdated(updated);
+ vspUploadStatusRecord.setStatus(VspUploadStatus.UPLOADING);
+ when(vspUploadStatusRecordDao.findLatest(vspId, vspVersionId)).thenReturn(Optional.of(vspUploadStatusRecord));
+ //when
+ final VspUploadStatusDto vspUploadStatusDto = packageUploadManagerImpl.putUploadInProcessing(vspId, vspVersionId, username);
+ //then
+ assertEquals(VspUploadStatus.PROCESSING, vspUploadStatusDto.getStatus());
+ assertNotEquals(updated, vspUploadStatusDto.getUpdated());
+ assertEquals(vspId, vspUploadStatusDto.getVspId());
+ assertEquals(vspVersionId, vspUploadStatusDto.getVspVersionId());
+ assertEquals(lockId, vspUploadStatusDto.getLockId());
+ assertEquals(created, vspUploadStatusDto.getCreated());
+ assertFalse(vspUploadStatusDto.isComplete());
+ }
+
+
+ @Test
+ void startProcessing_statusNotFoundTest() {
+ //given
+ final String vspId = "vspId";
+ final String vspVersionId = "vspVersionId";
+ when(vspUploadStatusRecordDao.findLatest(vspId, vspVersionId)).thenReturn(Optional.empty());
+ //when/then
+ final CoreException actualCoreException = assertThrows(CoreException.class,
+ () -> packageUploadManagerImpl.putUploadInProcessing(vspId, vspVersionId, "username"));
+
+ final CoreException expectedCoreException = couldNotFindStatus(vspId, vspVersionId).get();
+ assertEquals(expectedCoreException.code().id(), actualCoreException.code().id());
+ assertEquals(expectedCoreException.getMessage(), actualCoreException.getMessage());
+ }
+
+ @Test
+ void startProcessing_alreadyInGivenStatusTest() {
+ //given
+ final String vspId = "vspId";
+ final String vspVersionId = "vspVersionId";
+ final VspUploadStatus processingStatus = VspUploadStatus.PROCESSING;
+ final VspUploadStatusRecord vspUploadStatusRecord = new VspUploadStatusRecord();
+ vspUploadStatusRecord.setStatus(processingStatus);
+ when(vspUploadStatusRecordDao.findLatest(vspId, vspVersionId)).thenReturn(Optional.of(vspUploadStatusRecord));
+
+ //when/then
+ final CoreException actualCoreException = assertThrows(CoreException.class,
+ () -> packageUploadManagerImpl.putUploadInProcessing(vspId, vspVersionId, "username"));
+
+ final CoreException expectedCoreException = alreadyInStatusBeingUpdated(vspId, vspVersionId, processingStatus).get();
+ assertEquals(expectedCoreException.code().id(), actualCoreException.code().id());
+ assertEquals(expectedCoreException.getMessage(), actualCoreException.getMessage());
+ }
+
+ @Test
+ void updateStatus_couldNotUpdateTest() {
+ //given
+ final String vspId = "vspId";
+ final String vspVersionId = "vspVersionId";
+ final VspUploadStatusRecord vspUploadStatusRecord = new VspUploadStatusRecord();
+ vspUploadStatusRecord.setVspId(vspId);
+ vspUploadStatusRecord.setVspVersionId(vspVersionId);
+ vspUploadStatusRecord.setStatus(VspUploadStatus.UPLOADING);
+ when(vspUploadStatusRecordDao.findLatest(vspId, vspVersionId)).thenReturn(Optional.of(vspUploadStatusRecord));
+ final RuntimeException exception = new RuntimeException("test");
+ doThrow(exception).when(vspUploadStatusRecordDao).update(vspUploadStatusRecord);
+
+ //when/then
+ final CoreException actualCoreException = assertThrows(CoreException.class,
+ () -> packageUploadManagerImpl.putUploadInProcessing(vspId, vspVersionId, "username"));
+
+ final CoreException expectedCoreException = couldNotUpdateStatus(vspId, vspVersionId, VspUploadStatus.PROCESSING, exception).get();
+ assertEquals(expectedCoreException.code().id(), actualCoreException.code().id());
+ assertEquals(expectedCoreException.getMessage(), actualCoreException.getMessage());
+ }
+
} \ No newline at end of file