StorageHelper { public String getStorageAttributeValueByName(String attributeName, Storage storage, Boolean required) { String attributeValue = null; for (Attribute attribute : storage.getAttributes()) { if (attribute.getName().equalsIgnoreCase(attributeName)) { attributeValue = attribute.getValue(); break; } } if (required && StringUtils.isBlank(attributeValue)) { throw new IllegalStateException(String.format("Attribute \"%s\" for \"%s\" storage must be configured.", attributeName, storage.getName())); } return attributeValue; }  boolean getBooleanStorageAttributeValueByName(String attributeName, StorageEntity storageEntity, boolean attributeRequired,
        boolean attributeValueRequiredIfExists); S3FileTransferRequestParamsDto getS3BucketAccessParams(StorageEntity storageEntity); S3FileCopyRequestParamsDto getS3FileCopyRequestParamsDto(); S3FileTransferRequestParamsDto getS3FileTransferRequestParamsDto(); S3FileTransferRequestParamsDto getS3FileTransferRequestParamsDtoByRole(String roleArn, String sessionName); Integer getStorageAttributeIntegerValueByName(String attributeName, StorageEntity storageEntity, Integer defaultValue); Integer getStorageAttributeIntegerValueByName(String attributeName, StorageEntity storageEntity, boolean attributeRequired,
        boolean attributeValueRequiredIfExists); String getStorageAttributeValueByName(String attributeName, Storage storage, Boolean required); String getStorageAttributeValueByName(String attributeName, StorageEntity storageEntity, boolean attributeValueRequired); String getStorageAttributeValueByName(String attributeName, StorageEntity storageEntity, boolean attributeRequired,
        boolean attributeValueRequiredIfExists); String getStorageBucketName(StorageEntity storageEntity); String getStorageKmsKeyId(StorageEntity storageEntity);  }
@Test public void testGetStorageAttributeValueByNameFromStorage() { final String testStorageName = "MY_TEST_STORAGE"; final String testAttributeNameNoExists = "I_DO_NOT_EXIST"; Storage testStorage = new Storage(); testStorage.setName(testStorageName); testStorage.setAttributes(businessObjectDefinitionServiceTestHelper.getNewAttributes()); assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE, testStorage, Boolean.FALSE)); assertEquals(ATTRIBUTE_VALUE_2, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_2_MIXED_CASE, testStorage, Boolean.TRUE)); assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), testStorage, Boolean.TRUE)); assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE.toUpperCase(), testStorage, Boolean.TRUE)); assertNull(storageHelper.getStorageAttributeValueByName(testAttributeNameNoExists, testStorage, Boolean.FALSE)); try { storageHelper.getStorageAttributeValueByName(testAttributeNameNoExists, testStorage, Boolean.TRUE); fail("Suppose to throw a RuntimeException when required storage attribute does not exist or has a blank value."); } catch (RuntimeException e) { assertEquals(String.format("Attribute \"%s\" for \"%s\" storage must be configured.", testAttributeNameNoExists, testStorage.getName()), e.getMessage()); } }
@Test public void testGetStorageAttributeValueByNameFromStorageEntity() { List<Attribute> attributes = new ArrayList<>(); attributes.add(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1)); attributes.add(new Attribute(ATTRIBUTE_NAME_2_MIXED_CASE, BLANK_TEXT)); attributes.add(new Attribute(ATTRIBUTE_NAME_3_MIXED_CASE, null)); StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, attributes); Assert.assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE, storageEntity, false)); Assert.assertEquals(BLANK_TEXT, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_2_MIXED_CASE, storageEntity, false)); Assert.assertNull(storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_3_MIXED_CASE, storageEntity, false)); Assert.assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE.toUpperCase(), storageEntity, false)); Assert.assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), storageEntity, false)); Assert.assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE, storageEntity, true)); String attributeNoExist = "I_DO_NOT_EXIST"; for (String attributeName : Arrays.asList(attributeNoExist, ATTRIBUTE_NAME_2_MIXED_CASE, ATTRIBUTE_NAME_3_MIXED_CASE)) { try { storageHelper.getStorageAttributeValueByName(attributeName, storageEntity, true); } catch (IllegalStateException e) { if (attributeName.equals(attributeNoExist)) { Assert.assertEquals(String.format("Attribute \"%s\" for \"%s\" storage must be configured.", attributeName, STORAGE_NAME), e.getMessage()); } else { Assert.assertEquals(String.format("Attribute \"%s\" for \"%s\" storage must have a value that is not blank.", attributeName, STORAGE_NAME), e.getMessage()); } } } }