public void validateTree() { for (ConfigurationProperty property : this) { property.validate(null); } }
public void validateTree() { ConfigSaveValidationContext validationContext = new ConfigSaveValidationContext(this); for (ConfigurationProperty configurationProperty : settingsMap) { configurationProperty.validate(validationContext); if (configurationProperty.hasErrors()) { hasErrors = true; } } } }
@Test public void validateTreeShouldValidateAllConfigurationProperties() { ConfigurationProperty outputDirectory = mock(ConfigurationProperty.class); ConfigurationProperty inputDirectory = mock(ConfigurationProperty.class); Configuration configuration = new Configuration(outputDirectory, inputDirectory); configuration.validateTree(); verify(outputDirectory).validate(null); verify(inputDirectory).validate(null); }
@Test public void shouldPassValidationIfBothNameAndEncryptedValueAreProvidedForSecureProperty() throws CryptoException { String encrypted = "encrypted"; String decrypted = "decrypted"; when(cipher.decrypt(encrypted)).thenReturn(decrypted); ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("name"), null, new EncryptedConfigurationValue(encrypted), cipher); property.validate(ConfigSaveValidationContext.forChain(property)); assertThat(property.errors().isEmpty(), is(true)); }
@Test public void shouldPassValidationIfBothNameAndValueAreProvided() { GoCipher cipher = mock(GoCipher.class); ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("name"), new ConfigurationValue("value"), null, cipher); property.validate(ConfigSaveValidationContext.forChain(property)); assertThat(property.errors().isEmpty(), is(true)); }
@Test public void shouldFailValidationIfAPropertyDoesNotHaveValue() { ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("secureKey"), null, new EncryptedConfigurationValue("invalid-encrypted-value"), new GoCipher()); property.validate(ConfigSaveValidationContext.forChain(property)); assertThat(property.errors().isEmpty(), is(false)); assertThat(property.errors().getAllOn(ConfigurationProperty.ENCRYPTED_VALUE).contains( "Encrypted value for property with key 'secureKey' is invalid. This usually happens when the cipher text is modified to have an invalid value."), is(true)); }