import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.vspUploadAlreadyInProgress;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
+import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.openecomp.sdc.be.csar.storage.MinIoStorageArtifactStorageConfig.EndPoint;
import org.openecomp.sdc.be.csar.storage.PackageSizeReducer;
import org.openecomp.sdc.be.csar.storage.StorageFactory;
+import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
void uploadSignedTest() throws IOException {
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());
+ when(orchestrationTemplateCandidateUploadManager.findLatestStatus(vspId, versionId, user)).thenReturn(Optional.empty());
+ final UUID lockId = UUID.randomUUID();
+ when(orchestrationTemplateCandidateUploadManager.putUploadInProgress(vspId, versionId, user))
+ .thenReturn(createVspUploadStatus(lockId, VspUploadStatus.UPLOADING));
+ when(orchestrationTemplateCandidateUploadManager.putUploadInValidation(vspId, versionId, user))
+ .thenReturn(createVspUploadStatus(lockId, VspUploadStatus.VALIDATING));
+ when(orchestrationTemplateCandidateUploadManager.putUploadInProcessing(vspId, versionId, user))
+ .thenReturn(createVspUploadStatus(lockId, VspUploadStatus.PROCESSING));
Response response = orchestrationTemplateCandidate
.upload(vspId, versionId, mockAttachment("filename.zip", this.getClass().getResource("/files/sample-signed.zip")), user);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
void uploadNotSignedTest() throws IOException {
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());
+ when(orchestrationTemplateCandidateUploadManager.findLatestStatus(vspId, versionId, user)).thenReturn(Optional.empty());
+ final UUID lockId = UUID.randomUUID();
+ when(orchestrationTemplateCandidateUploadManager.putUploadInProgress(vspId, versionId, user))
+ .thenReturn(createVspUploadStatus(lockId, VspUploadStatus.UPLOADING));
+ when(orchestrationTemplateCandidateUploadManager.putUploadInValidation(vspId, versionId, user))
+ .thenReturn(createVspUploadStatus(lockId, VspUploadStatus.VALIDATING));
+ when(orchestrationTemplateCandidateUploadManager.putUploadInProcessing(vspId, versionId, user))
+ .thenReturn(createVspUploadStatus(lockId, VspUploadStatus.PROCESSING));
Response response = orchestrationTemplateCandidate.upload(vspId, versionId,
mockAttachment("filename.csar", this.getClass().getResource("/files/sample-not-signed.csar")), user);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
assertTrue(((UploadFileResponseDto) response.getEntity()).getErrors().isEmpty());
}
+ @NotNull
+ private VspUploadStatusDto createVspUploadStatus(final UUID lockId, final VspUploadStatus uploadStatus) {
+ final VspUploadStatusDto vspUploadStatusProcessing = new VspUploadStatusDto();
+ vspUploadStatusProcessing.setLockId(lockId);
+ vspUploadStatusProcessing.setStatus(uploadStatus);
+ return vspUploadStatusProcessing;
+ }
+
@Test
void uploadNotSignedArtifactStorageManagerIsEnabledTest() throws IOException {
when(storageFactory.createArtifactStorageManager()).thenReturn(artifactStorageManager);
final byte[] bytes = Files.readAllBytes(path);
when(packageSizeReducer.reduce(any())).thenReturn(bytes);
- when(orchestrationTemplateCandidateUploadManager.putUploadInProgress(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
+ final VspUploadStatusDto vspUploadStatusDto = new VspUploadStatusDto();
+ vspUploadStatusDto.setStatus(VspUploadStatus.UPLOADING);
+ when(orchestrationTemplateCandidateUploadManager.findLatestStatus(vspId, versionId, user)).thenReturn(Optional.of(vspUploadStatusDto));
when(orchestrationTemplateCandidateUploadManager.putUploadInValidation(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
when(orchestrationTemplateCandidateUploadManager.putUploadInProcessing(vspId, versionId, user)).thenReturn(new VspUploadStatusDto());
@Test
void uploadSignNotValidTest() throws IOException {
//given
+ final VspUploadStatusDto vspUploadStatusDto = new VspUploadStatusDto();
+ vspUploadStatusDto.setStatus(VspUploadStatus.UPLOADING);
+ when(orchestrationTemplateCandidateUploadManager.findLatestStatus(candidateId, versionId, user))
+ .thenReturn(Optional.of(vspUploadStatusDto));
when(orchestrationTemplateCandidateUploadManager.putUploadInValidation(candidateId, versionId, user)).thenReturn(new VspUploadStatusDto());
//when
Response response = orchestrationTemplateCandidate
@Test
void finishUploadMustBeCalledWhenExceptionHappensTest() {
//given
- final VspUploadStatusDto vspUploadStatusDto = new VspUploadStatusDto();
- vspUploadStatusDto.setLockId(UUID.randomUUID());
+ final VspUploadStatusDto vspUploadStatusDto = createVspUploadStatus(UUID.randomUUID(), VspUploadStatus.UPLOADING);
+ when(orchestrationTemplateCandidateUploadManager.findLatestStatus(candidateId, versionId, user)).thenReturn(Optional.empty());
when(orchestrationTemplateCandidateUploadManager.putUploadInProgress(candidateId, versionId, user)).thenReturn(vspUploadStatusDto);
final RuntimeException forcedException = new RuntimeException();
when(fileToUpload.getDataHandler()).thenThrow(forcedException);
verify(orchestrationTemplateCandidateUploadManager)
.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();
+ vspUploadStatusDto.setComplete(false);
+ vspUploadStatusDto.setStatus(VspUploadStatus.PROCESSING);
+ //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 = vspUploadAlreadyInProgress(candidateId, versionId).get();
+ //then
+ assertEquals(expectedException.code().id(), actualException.code().id());
+ assertEquals(expectedException.code().message(), actualException.code().message());
+ verify(orchestrationTemplateCandidateUploadManager).findLatestStatus(candidateId, versionId, user);
+ }
+
}
import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
import VNFImportActionHelper from '../vnfMarketPlace/VNFImportActionHelper.js';
+import VspUploadStatus from 'sdc-app/onboarding/softwareProduct/landingPage/VspUploadStatus';
export const mapStateToProps = ({
features,
// do nothing by default
}
) => {
- SoftwareProductActionHelper.uploadFile(dispatch, {
+ SoftwareProductActionHelper.createUploadStatus(
softwareProductId,
- formData,
- failedNotificationTitle: i18n('Upload validation failed'),
- version,
- onUploadProgress
- }).finally(() => {
- onUploadFinished();
- });
- onUploadStart();
+ version.id
+ )
+ .then(response => {
+ const vspUploadStatus = new VspUploadStatus(response);
+ onUploadStart(vspUploadStatus);
+ SoftwareProductActionHelper.uploadFile(dispatch, {
+ softwareProductId,
+ formData,
+ failedNotificationTitle: i18n(
+ 'Upload validation failed'
+ ),
+ version,
+ onUploadProgress
+ }).finally(() => {
+ onUploadFinished();
+ });
+ })
+ .catch(error => {
+ dispatch({
+ type: modalActionTypes.GLOBAL_MODAL_ERROR,
+ data: {
+ title: i18n('upload.failed'),
+ msg: error.message
+ }
+ });
+ });
},
onUploadConfirmation: (
confirmationButtonText: i18n('Continue'),
title: i18n('Warning'),
onConfirmed: () => {
- SoftwareProductActionHelper.uploadFile(dispatch, {
+ SoftwareProductActionHelper.createUploadStatus(
softwareProductId,
- formData,
- failedNotificationTitle: i18n(
- 'Upload validation failed'
- ),
- version,
- onUploadProgress
- }).finally(value => {
- console.log('upload finished', value);
- onUploadFinished();
- });
- onUploadStart();
+ version.id
+ )
+ .then(response => {
+ const vspUploadStatus = new VspUploadStatus(
+ response
+ );
+ onUploadStart(vspUploadStatus);
+ SoftwareProductActionHelper.uploadFile(
+ dispatch,
+ {
+ softwareProductId,
+ formData,
+ failedNotificationTitle: i18n(
+ 'Upload validation failed'
+ ),
+ version,
+ onUploadProgress
+ }
+ ).finally(() => {
+ onUploadFinished();
+ });
+ })
+ .catch(error => {
+ dispatch({
+ type: modalActionTypes.GLOBAL_MODAL_ERROR,
+ data: {
+ title: i18n('upload.failed'),
+ msg: error.message
+ }
+ });
+ });
},
onDeclined: () =>
dispatch({