/** * Gets a storage attribute value by name. If the attribute does not exist, returns the default value. If the attribute exists, and is defined, the value * MUST be an integer, otherwise a exception is thrown. * * @param attributeName The name of attribute * @param storageEntity The storage entity * @param defaultValue The default value * * @return The integer value */ public Integer getStorageAttributeIntegerValueByName(String attributeName, StorageEntity storageEntity, Integer defaultValue) { Integer value = getStorageAttributeIntegerValueByName(attributeName, storageEntity, false, false); if (value == null) { value = defaultValue; } return value; }
/** * Gets a storage attribute value by name. If the attribute does not exist, returns the default value. If the attribute exists, and is defined, the value * MUST be an integer, otherwise a exception is thrown. * * @param attributeName The name of attribute * @param storageEntity The storage entity * @param defaultValue The default value * * @return The integer value */ public Integer getStorageAttributeIntegerValueByName(String attributeName, StorageEntity storageEntity, Integer defaultValue) { Integer value = getStorageAttributeIntegerValueByName(attributeName, storageEntity, false, false); if (value == null) { value = defaultValue; } return value; }
/** * Gets the storage's download session duration in seconds. Defaults to the configured default value if not defined. * * @param storageEntity The storage entity * * @return Download session duration in seconds */ private Integer getStorageDownloadSessionDuration(StorageEntity storageEntity) { return storageHelper .getStorageAttributeIntegerValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_DOWNLOAD_SESSION_DURATION_SECS), storageEntity, configurationHelper.getProperty(ConfigurationValue.AWS_S3_DEFAULT_DOWNLOAD_SESSION_DURATION_SECS, Integer.class)); }
/** * Gets the storage's upload session duration in seconds. Defaults to the configured default value if not defined. * * @param storageEntity The storage entity * * @return Upload session duration in seconds */ private Integer getStorageUploadSessionDuration(StorageEntity storageEntity) { return storageHelper .getStorageAttributeIntegerValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_SESSION_DURATION_SECS), storageEntity, configurationHelper.getProperty(ConfigurationValue.AWS_S3_DEFAULT_UPLOAD_SESSION_DURATION_SECS, Integer.class)); }
/** * Gets the storage's upload session duration in seconds. Defaults to the configured default value if not defined. * * @param storageEntity The storage entity * * @return Upload session duration in seconds */ private Integer getStorageUploadSessionDuration(StorageEntity storageEntity) { return storageHelper .getStorageAttributeIntegerValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_SESSION_DURATION_SECS), storageEntity, configurationHelper.getProperty(ConfigurationValue.AWS_S3_DEFAULT_UPLOAD_SESSION_DURATION_SECS, Integer.class)); }
/** * Gets the storage's download session duration in seconds. Defaults to the configured default value if not defined. * * @param storageEntity The storage entity * * @return Download session duration in seconds */ private Integer getStorageDownloadSessionDuration(StorageEntity storageEntity) { return storageHelper .getStorageAttributeIntegerValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_DOWNLOAD_SESSION_DURATION_SECS), storageEntity, configurationHelper.getProperty(ConfigurationValue.AWS_S3_DEFAULT_DOWNLOAD_SESSION_DURATION_SECS, Integer.class)); }
/** * 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); }
/** * Storage attribute: 1234 Default value: 2345 Assert return default value */ @Test public void testGetStorageAttributeIntegerValueByNameWithDefault_3() { String attributeName = "test"; String attributeValue = "1234"; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue); Integer defaultValue = 2345; Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, defaultValue); assertEquals(new Integer(attributeValue), value); }
/** * Storage attribute: 1234 Attribute required: false Attribute required if exists: true Assert result = 1234 */ @Test public void testGetStorageAttributeIntegerValueByName_1() { String attributeName = "test"; String attributeValue = "1234"; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue); boolean attributeRequired = false; boolean attributeValueRequiredIfExists = true; Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists); assertEquals(new Integer(attributeValue), value); }
/** * Storage attribute: 1234 Attribute required: true Attribute required if exists: false Assert result = 1234 */ @Test public void testGetStorageAttributeIntegerValueByName_2() { String attributeName = "test"; String attributeValue = "1234"; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue); boolean attributeRequired = true; boolean attributeValueRequiredIfExists = false; Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists); assertEquals(new Integer(attributeValue), value); }
/** * 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); }
/** * Storage attribute: non-existent Default value: null Assert return default value */ @Test public void testGetStorageAttributeIntegerValueByNameWithDefault_2() { String attributeName = "test"; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(); Integer defaultValue = null; Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, defaultValue); assertEquals(defaultValue, value); }
/** * Storage attribute: non-existent Default value: 2345 Assert return default value */ @Test public void testGetStorageAttributeIntegerValueByNameWithDefault_1() { String attributeName = "test"; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(); Integer defaultValue = 2345; Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, defaultValue); assertEquals(defaultValue, value); }
/** * Storage attribute: non-existent Attribute required: false Attribute required if exists: true Assert return null */ @Test public void testGetStorageAttributeIntegerValueByName_8() { String attributeName = "test"; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(); boolean attributeRequired = false; boolean attributeValueRequiredIfExists = true; Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists); assertEquals(null, value); }
/** * Storage attribute: non-existent Attribute required: false Attribute required if exists: false Assert return null */ @Test public void testGetStorageAttributeIntegerValueByName_10() { String attributeName = "test"; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(); boolean attributeRequired = false; boolean attributeValueRequiredIfExists = true; Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists); assertEquals(null, value); }
/** * Storage attribute: null Attribute required: true Attribute required if exists: false Assert throw */ @Test public void testGetStorageAttributeIntegerValueByName_12() { String attributeName = "test"; String attributeValue = null; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue); boolean attributeRequired = true; boolean attributeValueRequiredIfExists = false; Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists); assertEquals(attributeValue, value); }
/** * Storage attribute: null Attribute required: false Attribute required if exists: false Assert return null */ @Test public void testGetStorageAttributeIntegerValueByName_13() { String attributeName = "test"; String attributeValue = null; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue); boolean attributeRequired = true; boolean attributeValueRequiredIfExists = false; assertEquals(attributeValue, storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists)); }
/** * Storage attribute: abcd Default value: 2345 Assert throw */ @Test public void testGetStorageAttributeIntegerValueByNameWithDefault_5() { String attributeName = "test"; String attributeValue = "abcd"; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue); Integer defaultValue = 2345; try { storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, defaultValue); fail(); } catch (Exception e) { assertEquals(IllegalStateException.class, e.getClass()); assertEquals("Storage attribute \"" + attributeName + "\" must be a valid integer. Actual value is \"" + attributeValue + "\"", e.getMessage()); } }
/** * Storage attribute: blank Attribute required: false Attribute required if exists: false Assert throw */ @Test public void testGetStorageAttributeIntegerValueByName_7() { String attributeName = "test"; String attributeValue = BLANK_TEXT; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue); boolean attributeRequired = false; boolean attributeValueRequiredIfExists = false; try { storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists); fail(); } catch (Exception e) { assertEquals(IllegalStateException.class, e.getClass()); assertEquals("Storage attribute \"" + attributeName + "\" must be a valid integer. Actual value is \"" + attributeValue + "\"", e.getMessage()); } }
/** * Storage attribute: null Attribute required: false Attribute required if exists: true Assert return null */ @Test public void testGetStorageAttributeIntegerValueByName_11() { String attributeName = "test"; String attributeValue = null; StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue); boolean attributeRequired = false; boolean attributeValueRequiredIfExists = true; try { storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists); fail(); } catch (Exception e) { assertEquals(IllegalStateException.class, e.getClass()); assertEquals("Attribute \"" + attributeName + "\" for \"" + storageEntity.getName() + "\" storage must have a value that is not blank.", e.getMessage()); } }