/** * Creates and persists a new storage entity of S3 storage platform with the specified attributes. * * @param storageName the storage name * @param attributes the storage attributes. * * @return the newly created storage entity. */ public StorageEntity createStorageEntity(String storageName, List<Attribute> attributes) { return createStorageEntity(storageName, StoragePlatformEntity.S3, attributes); }
@Before public void before() { s3BucketName = storageDaoTestHelper.getS3ManagedBucketName(); }
@Test public void testGetAllStorage() { // Get a list of test storage keys. List<StorageKey> storageKeys = storageDaoTestHelper.getTestStorageKeys(); // Create and persist storage entities. for (StorageKey storageKey : storageKeys) { storageDaoTestHelper.createStorageEntity(storageKey.getStorageName()); } // Retrieve a list of storage keys for all storage registered in the system. List<StorageKey> result = storageDao.getAllStorage(); // Validate the results. assertNotNull(result); assertTrue(result.containsAll(storageDaoTestHelper.getTestStorageKeys())); } }
/** * Test S3 file copy without any errors. */ @Test public void testCopyFile() throws InterruptedException { // Put a 1 byte file in S3. s3Operations .putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), null), null); S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto(); transferDto.setSourceBucketName(storageDaoTestHelper.getS3LoadingDockBucketName()); transferDto.setTargetBucketName(storageDaoTestHelper.getS3ExternalBucketName()); transferDto.setSourceObjectKey(TARGET_S3_KEY); transferDto.setTargetObjectKey(TARGET_S3_KEY); transferDto.setKmsKeyId(MockS3OperationsImpl.MOCK_KMS_ID); S3FileTransferResultsDto resultsDto = s3Dao.copyFile(transferDto); assertEquals(Long.valueOf(1L), resultsDto.getTotalFilesTransferred()); }
.createStorageEntity(storageName, storagePlatform, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storageDaoTestHelper.getS3ManagedBucketName());
/** * 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()); } }
/** * Storage attribute: 1234 Default value: null Assert return default value */ @Test public void testGetStorageAttributeIntegerValueByNameWithDefault_4() { String attributeName = "test"; String attributeValue = "1234"; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue); Integer defaultValue = null; Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, defaultValue); assertEquals(new Integer(attributeValue), value); }
new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[(int) FILE_SIZE_1_KB]), null), null);
/** * Gets the bucket name for the S3 managed storage. * * @return the bucket name. */ public String getS3ManagedBucketName() { return getBucketNameFromStorage(StorageEntity.MANAGED_STORAGE); }
.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucketName")); .createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_DOWNLOAD_ROLE_ARN), "downloadRole"));
/** * Test S3 file copy without a KMS ID specified. */ @Test public void testCopyFileNoKmsId() throws InterruptedException { // Put a 1 byte file in S3. s3Operations .putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), null), null); // Perform an S3 file copy operation when KMS ID value is not specified. for (String kmsId : Arrays.asList(BLANK_TEXT, null)) { S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto(); transferDto.setSourceBucketName(storageDaoTestHelper.getS3LoadingDockBucketName()); transferDto.setTargetBucketName(storageDaoTestHelper.getS3ExternalBucketName()); transferDto.setSourceObjectKey(TARGET_S3_KEY); transferDto.setTargetObjectKey(TARGET_S3_KEY); transferDto.setKmsKeyId(kmsId); S3FileTransferResultsDto resultsDto = s3Dao.copyFile(transferDto); assertEquals(Long.valueOf(1L), resultsDto.getTotalFilesTransferred()); } }
storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, Arrays.asList( new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storageDaoTestHelper.getS3ManagedBucketName()), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), S3_KEY_PREFIX_VELOCITY_TEMPLATE), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), Boolean.toString(false)),
@Test public void testCreateBusinessObjectDataPreRegistrationAssertDirectoryPathNotRequiredWhenStatusIsPreRegistrationAndDirectoryIsSetInResponse() { StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME); storageEntity.getAttributes().add(storageDaoTestHelper .createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), "foo")); // Create an initial version of the business object data. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(); businessObjectDataCreateRequest.setSubPartitionValues(null); businessObjectDataCreateRequest.setStatus("UPLOADING"); businessObjectDataCreateRequest.setStorageUnits(Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, null, null, null))); BusinessObjectData businessObjectData = businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); assertEquals("foo", businessObjectData.getStorageUnits().get(0).getStorageDirectory().getDirectoryPath()); }
/** * Storage attribute: 1234 Attribute required: false Attribute required if exists: false Assert result = 1234 */ @Test public void testGetStorageAttributeIntegerValueByName_3() { String attributeName = "test"; String attributeValue = "1234"; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue); boolean attributeRequired = false; boolean attributeValueRequiredIfExists = false; Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists); assertEquals(new Integer(attributeValue), value); }
new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), filePath, new ByteArrayInputStream(new byte[(int) FILE_SIZE_1_KB]), null); s3Operations.putObject(putObjectRequest, null); S3FileTransferRequestParamsDto.builder().withS3BucketName(storageDaoTestHelper.getS3LoadingDockBucketName()).withS3KeyPrefix(filePath).build());
/** * Gets the bucket name for the S3 external storage. * * @return the bucket name. */ public String getS3ExternalBucketName() { return getBucketNameFromStorage(StorageEntity.MANAGED_EXTERNAL_STORAGE); }
.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucketName")); .createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_DOWNLOAD_ROLE_ARN), "downloadRole"));
@Test public void testDeleteSourceFileFromS3() { // 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); // Initialize parameters required to delete the S3 source file 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()); // Delete the source file from S3 uploadDownloadHelperService.deleteSourceFileFromS3(completeUploadSingleParamsDto); }
/** * Creates and persists a new storage entity of S3 storage platform with no attributes. * * @param storageName the storage name * * @return the newly created storage entity. */ public StorageEntity createStorageEntity(String storageName) { return createStorageEntity(storageName, StoragePlatformEntity.S3); }
@Test public void testValidateS3File() throws IOException, InterruptedException { // Put a 1 KB file in S3. PutObjectRequest putObjectRequest = new PutObjectRequest(storageDaoTestHelper.getS3ManagedBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[(int) FILE_SIZE_1_KB]), null); s3Operations.putObject(putObjectRequest, null); // Validate the S3 file. S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = s3DaoTestHelper.getTestS3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setS3KeyPrefix(TARGET_S3_KEY); s3Dao.validateS3File(s3FileTransferRequestParamsDto, FILE_SIZE_1_KB); }