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());
}
}
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());
}
}
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;
}
Aggregations