StorageUnitHelper { List<StorageUnit> createStorageUnitsFromEntities(Collection<StorageUnitEntity> storageUnitEntities, Boolean includeStorageUnitStatusHistory, Boolean excludeBusinessObjectDataStorageFiles) { List<StorageUnit> storageUnits = new ArrayList<>(); for (StorageUnitEntity storageUnitEntity : storageUnitEntities) { StorageUnit storageUnit = new StorageUnit(); storageUnits.add(storageUnit); Storage storage = new Storage(); storageUnit.setStorage(storage); StorageEntity storageEntity = storageUnitEntity.getStorage(); storage.setName(storageEntity.getName()); storage.setStoragePlatformName(storageEntity.getStoragePlatform().getName()); if (!CollectionUtils.isEmpty(storageEntity.getAttributes())) { List<Attribute> storageAttributes = new ArrayList<>(); storage.setAttributes(storageAttributes); for (StorageAttributeEntity storageAttributeEntity : storageEntity.getAttributes()) { Attribute attribute = new Attribute(); storageAttributes.add(attribute); attribute.setName(storageAttributeEntity.getName()); attribute.setValue(storageAttributeEntity.getValue()); } } if (storageUnitEntity.getDirectoryPath() != null) { StorageDirectory storageDirectory = new StorageDirectory(); storageUnit.setStorageDirectory(storageDirectory); storageDirectory.setDirectoryPath(storageUnitEntity.getDirectoryPath()); } if (BooleanUtils.isNotTrue(excludeBusinessObjectDataStorageFiles) && CollectionUtils.isNotEmpty(storageUnitEntity.getStorageFiles())) { List<StorageFile> storageFiles = new ArrayList<>(); storageUnit.setStorageFiles(storageFiles); for (StorageFileEntity storageFileEntity : storageUnitEntity.getStorageFiles()) { storageFiles.add(storageFileHelper.createStorageFileFromEntity(storageFileEntity, storageUnitEntity.getDirectoryPath())); } } storageUnit.setStorageUnitStatus(storageUnitEntity.getStatus().getCode()); if (BooleanUtils.isTrue(includeStorageUnitStatusHistory)) { List<StorageUnitStatusChangeEvent> storageUnitStatusChangeEvents = new ArrayList<>(); storageUnit.setStorageUnitStatusHistory(storageUnitStatusChangeEvents); for (StorageUnitStatusHistoryEntity storageUnitStatusHistoryEntity : storageUnitEntity.getHistoricalStatuses()) { storageUnitStatusChangeEvents.add(new StorageUnitStatusChangeEvent(storageUnitStatusHistoryEntity.getStatus().getCode(), HerdDateUtils.getXMLGregorianCalendarValue(storageUnitStatusHistoryEntity.getCreatedOn()), storageUnitStatusHistoryEntity.getCreatedBy())); } } storageUnit.setStoragePolicyTransitionFailedAttempts(storageUnitEntity.getStoragePolicyTransitionFailedAttempts()); if (storageUnitEntity.getRestoreExpirationOn() != null) { storageUnit.setRestoreExpirationOn(HerdDateUtils.getXMLGregorianCalendarValue(storageUnitEntity.getRestoreExpirationOn())); } } return storageUnits; }  BusinessObjectDataStorageUnitKey createBusinessObjectDataStorageUnitKey(BusinessObjectDataKey businessObjectDataKey, String storageName); BusinessObjectDataStorageUnitKey createStorageUnitKey(BusinessObjectDataKey businessObjectDataKey, String storageName); BusinessObjectDataStorageUnitKey createStorageUnitKeyFromEntity(StorageUnitEntity storageUnitEntity); List<StorageUnitAvailabilityDto> excludeBusinessObjectDataStatus(List<StorageUnitAvailabilityDto> storageUnitAvailabilityDtos,
        String excludedBusinessObjectDataStatus); List<StorageUnitAvailabilityDto> excludePartitions(List<StorageUnitAvailabilityDto> storageUnitAvailabilityDtos,
        List<List<String>> excludedPartitions); BusinessObjectDataKey getBusinessObjectDataKey(BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey); List<Integer> getStorageUnitIds(List<StorageUnitAvailabilityDto> storageUnitAvailabilityDtos); void validateBusinessObjectDataStorageUnitKey(BusinessObjectDataStorageUnitKey key);  }
@Test public void testCreateStorageUnitsFromEntities() { BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME); StorageFileEntity storageFileOneEntity = new StorageFileEntity(); storageFileOneEntity.setStorageUnit(null); storageFileOneEntity.setPath(FILE_NAME); storageFileOneEntity.setFileSizeBytes(FILE_SIZE); storageFileOneEntity.setRowCount(ROW_COUNT); StorageFileEntity storageFileTwoEntity = new StorageFileEntity(); storageFileTwoEntity.setStorageUnit(null); storageFileTwoEntity.setPath(STORAGE_DIRECTORY_PATH + "/" + FILE_NAME_2); storageFileTwoEntity.setFileSizeBytes(FILE_SIZE_2); storageFileTwoEntity.setRowCount(ROW_COUNT_2); final Timestamp restoredExpirationOn = new Timestamp(new Date().getTime()); StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS); storageUnitEntity.setDirectoryPath(STORAGE_DIRECTORY_PATH); storageUnitEntity.setStorageFiles(Lists.newArrayList(storageFileOneEntity, storageFileTwoEntity)); storageUnitEntity.setStoragePolicyTransitionFailedAttempts(STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS); storageUnitEntity.setRestoreExpirationOn(restoredExpirationOn); when(storageFileHelper.createStorageFileFromEntity(any(StorageFileEntity.class), eq(STORAGE_DIRECTORY_PATH))).thenCallRealMethod(); List<StorageUnit> result = storageUnitHelper.createStorageUnitsFromEntities(Collections.singletonList(storageUnitEntity), NO_INCLUDE_STORAGE_UNIT_STATUS_HISTORY, NO_EXCLUDE_BUSINESS_OBJECT_DATA_STORAGE_FILES); verify(storageFileHelper).createStorageFileFromEntity(storageFileOneEntity, STORAGE_DIRECTORY_PATH); verify(storageFileHelper).createStorageFileFromEntity(storageFileTwoEntity, STORAGE_DIRECTORY_PATH); verifyNoMoreInteractionsHelper(); assertEquals(Collections.singletonList( new StorageUnit(new Storage(STORAGE_NAME, StoragePlatformEntity.S3, null), new StorageDirectory(STORAGE_DIRECTORY_PATH), Lists .newArrayList(new StorageFile(STORAGE_DIRECTORY_PATH + "/" + FILE_NAME, FILE_SIZE, ROW_COUNT), new StorageFile(STORAGE_DIRECTORY_PATH + "/" + FILE_NAME_2, FILE_SIZE_2, ROW_COUNT_2)), STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS_HISTORY, STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, HerdDateUtils.getXMLGregorianCalendarValue(restoredExpirationOn))), result); }