Class ConfigValidator

java.lang.Object
org.jpos.core.ConfigValidator

public class ConfigValidator extends Object
Declarative configuration validation framework.

Provides a fluent API for defining validation rules for jPOS configuration properties.

Example usage:

ConfigValidator validator = new ConfigValidator()
    .required("bootstrap-servers")
    .required("app-id")
    .range("startup-timeout-seconds", 1, 3600)
    .range("max-retries", 0, 10)
    .nonEmpty("topic")
    .pattern("group-id", "^[a-zA-Z0-9._-]+$")
    .custom("processing-guarantee",
            v -> v.equals("at_least_once") || v.equals("exactly_once"),
            "must be 'at_least_once' or 'exactly_once'");

validator.validate(config);
Since:
3.0.2
  • Constructor Details

  • Method Details

    • required

      Validate that a property is present and non-empty.
      Parameters:
      key - the property key
      Returns:
      this validator for chaining
    • nonEmpty

      Validate that a property, if present, is non-empty.
      Parameters:
      key - the property key
      Returns:
      this validator for chaining
    • range

      public ConfigValidator range(String key, int min, int max)
      Validate that an integer property is within a specified range. Only validates if the property is present.
      Parameters:
      key - the property key
      min - minimum value (inclusive)
      max - maximum value (inclusive)
      Returns:
      this validator for chaining
    • rangeLong

      public ConfigValidator rangeLong(String key, long min, long max)
      Validate that a long property is within a specified range. Only validates if the property is present.
      Parameters:
      key - the property key
      min - minimum value (inclusive)
      max - maximum value (inclusive)
      Returns:
      this validator for chaining
    • rangeDouble

      public ConfigValidator rangeDouble(String key, double min, double max)
      Validate that a double property is within a specified range. Only validates if the property is present.
      Parameters:
      key - the property key
      min - minimum value (inclusive)
      max - maximum value (inclusive)
      Returns:
      this validator for chaining
    • pattern

      public ConfigValidator pattern(String key, String regex)
      Validate that a property matches a regex pattern. Only validates if the property is present.
      Parameters:
      key - the property key
      regex - the regular expression pattern
      Returns:
      this validator for chaining
    • custom

      public ConfigValidator custom(String key, Predicate<String> predicate, String errorMessage)
      Validate a property using a custom predicate. Only validates if the property is present.
      Parameters:
      key - the property key
      predicate - the validation predicate (returns true if valid)
      errorMessage - error message if validation fails
      Returns:
      this validator for chaining
    • requireAtLeastOne

      Validate that at least one of the specified properties is present.
      Parameters:
      keys - the property keys
      Returns:
      this validator for chaining
    • requireExactlyOne

      Validate that exactly one of the specified properties is present.
      Parameters:
      keys - the property keys
      Returns:
      this validator for chaining
    • validBoolean

      Validate that a boolean property has a valid value. Accepted values: true, false, yes, no, 1, 0 (case-insensitive). Only validates if the property is present.
      Parameters:
      key - the property key
      Returns:
      this validator for chaining
    • validate

      public void validate(Configuration config) throws ConfigurationException
      Validate the configuration.
      Parameters:
      config - the configuration to validate
      Throws:
      ConfigurationException - if validation fails