use of com.epam.pipeline.entity.datastorage.S3bucketDataStorage in project cloud-pipeline by epam.
the class DataStorageLoaderTest method shouldLoadDataStorageTest.
@Test
void shouldLoadDataStorageTest() throws EntityNotFoundException {
StoragePolicy policy = new StoragePolicy();
policy.setBackupDuration(DURATION);
policy.setLongTermStorageDuration(DURATION);
policy.setShortTermStorageDuration(DURATION);
S3bucketDataStorage expectedDataStorage = new S3bucketDataStorage();
expectedDataStorage.setId(1L);
expectedDataStorage.setParentFolderId(1L);
expectedDataStorage.setName(TEST_NAME);
expectedDataStorage.setPath(TEST_PATH);
expectedDataStorage.setOwner(TEST_NAME);
expectedDataStorage.setStoragePolicy(policy);
DataStorageLoader dataStorageLoader = new DataStorageLoader(apiClient);
when(apiClient.loadDataStorage(anyLong())).thenReturn(expectedDataStorage);
Optional<EntityContainer<DataStorageDoc>> container = dataStorageLoader.loadEntity(1L);
EntityContainer<DataStorageDoc> storageDocEntityContainer = container.orElseThrow(AssertionError::new);
DataStorageDoc actualDataStorageDoc = storageDocEntityContainer.getEntity();
assertNotNull(actualDataStorageDoc);
AbstractDataStorage actualDataStorage = actualDataStorageDoc.getStorage();
verifyDataStorage(expectedDataStorage, actualDataStorage);
verifyPipelineUser(storageDocEntityContainer.getOwner());
verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, storageDocEntityContainer.getPermissions());
verifyMetadata(EXPECTED_METADATA, new ArrayList<>(storageDocEntityContainer.getMetadata().values()));
}
use of com.epam.pipeline.entity.datastorage.S3bucketDataStorage in project cloud-pipeline by epam.
the class DataStorageMapperTest method shouldMapS3DataStorage.
@Test
void shouldMapS3DataStorage() throws IOException {
DataStorageMapper mapper = new DataStorageMapper(SearchDocumentType.S3_STORAGE);
StoragePolicy policy = new StoragePolicy();
policy.setBackupDuration(DURATION);
policy.setLongTermStorageDuration(DURATION);
policy.setShortTermStorageDuration(DURATION);
S3bucketDataStorage dataStorage = new S3bucketDataStorage();
fillStorage(dataStorage);
dataStorage.setStoragePolicy(policy);
DataStorageDoc doc = DataStorageDoc.builder().regionName(TEST_REGION).storage(dataStorage).build();
XContentBuilder contentBuilder = mapper.map(buildContainer(doc));
verifyS3Storage(dataStorage, TEST_REGION, contentBuilder);
verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder);
verifyMetadata(EXPECTED_METADATA, contentBuilder);
verifyPipelineUser(USER, contentBuilder);
}
use of com.epam.pipeline.entity.datastorage.S3bucketDataStorage in project cloud-pipeline by epam.
the class DataStorageLoader method fetchEntity.
@Override
protected DataStorageDoc fetchEntity(final Long id) {
AbstractDataStorage dataStorage = getApiClient().loadDataStorage(id);
List<AwsRegion> awsRegions = getApiClient().loadAllRegions();
DataStorageDoc.DataStorageDocBuilder docBuilder = DataStorageDoc.builder().storage(dataStorage);
if (dataStorage instanceof S3bucketDataStorage) {
S3bucketDataStorage bucket = (S3bucketDataStorage) dataStorage;
docBuilder.regionName(Optional.ofNullable(bucket.getRegionId()).flatMap(regionId -> awsRegions.stream().filter(region -> region.getId().equals(bucket.getRegionId())).findFirst().map(AwsRegion::getAwsRegionName)).orElse(StringUtils.EMPTY));
}
return docBuilder.build();
}
Aggregations