Search in sources :

Example 21 with UploadSingleInitiationResponse

use of org.finra.herd.model.api.xml.UploadSingleInitiationResponse in project herd by FINRAOS.

the class UploadDownloadServiceTest method testInitiateDownloadSingleMultipleStorageFilesExist.

@Test
public void testInitiateDownloadSingleMultipleStorageFilesExist() {
    // Create the upload data.
    UploadSingleInitiationResponse uploadSingleInitiationResponse = uploadDownloadServiceTestHelper.createUploadedFileData(BusinessObjectDataStatusEntity.VALID);
    // Get the target business object data entity.
    BusinessObjectDataEntity targetBusinessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(businessObjectDataHelper.getBusinessObjectDataKey(uploadSingleInitiationResponse.getTargetBusinessObjectData()));
    // Get the target bushiness object data storage unit.
    StorageUnitEntity targetStorageUnitEntity = IterableUtils.get(targetBusinessObjectDataEntity.getStorageUnits(), 0);
    // Add a second storage file to the target business object data storage unit.
    storageFileDaoTestHelper.createStorageFileEntity(targetStorageUnitEntity, FILE_NAME_2, FILE_SIZE_1_KB, ROW_COUNT_1000);
    // Try to initiate a single file download when business object data has more than one storage file.
    try {
        // Initiate the download against the uploaded data (i.e. the target business object data).
        initiateDownload(uploadSingleInitiationResponse.getTargetBusinessObjectData());
        fail("Suppose to throw an IllegalArgumentException when business object has more than one storage file.");
    } catch (IllegalArgumentException e) {
        BusinessObjectData businessObjectData = uploadSingleInitiationResponse.getTargetBusinessObjectData();
        assertEquals(String.format("Found 2 registered storage files when expecting one in \"%s\" storage for the business object data {%s}.", targetStorageUnitEntity.getStorage().getName(), businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectData))), e.getMessage());
    }
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) Test(org.junit.Test)

Example 22 with UploadSingleInitiationResponse

use of org.finra.herd.model.api.xml.UploadSingleInitiationResponse in project herd by FINRAOS.

the class UploadDownloadServiceTest method testInitiateDownloadSingleBusinessObjectDataStatusNotValid.

@Test
public void testInitiateDownloadSingleBusinessObjectDataStatusNotValid() {
    // Create the upload data, but leave the target business object data in a "RE-ENCRYPTING" status.
    UploadSingleInitiationResponse uploadSingleInitiationResponse = uploadDownloadServiceTestHelper.createUploadedFileData(BusinessObjectDataStatusEntity.RE_ENCRYPTING);
    // Try to initiate a single file download when the business object data is not set to "VALID" which is invalid.
    try {
        // Initiate the download against the uploaded data (i.e. the target business object data).
        initiateDownload(uploadSingleInitiationResponse.getTargetBusinessObjectData());
        fail("Suppose to throw an IllegalArgumentException when business object data is not in VALID status.");
    } catch (IllegalArgumentException e) {
        BusinessObjectData businessObjectData = uploadSingleInitiationResponse.getTargetBusinessObjectData();
        assertEquals(String.format("Business object data status \"%s\" does not match the expected status \"%s\" for the business object data {%s}.", uploadSingleInitiationResponse.getTargetBusinessObjectData().getStatus(), BusinessObjectDataStatusEntity.VALID, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectData.getNamespace(), businessObjectData.getBusinessObjectDefinitionName(), businessObjectData.getBusinessObjectFormatUsage(), businessObjectData.getBusinessObjectFormatFileType(), businessObjectData.getBusinessObjectFormatVersion(), businessObjectData.getPartitionValue(), businessObjectData.getSubPartitionValues(), businessObjectData.getVersion())), e.getMessage());
    }
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) Test(org.junit.Test)

Example 23 with UploadSingleInitiationResponse

use of org.finra.herd.model.api.xml.UploadSingleInitiationResponse in project herd by FINRAOS.

the class UploadDownloadServiceTestHelper method createUploadedFileData.

/**
 * Creates the appropriate business object data entries for an upload.
 *
 * @param businessObjectDataStatusCode the target business object data status.
 *
 * @return the upload single initiation response created during the upload flow.
 */
public UploadSingleInitiationResponse createUploadedFileData(String businessObjectDataStatusCode) {
    loggingHelper.setLogLevel(UploadDownloadHelperServiceImpl.class, LogLevel.OFF);
    // Create source and target business object formats database entities which are required to initiate an upload.
    createDatabaseEntitiesForUploadDownloadTesting();
    // Initiate a file upload.
    UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(createUploadSingleInitiationRequest());
    // Complete the upload.
    uploadDownloadService.performCompleteUploadSingleMessage(resultUploadSingleInitiationResponse.getSourceBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath());
    // Update the target business object data status to valid. Normally this would happen as part of the completion request, but since the status update
    // happens asynchronously, this will not happen within a unit test context which is why we are setting it explicitly.
    businessObjectDataDao.getBusinessObjectDataByAltKey(businessObjectDataHelper.getBusinessObjectDataKey(resultUploadSingleInitiationResponse.getTargetBusinessObjectData())).setStatus(businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(businessObjectDataStatusCode));
    resultUploadSingleInitiationResponse.getTargetBusinessObjectData().setStatus(businessObjectDataStatusCode);
    // Return the initiate upload single response.
    return resultUploadSingleInitiationResponse;
}
Also used : UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse)

Aggregations

UploadSingleInitiationResponse (org.finra.herd.model.api.xml.UploadSingleInitiationResponse)23 Test (org.junit.Test)20 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)7 UploadDownloadServiceImpl (org.finra.herd.service.impl.UploadDownloadServiceImpl)4 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)3 UploadSingleInitiationRequest (org.finra.herd.model.api.xml.UploadSingleInitiationRequest)3 S3EventNotification (com.amazonaws.services.s3.event.S3EventNotification)2 S3Entity (com.amazonaws.services.s3.event.S3EventNotification.S3Entity)2 S3EventNotificationRecord (com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord)2 S3ObjectEntity (com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity)2 ArrayList (java.util.ArrayList)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 BusinessObjectDataStatusUpdateRequest (org.finra.herd.model.api.xml.BusinessObjectDataStatusUpdateRequest)2 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)2 StorageEntity (org.finra.herd.model.jpa.StorageEntity)2 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)2 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 Credentials (com.amazonaws.services.securitytoken.model.Credentials)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1