KmsHelper { public String getDecryptedConfigurationValue(ConfigurationValue configurationValue) { String encryptedValue = configurationHelper.getProperty(configurationValue); if (StringUtils.isBlank(encryptedValue)) { throw new IllegalStateException("Unable to decrypt configuration value \"" + configurationValue.getKey() + "\" since it is not configured."); } try { return kmsDao.decrypt(awsHelper.getAwsParamsDto(), encryptedValue); } catch (Exception e) { throw new IllegalStateException("Error decrypting configuration value \"" + configurationValue.getKey() + "\".", e); } }  String getDecryptedConfigurationValue(ConfigurationValue configurationValue);  }
@Test public void testGetDecryptedConfigurationValue() throws Exception { Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE.getKey(), MockKmsOperationsImpl.MOCK_CIPHER_TEXT); modifyPropertySourceInEnvironment(overrideMap); try { String resultDecryptedValue = kmsHelper.getDecryptedConfigurationValue(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE); assertEquals(MockKmsOperationsImpl.MOCK_PLAIN_TEXT, resultDecryptedValue); } finally { restorePropertySourceInEnvironment(); } }
@Test public void testGetDecryptedConfigurationValueBlank() throws Exception { Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE.getKey(), BLANK_TEXT); modifyPropertySourceInEnvironment(overrideMap); try { kmsHelper.getDecryptedConfigurationValue(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE); fail("Suppose to throw an IllegalStateException when encrypted configuration value is blank."); } catch (IllegalStateException e) { assertEquals(String.format("Unable to decrypt configuration value \"%s\" since it is not configured.", ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE.getKey()), e.getMessage()); } finally { restorePropertySourceInEnvironment(); } }
@Test public void testGetDecryptedConfigurationValueDecryptionError() throws Exception { Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE.getKey(), MockKmsOperationsImpl.MOCK_CIPHER_TEXT_INVALID); modifyPropertySourceInEnvironment(overrideMap); try { kmsHelper.getDecryptedConfigurationValue(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE); fail("Suppose to throw an IllegalStateException when encrypted value is invalid."); } catch (IllegalStateException e) { assertEquals(String.format("Error decrypting configuration value \"%s\".", ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE.getKey()), e.getMessage()); } finally { restorePropertySourceInEnvironment(); } }