Search in sources :

Example 81 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class UploadDownloadHelperServiceTest method testDeleteSourceFileFromS3Fails.

@Test
public void testDeleteSourceFileFromS3Fails() throws Exception {
    // Create and persists entities required for testing.
    // Create source and target business object data entities.
    BusinessObjectDataEntity sourceBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
    BusinessObjectDataEntity targetBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
    // Put a 1 KB file in S3.
    s3Operations.putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[(int) FILE_SIZE_1_KB]), null), null);
    // Make the S3 delete fail by a null aws Params
    CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity), EMPTY_S3_BUCKET_NAME, MockS3OperationsImpl.MOCK_S3_FILE_NAME_SERVICE_EXCEPTION, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity), EMPTY_S3_BUCKET_NAME, MockS3OperationsImpl.MOCK_S3_FILE_NAME_SERVICE_EXCEPTION, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, MockS3OperationsImpl.MOCK_KMS_ID, null);
    // Try to delete the source file from S3
    executeWithoutLogging(UploadDownloadHelperServiceImpl.class, () -> {
        uploadDownloadHelperService.deleteSourceFileFromS3(completeUploadSingleParamsDto);
    });
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) CompleteUploadSingleParamsDto(org.finra.herd.model.dto.CompleteUploadSingleParamsDto) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 82 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class UploadDownloadHelperServiceTest method testPrepareForFileMoveTargetStatusNotUploading.

@Test
public void testPrepareForFileMoveTargetStatusNotUploading() throws Exception {
    // Create and persists entities required for testing with the target business object data not having "UPLOADING" status.
    BusinessObjectDataEntity sourceBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.UPLOADING);
    StorageUnitEntity sourceStorageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE), sourceBusinessObjectDataEntity, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    storageFileDaoTestHelper.createStorageFileEntity(sourceStorageUnitEntity, FILE_NAME, FILE_SIZE_1_KB, NO_ROW_COUNT);
    BusinessObjectDataEntity targetBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID);
    StorageUnitEntity targetStorageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_EXTERNAL_STORAGE), targetBusinessObjectDataEntity, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    storageFileDaoTestHelper.createStorageFileEntity(targetStorageUnitEntity, FILE_NAME, FILE_SIZE_1_KB, NO_ROW_COUNT);
    // Create an uninitialized DTO to hold parameters required to perform a complete upload single message processing.
    CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto();
    // Try to execute the prepare for the file move operation when the target business object data does not have "UPLOADING" status.
    executeWithoutLogging(UploadDownloadHelperServiceImpl.class, () -> {
        uploadDownloadHelperService.prepareForFileMove(FILE_NAME, completeUploadSingleParamsDto);
    });
    // Refresh the data entities.
    sourceBusinessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity));
    targetBusinessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity));
    // Validate the source and target business object data statuses.
    assertEquals(BusinessObjectDataStatusEntity.UPLOADING, sourceBusinessObjectDataEntity.getStatus().getCode());
    assertEquals(BusinessObjectDataStatusEntity.VALID, targetBusinessObjectDataEntity.getStatus().getCode());
    // Validate the updated DTO parameters.
    assertNull(completeUploadSingleParamsDto.getSourceNewStatus());
    assertEquals(BusinessObjectDataStatusEntity.UPLOADING, completeUploadSingleParamsDto.getSourceOldStatus());
    assertNull(completeUploadSingleParamsDto.getTargetNewStatus());
    assertEquals(BusinessObjectDataStatusEntity.VALID, completeUploadSingleParamsDto.getTargetOldStatus());
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) CompleteUploadSingleParamsDto(org.finra.herd.model.dto.CompleteUploadSingleParamsDto) Test(org.junit.Test)

Example 83 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class UploadDownloadHelperServiceTest method testPerformFileMove.

@Test
public void testPerformFileMove() {
    // Create source and target business object data entities.
    BusinessObjectDataEntity sourceBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
    BusinessObjectDataEntity targetBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
    // Put a 1 KB file in S3.
    s3Operations.putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[(int) FILE_SIZE_1_KB]), null), null);
    // Initialize parameters required to perform a file move.
    CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity), storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity), storageDaoTestHelper.getS3ExternalBucketName(), TARGET_S3_KEY, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, MockS3OperationsImpl.MOCK_KMS_ID, emrHelper.getAwsParamsDto());
    // Perform the file move.
    uploadDownloadHelperService.performFileMove(completeUploadSingleParamsDto);
    // Refresh the data entities.
    sourceBusinessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity));
    targetBusinessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity));
    // Validate the source business object data status.
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, sourceBusinessObjectDataEntity.getStatus().getCode());
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, completeUploadSingleParamsDto.getSourceNewStatus());
    assertEquals(BusinessObjectDataStatusEntity.UPLOADING, completeUploadSingleParamsDto.getSourceOldStatus());
    // Validate the target business object data status.
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, targetBusinessObjectDataEntity.getStatus().getCode());
    assertEquals(BusinessObjectDataStatusEntity.VALID, completeUploadSingleParamsDto.getTargetNewStatus());
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, completeUploadSingleParamsDto.getTargetOldStatus());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) CompleteUploadSingleParamsDto(org.finra.herd.model.dto.CompleteUploadSingleParamsDto) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 84 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class UploadDownloadHelperServiceTest method testPrepareForFileMove.

@Test
public void testPrepareForFileMove() {
    // Create and persists entities required for testing.
    BusinessObjectDataEntity sourceBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.UPLOADING);
    StorageUnitEntity sourceStorageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE), sourceBusinessObjectDataEntity, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    storageFileDaoTestHelper.createStorageFileEntity(sourceStorageUnitEntity, TARGET_S3_KEY, FILE_SIZE_1_KB, NO_ROW_COUNT);
    BusinessObjectDataEntity targetBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.UPLOADING);
    StorageUnitEntity targetStorageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_EXTERNAL_STORAGE), targetBusinessObjectDataEntity, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    storageFileDaoTestHelper.createStorageFileEntity(targetStorageUnitEntity, TARGET_S3_KEY, FILE_SIZE_1_KB, NO_ROW_COUNT);
    // Put a 1 KB file in S3.
    PutObjectRequest putObjectRequest = new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[(int) FILE_SIZE_1_KB]), null);
    s3Operations.putObject(putObjectRequest, null);
    // Create an uninitialized DTO to hold parameters required to perform a complete upload single message processing.
    CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto();
    // Prepare for the file move operation.
    uploadDownloadHelperService.prepareForFileMove(TARGET_S3_KEY, completeUploadSingleParamsDto);
    // Refresh the data entities.
    sourceBusinessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity));
    targetBusinessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity));
    // Validate the source and target business object data statuses.
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, sourceBusinessObjectDataEntity.getStatus().getCode());
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, targetBusinessObjectDataEntity.getStatus().getCode());
    // Validate the updated DTO parameters.
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, completeUploadSingleParamsDto.getSourceNewStatus());
    assertEquals(BusinessObjectDataStatusEntity.UPLOADING, completeUploadSingleParamsDto.getSourceOldStatus());
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, completeUploadSingleParamsDto.getTargetNewStatus());
    assertEquals(BusinessObjectDataStatusEntity.UPLOADING, completeUploadSingleParamsDto.getTargetOldStatus());
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) CompleteUploadSingleParamsDto(org.finra.herd.model.dto.CompleteUploadSingleParamsDto) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 85 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class UploadDownloadHelperServiceTest method testPerformFileMoveS3CopyFails.

@Test
public void testPerformFileMoveS3CopyFails() throws Exception {
    // Create source and target business object data entities.
    BusinessObjectDataEntity sourceBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
    BusinessObjectDataEntity targetBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
    // Initialize parameters required to perform a file move.
    // Make the S3 copy operation fail by passing a special mocked file name.
    CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity), EMPTY_S3_BUCKET_NAME, MockS3OperationsImpl.MOCK_S3_FILE_NAME_SERVICE_EXCEPTION, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity), EMPTY_S3_BUCKET_NAME, MockS3OperationsImpl.MOCK_S3_FILE_NAME_SERVICE_EXCEPTION, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, MockS3OperationsImpl.MOCK_KMS_ID, emrHelper.getAwsParamsDto());
    // Try to perform the file move.
    executeWithoutLogging(UploadDownloadHelperServiceImpl.class, () -> {
        uploadDownloadHelperService.performFileMove(completeUploadSingleParamsDto);
    });
    // Refresh the data entities
    sourceBusinessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity));
    targetBusinessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity));
    // Validate the source business object data status.
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, sourceBusinessObjectDataEntity.getStatus().getCode());
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, completeUploadSingleParamsDto.getSourceNewStatus());
    assertEquals(BusinessObjectDataStatusEntity.UPLOADING, completeUploadSingleParamsDto.getSourceOldStatus());
    // Validate the target business object data status.
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, targetBusinessObjectDataEntity.getStatus().getCode());
    assertEquals(BusinessObjectDataStatusEntity.INVALID, completeUploadSingleParamsDto.getTargetNewStatus());
    assertEquals(BusinessObjectDataStatusEntity.RE_ENCRYPTING, completeUploadSingleParamsDto.getTargetOldStatus());
}
Also used : BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) CompleteUploadSingleParamsDto(org.finra.herd.model.dto.CompleteUploadSingleParamsDto) Test(org.junit.Test)

Aggregations

BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)278 Test (org.junit.Test)184 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)138 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)105 ArrayList (java.util.ArrayList)70 StorageEntity (org.finra.herd.model.jpa.StorageEntity)67 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)63 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)57 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)54 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)31 Attribute (org.finra.herd.model.api.xml.Attribute)28 NotificationMessageDefinition (org.finra.herd.model.api.xml.NotificationMessageDefinition)27 NotificationMessageDefinitions (org.finra.herd.model.api.xml.NotificationMessageDefinitions)27 ConfigurationEntity (org.finra.herd.model.jpa.ConfigurationEntity)27 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)25 Predicate (javax.persistence.criteria.Predicate)24 NotificationMessage (org.finra.herd.model.dto.NotificationMessage)24 BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)23 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)21 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)19