Class ConfigValidator
java.lang.Object
org.jpos.core.ConfigValidator
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionValidate a property using a custom predicate.Validate that a property, if present, is non-empty.Validate that a property matches a regex pattern.Validate that an integer property is within a specified range.rangeDouble(String key, double min, double max) Validate that a double property is within a specified range.Validate that a long property is within a specified range.requireAtLeastOne(String... keys) Validate that at least one of the specified properties is present.Validate that a property is present and non-empty.requireExactlyOne(String... keys) Validate that exactly one of the specified properties is present.voidvalidate(Configuration config) Validate the configuration.validBoolean(String key) Validate that a boolean property has a valid value.
-
Constructor Details
-
ConfigValidator
public ConfigValidator()
-
-
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
Validate that an integer property is within a specified range. Only validates if the property is present.- Parameters:
key- the property keymin- minimum value (inclusive)max- maximum value (inclusive)- Returns:
- this validator for chaining
-
rangeLong
Validate that a long property is within a specified range. Only validates if the property is present.- Parameters:
key- the property keymin- minimum value (inclusive)max- maximum value (inclusive)- Returns:
- this validator for chaining
-
rangeDouble
Validate that a double property is within a specified range. Only validates if the property is present.- Parameters:
key- the property keymin- minimum value (inclusive)max- maximum value (inclusive)- Returns:
- this validator for chaining
-
pattern
Validate that a property matches a regex pattern. Only validates if the property is present.- Parameters:
key- the property keyregex- the regular expression pattern- Returns:
- this validator for chaining
-
custom
Validate a property using a custom predicate. Only validates if the property is present.- Parameters:
key- the property keypredicate- 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
Validate the configuration.- Parameters:
config- the configuration to validate- Throws:
ConfigurationException- if validation fails
-