Search in sources :

Example 6 with UploadSingleInitiationRequest

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

the class UploadDownloadServiceTest method testInitiateUploadSingleAssertTargetStorageKmsKeyIdRequired.

/**
 * Asserts that error is thrown when target storage's kms kms id is not set.
 */
@Test
public void testInitiateUploadSingleAssertTargetStorageKmsKeyIdRequired() {
    // Create database entities required for testing.
    uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
    StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME_3);
    storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucketName"));
    storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), "$environment/$namespace/$businessObjectDataPartitionValue"));
    // Initiate a file upload.
    UploadSingleInitiationRequest uploadSingleInitiationRequest = uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest();
    uploadSingleInitiationRequest.setTargetStorageName(STORAGE_NAME_3);
    try {
        uploadDownloadService.initiateUploadSingle(uploadSingleInitiationRequest);
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("Attribute \"" + configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KMS_KEY_ID) + "\" for \"" + STORAGE_NAME_3 + "\" storage must be configured.", e.getMessage());
    }
}
Also used : StorageEntity(org.finra.herd.model.jpa.StorageEntity) UploadSingleInitiationRequest(org.finra.herd.model.api.xml.UploadSingleInitiationRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Example 7 with UploadSingleInitiationRequest

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

the class UploadDownloadServiceTest method testInitiateUploadSingleAssertTargetStoragePrefixTemplateRequired.

/**
 * Asserts that error is thrown when target storage's prefix template is not set.
 */
@Test
public void testInitiateUploadSingleAssertTargetStoragePrefixTemplateRequired() {
    // Create database entities required for testing.
    uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
    StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME_3);
    storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucketName"));
    storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KMS_KEY_ID), "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012"));
    // Initiate a file upload.
    UploadSingleInitiationRequest uploadSingleInitiationRequest = uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest();
    uploadSingleInitiationRequest.setTargetStorageName(STORAGE_NAME_3);
    try {
        uploadDownloadService.initiateUploadSingle(uploadSingleInitiationRequest);
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("Storage \"" + STORAGE_NAME_3 + "\" has no S3 key prefix velocity template configured.", e.getMessage());
    }
}
Also used : StorageEntity(org.finra.herd.model.jpa.StorageEntity) UploadSingleInitiationRequest(org.finra.herd.model.api.xml.UploadSingleInitiationRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Example 8 with UploadSingleInitiationRequest

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

the class UploadDownloadServiceTest method testInitiateUploadSingleAssertUseTargetStorageInRequest.

/**
 * Asserts that the target business object data that is created is using the target storage name that is specified in the request.
 */
@Test
public void testInitiateUploadSingleAssertUseTargetStorageInRequest() {
    // Create database entities required for testing.
    uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
    StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME_3);
    storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucketName"));
    storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), "$environment/$namespace/$businessObjectDataPartitionValue"));
    storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KMS_KEY_ID), "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012"));
    // Initiate a file upload.
    UploadSingleInitiationRequest uploadSingleInitiationRequest = uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest();
    uploadSingleInitiationRequest.setTargetStorageName(STORAGE_NAME_3);
    UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadSingleInitiationRequest);
    // 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, STORAGE_NAME_3, resultUploadSingleInitiationResponse);
    BusinessObjectDataEntity targetBusinessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(new BusinessObjectDataKey(NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, resultUploadSingleInitiationResponse.getTargetBusinessObjectData().getPartitionValue(), null, 0));
    assertNotNull(targetBusinessObjectDataEntity);
    assertNotNull(targetBusinessObjectDataEntity.getStorageUnits());
    assertEquals(1, targetBusinessObjectDataEntity.getStorageUnits().size());
    StorageUnitEntity storageUnit = IterableUtils.get(targetBusinessObjectDataEntity.getStorageUnits(), 0);
    assertNotNull(storageUnit);
    assertNotNull(storageUnit.getStorage());
    assertEquals(STORAGE_NAME_3, storageUnit.getStorage().getName());
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) UploadSingleInitiationRequest(org.finra.herd.model.api.xml.UploadSingleInitiationRequest) UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 9 with UploadSingleInitiationRequest

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

the class UploadDownloadServiceTest method testInitiateUploadSingleAssertTargetStorageBucketNameRequired.

/**
 * Asserts that error is thrown when target storage's bucket name is not set.
 */
@Test
public void testInitiateUploadSingleAssertTargetStorageBucketNameRequired() {
    // Create database entities required for testing.
    uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
    StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME_3);
    storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), "$environment/$namespace/$businessObjectDataPartitionValue"));
    storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KMS_KEY_ID), "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012"));
    // Initiate a file upload.
    UploadSingleInitiationRequest uploadSingleInitiationRequest = uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest();
    uploadSingleInitiationRequest.setTargetStorageName(STORAGE_NAME_3);
    try {
        uploadDownloadService.initiateUploadSingle(uploadSingleInitiationRequest);
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("Attribute \"" + configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME) + "\" for \"" + STORAGE_NAME_3 + "\" storage must be configured.", e.getMessage());
    }
}
Also used : StorageEntity(org.finra.herd.model.jpa.StorageEntity) UploadSingleInitiationRequest(org.finra.herd.model.api.xml.UploadSingleInitiationRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Example 10 with UploadSingleInitiationRequest

use of org.finra.herd.model.api.xml.UploadSingleInitiationRequest 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)

Aggregations

UploadSingleInitiationRequest (org.finra.herd.model.api.xml.UploadSingleInitiationRequest)11 Test (org.junit.Test)10 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)4 StorageEntity (org.finra.herd.model.jpa.StorageEntity)4 Attribute (org.finra.herd.model.api.xml.Attribute)3 UploadSingleInitiationResponse (org.finra.herd.model.api.xml.UploadSingleInitiationResponse)3 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)2 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)2 File (org.finra.herd.model.api.xml.File)2 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)1 Storage (org.finra.herd.model.api.xml.Storage)1 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)1 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)1 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)1