BusinessObjectDataInitiateDestroyHelperServiceImpl implements BusinessObjectDataInitiateDestroyHelperService { StorageUnitEntity getAndValidateStorageUnit(BusinessObjectDataEntity businessObjectDataEntity, BusinessObjectDataKey businessObjectDataKey) { List<StorageUnitEntity> s3StorageUnitEntities = storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); if (CollectionUtils.isEmpty(s3StorageUnitEntities)) { throw new IllegalArgumentException(String.format("Business object data has no S3 storage unit. Business object data: {%s}", businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } if (CollectionUtils.size(s3StorageUnitEntities) > 1) { throw new IllegalArgumentException(String .format("Business object data has multiple (%s) %s storage units. Business object data: {%s}", s3StorageUnitEntities.size(), StoragePlatformEntity.S3, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } StorageUnitEntity storageUnitEntity = s3StorageUnitEntities.get(0); String storageUnitStatus = storageUnitEntity.getStatus().getCode(); if (!BusinessObjectDataInitiateDestroyHelperServiceImpl.SUPPORTED_STORAGE_UNIT_STATUSES.contains(storageUnitStatus)) { throw new IllegalArgumentException(String .format("Storage unit status \"%s\" is not supported by the business object data destroy feature. Storage: {%s}, business object data: {%s}", storageUnitStatus, storageUnitEntity.getStorage().getName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); } return storageUnitEntity; }  @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) BusinessObjectData executeInitiateDestroyAfterStep(BusinessObjectDataDestroyDto businessObjectDataDestroyDto); @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) void executeS3SpecificSteps(BusinessObjectDataDestroyDto businessObjectDataDestroyDto); @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void prepareToInitiateDestroy(BusinessObjectDataDestroyDto businessObjectDataDestroyDto, BusinessObjectDataKey businessObjectDataKey);  }
@Test public void testGetAndValidateStorageUnitInvalidStorageUnitStatus() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setId(ID); StorageEntity storageEntity = new StorageEntity(); storageEntity.setName(STORAGE_NAME); StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(INVALID_VALUE); StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setStorage(storageEntity); storageUnitEntity.setStatus(storageUnitStatusEntity); when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)) .thenReturn(Arrays.asList(storageUnitEntity)); when(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); try { businessObjectDataInitiateDestroyHelperServiceImpl.getAndValidateStorageUnit(businessObjectDataEntity, businessObjectDataKey); fail(); } catch (IllegalArgumentException e) { assertEquals(String .format("Storage unit status \"%s\" is not supported by the business object data destroy feature. Storage: {%s}, business object data: {%s}", INVALID_VALUE, STORAGE_NAME, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); verify(businessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey); verifyNoMoreInteractionsHelper(); }
@Test public void testGetAndValidateStorageUnitMultipleS3StorageUnits() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setId(ID); when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)) .thenReturn(Arrays.asList(new StorageUnitEntity(), new StorageUnitEntity())); when(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); try { businessObjectDataInitiateDestroyHelperServiceImpl.getAndValidateStorageUnit(businessObjectDataEntity, businessObjectDataKey); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has multiple (%s) %s storage units. Business object data: {%s}", 2, StoragePlatformEntity.S3, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); verify(businessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey); verifyNoMoreInteractionsHelper(); }
@Test public void testGetAndValidateStorageUnitNoS3StorageUnit() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setId(ID); when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)) .thenReturn(new ArrayList<>()); when(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); try { businessObjectDataInitiateDestroyHelperServiceImpl.getAndValidateStorageUnit(businessObjectDataEntity, businessObjectDataKey); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has no S3 storage unit. Business object data: {%s}", BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); verify(businessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey); verifyNoMoreInteractionsHelper(); }