UploadDownloadHelperServiceImpl implements UploadDownloadHelperService { @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public void prepareForFileMove(String objectKey, CompleteUploadSingleParamsDto completeUploadSingleParamsDto) { prepareForFileMoveImpl(objectKey, completeUploadSingleParamsDto); }  @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void prepareForFileMove(String objectKey, CompleteUploadSingleParamsDto completeUploadSingleParamsDto); @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) void performFileMove(CompleteUploadSingleParamsDto completeUploadSingleParamsDto); @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void executeFileMoveAfterSteps(CompleteUploadSingleParamsDto completeUploadSingleParamsDto); void executeFileMoveAfterStepsImpl(CompleteUploadSingleParamsDto completeUploadSingleParamsDto); @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) void deleteSourceFileFromS3(CompleteUploadSingleParamsDto completeUploadSingleParamsDto); @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void updateBusinessObjectDataStatus(BusinessObjectDataKey businessObjectDataKey, String businessObjectDataStatus); @Override void assertS3ObjectKeyDoesNotExist(String bucketName, String key);  }
@Test public void testPrepareForFileMove() { String objectKey = UUID_VALUE; CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto(); BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity(); businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.UPLOADING); StorageEntity sourceStorageEntity = new StorageEntity(); BusinessObjectDataKey sourceBusinessObjectDataKey = new BusinessObjectDataKey(); sourceBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE); BusinessObjectDataEntity sourceBusinessObjectDataEntity = new BusinessObjectDataEntity(); sourceBusinessObjectDataEntity.setId(ID); sourceBusinessObjectDataEntity.setPartitionValue(objectKey); sourceBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity); List<StorageFileEntity> sourceStorageFileEntities = new ArrayList<>(); StorageUnitEntity sourceStorageUnitEntity = new StorageUnitEntity(); sourceStorageUnitEntity.setBusinessObjectData(sourceBusinessObjectDataEntity); sourceStorageUnitEntity.setStorage(sourceStorageEntity); sourceStorageUnitEntity.setStorageFiles(sourceStorageFileEntities); StorageFileEntity sourceStorageFileEntity = new StorageFileEntity(); sourceStorageFileEntities.add(sourceStorageFileEntity); sourceStorageFileEntity.setStorageUnit(sourceStorageUnitEntity); sourceStorageFileEntity.setPath(S3_KEY); sourceStorageFileEntity.setFileSizeBytes(FILE_SIZE); StorageEntity targetStorageEntity = new StorageEntity(); BusinessObjectDataKey targetBusinessObjectDataKey = new BusinessObjectDataKey(); targetBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE_2); List<StorageFileEntity> targetStorageFileEntities = new ArrayList<>(); StorageUnitEntity targetStorageUnitEntity = new StorageUnitEntity(); targetStorageUnitEntity.setStorage(targetStorageEntity); targetStorageUnitEntity.setStorageFiles(targetStorageFileEntities); StorageFileEntity targetStorageFileEntity = new StorageFileEntity(); targetStorageFileEntities.add(targetStorageFileEntity); targetStorageFileEntity.setPath(S3_KEY_2); BusinessObjectDataEntity targetBusinessObjectDataEntity = new BusinessObjectDataEntity(); targetBusinessObjectDataEntity.setId(ID_2); targetBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity); targetBusinessObjectDataEntity.setStorageUnits(Collections.singletonList(targetStorageUnitEntity)); AwsParamsDto awsParamsDto = new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1); when(storageFileDaoHelper.getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey)).thenReturn(sourceStorageFileEntity); when(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity)).thenReturn(sourceBusinessObjectDataKey); when(businessObjectDataDao.getBusinessObjectDataEntitiesByPartitionValue(objectKey)) .thenReturn(Arrays.asList(sourceBusinessObjectDataEntity, targetBusinessObjectDataEntity)); when(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity)).thenReturn(targetBusinessObjectDataKey); when(storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE)).thenReturn(sourceStorageEntity); when(storageHelper.getStorageBucketName(sourceStorageEntity)).thenReturn(S3_BUCKET_NAME); when(storageUnitDaoHelper.getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity)) .thenReturn(sourceStorageUnitEntity); when(awsHelper.getAwsParamsDto()).thenReturn(awsParamsDto); when(storageHelper.getStorageBucketName(targetStorageEntity)).thenReturn(S3_BUCKET_NAME_2); when(storageHelper.getStorageKmsKeyId(targetStorageEntity)).thenReturn(AWS_KMS_KEY_ID); uploadDownloadHelperService.prepareForFileMoveImpl(objectKey, completeUploadSingleParamsDto); verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey); verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey); verify(businessObjectDataHelper).getBusinessObjectDataKey(sourceBusinessObjectDataEntity); verify(businessObjectDataDao).getBusinessObjectDataEntitiesByPartitionValue(objectKey); verify(businessObjectDataHelper).getBusinessObjectDataKey(targetBusinessObjectDataEntity); verify(storageDaoHelper).getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE); verify(storageHelper).getStorageBucketName(sourceStorageEntity); verify(storageUnitDaoHelper).getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity); verify(awsHelper, times(2)).getAwsParamsDto(); verify(s3Dao).validateS3File(any(S3FileTransferRequestParamsDto.class), eq(FILE_SIZE)); verify(storageHelper).getStorageBucketName(targetStorageEntity); verify(storageHelper).getStorageKmsKeyId(targetStorageEntity); verify(s3Dao).s3FileExists(any(S3FileTransferRequestParamsDto.class)); verify(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(sourceBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING); verify(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(targetBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING); verify(notificationEventService) .processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, sourceBusinessObjectDataKey, BusinessObjectDataStatusEntity.RE_ENCRYPTING, BusinessObjectDataStatusEntity.UPLOADING); verify(notificationEventService) .processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, targetBusinessObjectDataKey, BusinessObjectDataStatusEntity.RE_ENCRYPTING, BusinessObjectDataStatusEntity.UPLOADING); verifyNoMoreInteractionsHelper(); assertEquals(new CompleteUploadSingleParamsDto(sourceBusinessObjectDataKey, S3_BUCKET_NAME, S3_KEY, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, targetBusinessObjectDataKey, S3_BUCKET_NAME_2, S3_KEY_2, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, AWS_KMS_KEY_ID, awsParamsDto), completeUploadSingleParamsDto); }