/** * Updates the value of the property with the given PropertyDescriptor to * the specified value IF and ONLY IF the value is valid according to the * descriptor's validator. Otherwise, the property value is not updated. In * either case, the ValidationResult is returned, indicating whether or not * the property is valid * * @param descriptor of property to modify * @param value new value * @return result */ public ValidationResult setProperty(final PropertyDescriptor descriptor, final String value) { requireNonNull(descriptor); requireNonNull(value, "Cannot set property to null value; if the intent is to remove the property, call removeProperty instead"); final PropertyDescriptor fullyPopulatedDescriptor = component.getPropertyDescriptor(descriptor.getName()); final ValidationResult result = fullyPopulatedDescriptor.validate(value, new MockValidationContext(this, stateManager, variableRegistry)); String oldValue = properties.put(fullyPopulatedDescriptor, value); if (oldValue == null) { oldValue = fullyPopulatedDescriptor.getDefaultValue(); } if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) { component.onPropertyModified(fullyPopulatedDescriptor, oldValue, value); } return result; }
@Override public ValidationResult setProperty(final ControllerService service, final PropertyDescriptor property, final String value) { final MockStateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier()); if (serviceStateManager == null) { throw new IllegalStateException("Controller service " + service + " has not been added to this TestRunner via the #addControllerService method"); } final ControllerServiceConfiguration configuration = getConfigToUpdate(service); final Map<PropertyDescriptor, String> curProps = configuration.getProperties(); final Map<PropertyDescriptor, String> updatedProps = new HashMap<>(curProps); final ValidationContext validationContext = new MockValidationContext(context, serviceStateManager, variableRegistry).getControllerServiceValidationContext(service); final ValidationResult validationResult = property.validate(value, validationContext); final String oldValue = updatedProps.get(property); updatedProps.put(property, value); configuration.setProperties(updatedProps); if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) { service.onPropertyModified(property, oldValue, value); } return validationResult; }
@Override public ValidationResult setProperty(final ControllerService service, final PropertyDescriptor property, final String value) { final MockStateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier()); if (serviceStateManager == null) { throw new IllegalStateException("Controller service " + service + " has not been added to this TestRunner via the #addControllerService method"); } final ControllerServiceConfiguration configuration = getConfigToUpdate(service); final Map<PropertyDescriptor, String> curProps = configuration.getProperties(); final Map<PropertyDescriptor, String> updatedProps = new HashMap<>(curProps); final ValidationContext validationContext = new MockValidationContext(context, serviceStateManager, variableRegistry).getControllerServiceValidationContext(service); final ValidationResult validationResult = property.validate(value, validationContext); final String oldValue = updatedProps.get(property); updatedProps.put(property, value); configuration.setProperties(updatedProps); if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) { service.onPropertyModified(property, oldValue, value); } return validationResult; }
/** * Updates the value of the property with the given PropertyDescriptor to * the specified value IF and ONLY IF the value is valid according to the * descriptor's validator. Otherwise, the property value is not updated. In * either case, the ValidationResult is returned, indicating whether or not * the property is valid * * @param descriptor of property to modify * @param value new value * @return result */ public ValidationResult setProperty(final PropertyDescriptor descriptor, final String value) { requireNonNull(descriptor); requireNonNull(value, "Cannot set property to null value; if the intent is to remove the property, call removeProperty instead"); final PropertyDescriptor fullyPopulatedDescriptor = component.getPropertyDescriptor(descriptor.getName()); final ValidationResult result = fullyPopulatedDescriptor.validate(value, new MockValidationContext(this, stateManager, variableRegistry)); String oldValue = properties.put(fullyPopulatedDescriptor, value); if (oldValue == null) { oldValue = fullyPopulatedDescriptor.getDefaultValue(); } if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) { component.onPropertyModified(fullyPopulatedDescriptor, oldValue, value); } return result; }