-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23877 from gsmet/hv-expression-language
Hibernate Validator - Allow setting the expression language feature level
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...ava/io/quarkus/hibernate/validator/test/ConstraintExpressionLanguageFeatureLevelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.quarkus.hibernate.validator.test; | ||
|
||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import java.util.Set; | ||
|
||
import javax.inject.Inject; | ||
import javax.validation.Constraint; | ||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
import javax.validation.ConstraintViolation; | ||
import javax.validation.Payload; | ||
import javax.validation.Validator; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ConstraintExpressionLanguageFeatureLevelTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest().setArchiveProducer(() -> ShrinkWrap | ||
.create(JavaArchive.class) | ||
.addClasses(BeanMethodsConstraint.class, BeanMethodsConstraintStringValidator.class, BeanMethodsBean.class) | ||
.add(new StringAsset( | ||
"quarkus.hibernate-validator.expression-language.constraint-expression-feature-level=bean-methods"), | ||
"application.properties")); | ||
|
||
@Inject | ||
Validator validator; | ||
|
||
@Test | ||
public void testConstraintExpressionFeatureLevel() { | ||
Set<ConstraintViolation<BeanMethodsBean>> violations = validator.validate(new BeanMethodsBean()); | ||
assertEquals("Method execution: a", violations.iterator().next().getMessage()); | ||
} | ||
|
||
@Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@Constraint(validatedBy = { BeanMethodsConstraintStringValidator.class }) | ||
private @interface BeanMethodsConstraint { | ||
String message() default "Method execution: ${'aaaa'.substring(0, 1)}"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} | ||
|
||
public static class BeanMethodsConstraintStringValidator implements ConstraintValidator<BeanMethodsConstraint, String> { | ||
|
||
@Override | ||
public boolean isValid(String value, ConstraintValidatorContext context) { | ||
return false; | ||
} | ||
} | ||
|
||
public static class BeanMethodsBean { | ||
|
||
@BeanMethodsConstraint | ||
public String value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters