/** * Validate current property value(s) and report any validation problems via the * {@link PropertyValidation} that is returned. * * @return {@link PropertyValidation} containing validation errors if found. */ public PropertyValidation validate() { PropertyValidation errors = PropertyValidation.createFor(this); validate(errors); return errors; }
/** * {@inheritDoc} */ @Override public SingleProperty<?> forLogicalname(String propertyLogicalName) { for (AbstractProperty property : singleProperties) { SingleProperty<?> returnProperty = property.forLogicalname(propertyLogicalName); if (null != returnProperty) { return returnProperty; } } return null; }
/** * Returns <code>true</code> if at least one property in this section is marked as advanced, * <code>false</code> otherwise. * * @return Returns <code>true</code> if at least one property in this section is marked as * advanced, <code>false</code> otherwise. */ public boolean hasAdvancedProperties() { if (CollectionUtils.isNotEmpty(properties)) { for (AbstractProperty property : properties) { if (property.isAdvanced()) { return true; } } } return false; }
/** * Returns message for the {@link PropertyValidation}. * * @return Returns message for the {@link PropertyValidation}. */ public String getMessage() { StringBuilder stringBuilder = new StringBuilder(); if (this.hasErrors()) { stringBuilder.append("Property "); stringBuilder.append(this.getProperty().getName()); stringBuilder.append(" can not be validated. Validation test failed because of the following errors:\n"); for (ValidationError validationError : this.getErrors()) { stringBuilder.append("||- "); stringBuilder.append(validationError.getMessage()); } } else { stringBuilder.append("Property "); stringBuilder.append(this.getProperty().getName()); stringBuilder.append("validated without errors."); } return stringBuilder.toString(); }
for (AbstractProperty property : configuration.getAllProperties()) { if (!validationMap.containsKey(property)) { property.register(properties);
/** * Validates all properties in this configuration returning the map of containing the properties * that have validation errors. * * @return Map of properties with {@link PropertyValidation} containing errors. */ public Map<AbstractProperty, PropertyValidation> validate() { Map<AbstractProperty, PropertyValidation> validationMap = new HashMap<>(); for (AbstractProperty property : getAllProperties()) { PropertyValidation propertyValidation = property.validate(); if (propertyValidation.hasErrors()) { validationMap.put(property, propertyValidation); } } return validationMap; }
/** * Returns the {@link SingleProperty} with the given logical name in the configuration or * <code>null</code> if such does not exist. * * @param <T> * Type of property value. * * @param propertyLogicalName * Property logical name to search for. * @return {@link SingleProperty} or <code>null</code> */ @SuppressWarnings("unchecked") public <T> SingleProperty<T> forLogicalName(String propertyLogicalName) { for (AbstractProperty property : getAllProperties()) { SingleProperty<?> returnProperty = property.forLogicalname(propertyLogicalName); if (null != returnProperty) { return (SingleProperty<T>) returnProperty; } } return null; }
@Test public void validate() { when(propertyValidation1.hasErrors()).thenReturn(true); when(property1.validate()).thenReturn(propertyValidation1); when(propertyValidation2.hasErrors()).thenReturn(false); when(property2.validate()).thenReturn(propertyValidation2); Map<AbstractProperty, PropertyValidation> validateMap = configuration.validate(); assertThat(validateMap, hasEntry(property1, propertyValidation1)); assertThat(validateMap, not(hasKey(property2))); } }