/** * Gets a property value as a {@link BigDecimal}. * * @param configurationValue the {@link BigDecimal} configuration value * * @return the {@link BigDecimal} property value */ public BigDecimal getBigDecimalRequiredProperty(ConfigurationValue configurationValue) { return getBigDecimalRequiredProperty(configurationValue, environment); }
/** * Gets a property value as a {@link BigDecimal}. * * @param configurationValue the {@link BigDecimal} configuration value * * @return the {@link BigDecimal} property value */ public BigDecimal getBigDecimalRequiredProperty(ConfigurationValue configurationValue) { return getBigDecimalRequiredProperty(configurationValue, environment); }
/** * Gets a property value as {@link BigDecimal}. Additionally it ensures that the property value is not negative. * * @param configurationValue the {@link BigDecimal} configuration value * @param environment the environment containing the property * * @return the non-negative {@link BigDecimal} property value */ public BigDecimal getNonNegativeBigDecimalRequiredProperty(ConfigurationValue configurationValue, Environment environment) { final BigDecimal nonNegativeBigDecimalPropertyValue = getBigDecimalRequiredProperty(configurationValue, environment); if (nonNegativeBigDecimalPropertyValue.signum() == -1) { throw new IllegalStateException(String .format("Configuration \"%s\" has an invalid non-negative BigDecimal value: \"%s\".", configurationValue.getKey(), nonNegativeBigDecimalPropertyValue)); } return nonNegativeBigDecimalPropertyValue; }
/** * Gets a property value as {@link BigDecimal}. Additionally it ensures that the property value is not negative. * * @param configurationValue the {@link BigDecimal} configuration value * @param environment the environment containing the property * * @return the non-negative {@link BigDecimal} property value */ public BigDecimal getNonNegativeBigDecimalRequiredProperty(ConfigurationValue configurationValue, Environment environment) { final BigDecimal nonNegativeBigDecimalPropertyValue = getBigDecimalRequiredProperty(configurationValue, environment); if (nonNegativeBigDecimalPropertyValue.signum() == -1) { throw new IllegalStateException(String .format("Configuration \"%s\" has an invalid non-negative BigDecimal value: \"%s\".", configurationValue.getKey(), nonNegativeBigDecimalPropertyValue)); } return nonNegativeBigDecimalPropertyValue; }
@Test public void testGetBigDecimalRequiredPropertyValidationThrowsWhenConfigurationValueIsNull() { try { configurationHelper.getBigDecimalRequiredProperty(null); fail("Should throw an IllegalStateException when configuration value is null."); } catch (IllegalStateException e) { assertEquals("configurationValue is required", e.getMessage()); } }
@Test public void testGetBigDecimalRequiredPropertyValue() { ConfigurationValue configurationValue = ConfigurationValue.EMR_CLUSTER_LOWEST_CORE_INSTANCE_PRICE_PERCENTAGE; MockEnvironment environment = new MockEnvironment(); environment.setProperty(configurationValue.getKey(), "0.05"); assertEquals(new BigDecimal("0.05"), configurationHelper.getBigDecimalRequiredProperty(configurationValue, environment)); }
@Test public void testGetBigDecimalRequiredPropertyValueBlankStringValue() { ConfigurationValue configurationValue = ConfigurationValue.EMR_CLUSTER_LOWEST_CORE_INSTANCE_PRICE_PERCENTAGE; MockEnvironment environment = new MockEnvironment(); environment.setProperty(configurationValue.getKey(), " "); try { configurationHelper.getBigDecimalRequiredProperty(configurationValue, environment); fail("Should throw an IllegalStatueException when property value is not BigDecimal."); } catch (IllegalStateException e) { assertEquals(String.format("Configuration \"%s\" must have a value.", configurationValue.getKey()), e.getMessage()); } }
@Test public void testGetBigDecimalRequiredPropertyValueConversionFail() { ConfigurationValue configurationValue = ConfigurationValue.EMR_CLUSTER_LOWEST_CORE_INSTANCE_PRICE_PERCENTAGE; MockEnvironment environment = new MockEnvironment(); environment.setProperty(configurationValue.getKey(), "INVALID_BigDecimal_VALUE"); try { configurationHelper.getBigDecimalRequiredProperty(configurationValue, environment); fail("Should throw an IllegalStatueException when property value is not BigDecimal."); } catch (IllegalStateException e) { assertEquals(String.format("Configuration \"%s\" has an invalid BigDecimal value: \"INVALID_BigDecimal_VALUE\".", configurationValue.getKey()), e.getMessage()); } }