Search in sources :

Example 16 with UploadSingleInitiationResponse

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

the class UploadDownloadServiceTest method testInitiateUploadSingleMissingOptionalParameters.

@Test
public void testInitiateUploadSingleMissingOptionalParameters() {
    // Create database entities required for testing.
    uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
    // Initiate a file upload without specifying any of the optional parameters.
    UploadSingleInitiationRequest request = uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest();
    request.setBusinessObjectDataAttributes(null);
    request.getFile().setFileSizeBytes(null);
    UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(request);
    // Validate the returned object.
    uploadDownloadServiceTestHelper.validateUploadSingleInitiationResponse(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, NO_ATTRIBUTES, FILE_NAME, null, null, resultUploadSingleInitiationResponse);
}
Also used : UploadSingleInitiationRequest(org.finra.herd.model.api.xml.UploadSingleInitiationRequest) UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) Test(org.junit.Test)

Example 17 with UploadSingleInitiationResponse

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

the class UploadDownloadServiceTest method testPerformCompleteUploadSingleMessageSourceBusinessObjectDataStatusNotUploading.

@Test
public void testPerformCompleteUploadSingleMessageSourceBusinessObjectDataStatusNotUploading() {
    uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
    UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, FILE_NAME));
    String filePath = resultUploadSingleInitiationResponse.getTargetBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath();
    // Create a business object data status.
    businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS);
    // Update the status of the source business object data so it would not be "UPLOADING".
    businessObjectDataStatusService.updateBusinessObjectDataStatus(businessObjectDataHelper.getBusinessObjectDataKey(resultUploadSingleInitiationResponse.getSourceBusinessObjectData()), new BusinessObjectDataStatusUpdateRequest(BDATA_STATUS));
    // Try to complete the upload, when source business object data status is not "UPLOADING".
    UploadDownloadServiceImpl.CompleteUploadSingleMessageResult result = uploadDownloadService.performCompleteUploadSingleMessage(filePath);
    assertEquals(BDATA_STATUS, result.getSourceOldBusinessObjectDataStatus());
    assertNull(result.getSourceNewBusinessObjectDataStatus());
    assertEquals(BusinessObjectDataStatusEntity.UPLOADING, result.getTargetOldBusinessObjectDataStatus());
    assertNull(result.getTargetNewBusinessObjectDataStatus());
}
Also used : UploadDownloadServiceImpl(org.finra.herd.service.impl.UploadDownloadServiceImpl) UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) BusinessObjectDataStatusUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStatusUpdateRequest) Test(org.junit.Test)

Example 18 with UploadSingleInitiationResponse

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

the class UploadDownloadServiceTest method testInitiateUploadSingleTrimParameters.

@Test
public void testInitiateUploadSingleTrimParameters() {
    // Create database entities required for testing.
    uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
    // Initiate a file upload using input parameters with leading and trailing empty spaces.
    UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest(addWhitespace(NAMESPACE), addWhitespace(BDEF_NAME), addWhitespace(FORMAT_USAGE_CODE), addWhitespace(FORMAT_FILE_TYPE_CODE), FORMAT_VERSION, addWhitespace(NAMESPACE), addWhitespace(BDEF_NAME_2), addWhitespace(FORMAT_USAGE_CODE_2), addWhitespace(FORMAT_FILE_TYPE_CODE_2), FORMAT_VERSION_2));
    // Validate the returned object.
    uploadDownloadServiceTestHelper.validateUploadSingleInitiationResponse(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes(), FILE_NAME, FILE_SIZE_1_KB, null, resultUploadSingleInitiationResponse);
}
Also used : UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) Test(org.junit.Test)

Example 19 with UploadSingleInitiationResponse

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

the class UploadDownloadServiceTest method testPerformCompleteUploadSingleMessageTargetBusinessObjectDataStatusNotUploading.

@Test
public void testPerformCompleteUploadSingleMessageTargetBusinessObjectDataStatusNotUploading() {
    uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
    UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, FILE_NAME));
    String filePath = resultUploadSingleInitiationResponse.getTargetBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath();
    // Create a business object data status.
    businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS);
    // Update the status of the target business object data so it would not be "UPLOADING".
    businessObjectDataStatusService.updateBusinessObjectDataStatus(businessObjectDataHelper.getBusinessObjectDataKey(resultUploadSingleInitiationResponse.getTargetBusinessObjectData()), new BusinessObjectDataStatusUpdateRequest(BDATA_STATUS));
    // Try to complete the upload, when target business object data status is not "UPLOADING".
    UploadDownloadServiceImpl.CompleteUploadSingleMessageResult result = uploadDownloadService.performCompleteUploadSingleMessage(filePath);
    assertEquals(BusinessObjectDataStatusEntity.UPLOADING, result.getSourceOldBusinessObjectDataStatus());
    assertNull(result.getSourceNewBusinessObjectDataStatus());
    assertEquals(BDATA_STATUS, result.getTargetOldBusinessObjectDataStatus());
    assertNull(result.getTargetNewBusinessObjectDataStatus());
}
Also used : UploadDownloadServiceImpl(org.finra.herd.service.impl.UploadDownloadServiceImpl) UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) BusinessObjectDataStatusUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStatusUpdateRequest) Test(org.junit.Test)

Example 20 with UploadSingleInitiationResponse

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

the class UploadDownloadServiceTest method testExtendUploadSingleCredentialsBusinessObjectDataStatusNotValid.

@Test
public void testExtendUploadSingleCredentialsBusinessObjectDataStatusNotValid() {
    // Create the upload data. This internally calls "complete" which sets the source business object data's status to "DELETED".
    // This is a status where credentials can't be extended (i.e. only UPLOADING statuses).
    UploadSingleInitiationResponse uploadSingleInitiationResponse = uploadDownloadServiceTestHelper.createUploadedFileData(BusinessObjectDataStatusEntity.VALID);
    // Try to extend the upload credentials of a source business object data with an invalid status of "DELETED".
    try {
        extendUploadSingleCredentials(uploadSingleInitiationResponse.getSourceBusinessObjectData());
        fail("Suppose to throw an IllegalArgumentException when business object data is not in VALID status.");
    } catch (IllegalArgumentException e) {
        BusinessObjectData businessObjectData = uploadSingleInitiationResponse.getSourceBusinessObjectData();
        assertEquals(String.format("Business object data {%s} has a status of \"%s\" and must be \"%s\" to extend credentials.", businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectData.getNamespace(), businessObjectData.getBusinessObjectDefinitionName(), businessObjectData.getBusinessObjectFormatUsage(), businessObjectData.getBusinessObjectFormatFileType(), businessObjectData.getBusinessObjectFormatVersion(), businessObjectData.getPartitionValue(), NO_SUBPARTITION_VALUES, businessObjectData.getVersion()), BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.UPLOADING), e.getMessage());
    }
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) Test(org.junit.Test)

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