Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/validation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ Quarkus provides a default `ValidatorFactory` that you can customize using confi
This `ValidatorFactory` is carefully initialized to support native executables
using a bootstrap that is Quarkus-specific.

Creating a `ValidatorFactory` by yourself it not supported in native executables
Creating a `ValidatorFactory` by yourself is not supported in native executables
and if you try to do so,
you will get an error similar to `jakarta.validation.NoProviderFoundException: Unable to create a Configuration, because no
Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public String testCustomClassLevelConstraint() {
ResultBuilder result = new ResultBuilder();

result.append(formatViolations(validator.validate(new MyOtherBean(null))));
result.append(formatViolations(validator.validate(new MyOtherBean("fail"))));
result.append(formatViolations(validator.validate(new MyOtherBean("name"))));

return result.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.it.hibernate.validator.custom;

@MyServiceLoadedConstraint
@MyCustomConstraint
public class MyOtherBean {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.it.hibernate.validator.custom;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

@Target({ ElementType.TYPE_USE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {})
public @interface MyServiceLoadedConstraint {
String message() default "{MyServiceLoadedConstraint.message}";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.it.hibernate.validator.custom;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class MyServiceLoadedConstraintValidator implements ConstraintValidator<MyServiceLoadedConstraint, MyOtherBean> {

@Override
public boolean isValid(MyOtherBean value, ConstraintValidatorContext context) {
if (value == null || value.getName() == null) {
return true;
}
return !"fail".equalsIgnoreCase(value.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.it.hibernate.validator.custom.MyServiceLoadedConstraintValidator
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ MyCustomConstraint.message = invalid MyOtherBean
InjectedConstraintValidatorConstraint.message = InjectedConstraintValidatorConstraint violation
InjectedRuntimeConstraintValidatorConstraint.message = InjectedRuntimeConstraintValidatorConstraint violation
pattern.message=Value is not in line with the pattern
MyServiceLoadedConstraint.message = service-loaded invalid MyOtherBean
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void testBasicFeatures() throws Exception {
public void testCustomClassLevelConstraint() throws Exception {
StringBuilder expected = new StringBuilder();
expected.append("failed: (invalid MyOtherBean)").append("\n");
expected.append("failed: (service-loaded invalid MyOtherBean)").append("\n");
expected.append("passed");

RestAssured.when()
Expand Down
Loading