File tree Expand file tree Collapse file tree 6 files changed +75
-0
lines changed
integration-tests/hibernate-validator/src
java/io/quarkus/it/hibernate/validator
test/java/io/quarkus/it/hibernate/validator Expand file tree Collapse file tree 6 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 48
48
import io .quarkus .it .hibernate .validator .injection .InjectedRuntimeConstraintValidatorConstraint ;
49
49
import io .quarkus .it .hibernate .validator .injection .MyService ;
50
50
import io .quarkus .it .hibernate .validator .orm .TestEntity ;
51
+ import io .quarkus .it .hibernate .validator .xml .ValidationServiceBasedOnXmlConstraints ;
51
52
import io .quarkus .runtime .StartupEvent ;
52
53
53
54
@ Path ("/hibernate-validator/test" )
@@ -64,6 +65,9 @@ public class HibernateValidatorTestResource
64
65
@ Inject
65
66
EnhancedGreetingService enhancedGreetingService ;
66
67
68
+ @ Inject
69
+ ValidationServiceBasedOnXmlConstraints validationServiceBasedOnXmlConstraints ;
70
+
67
71
@ Inject
68
72
ZipCodeService zipCodeResource ;
69
73
@@ -341,6 +345,17 @@ public String testClockBasedConstraints() {
341
345
return result .build ();
342
346
}
343
347
348
+ @ GET
349
+ @ Path ("/constraints-defined-in-xml" )
350
+ @ Produces (MediaType .TEXT_PLAIN )
351
+ public String testConstraintsDefinedInXml () {
352
+ ResultBuilder result = new ResultBuilder ();
353
+
354
+ result .append (formatViolations (validationServiceBasedOnXmlConstraints .validateSomeMyXmlBean ()));
355
+
356
+ return result .build ();
357
+ }
358
+
344
359
private String formatViolations (Set <? extends ConstraintViolation <?>> violations ) {
345
360
if (violations .isEmpty ()) {
346
361
return "passed" ;
Original file line number Diff line number Diff line change
1
+ package io .quarkus .it .hibernate .validator .xml ;
2
+
3
+ public class MyXmlBean {
4
+ int id = 0 ;
5
+ String name ;
6
+ }
Original file line number Diff line number Diff line change
1
+ package io .quarkus .it .hibernate .validator .xml ;
2
+
3
+ import java .util .Set ;
4
+
5
+ import jakarta .enterprise .context .ApplicationScoped ;
6
+ import jakarta .inject .Inject ;
7
+ import jakarta .validation .ConstraintViolation ;
8
+ import jakarta .validation .Validator ;
9
+
10
+ @ ApplicationScoped
11
+ public class ValidationServiceBasedOnXmlConstraints {
12
+
13
+ @ Inject
14
+ Validator validator ;
15
+
16
+ public Set <ConstraintViolation <MyXmlBean >> validateSomeMyXmlBean () {
17
+ return validator .validate (new MyXmlBean ());
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <validation-config
3
+ xmlns =" https://jakarta.ee/xml/ns/validation/configuration"
4
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
5
+ xsi : schemaLocation =" https://jakarta.ee/xml/ns/validation/configuration https://jakarta.ee/xml/ns/validation/validation-configuration-3.0.xsd"
6
+ version =" 3.0" >
7
+ <constraint-mapping >META-INF/validation/constraints-my-xml-bean.xml</constraint-mapping >
8
+ </validation-config >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <constraint-mappings
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi : schemaLocation =" https://jakarta.ee/xml/ns/validation/mapping https://jakarta.ee/xml/ns/validation/validation-mapping-3.0.xsd"
5
+ xmlns =" https://jakarta.ee/xml/ns/validation/mapping" version =" 3.0" >
6
+
7
+ <bean class =" io.quarkus.it.hibernate.validator.xml.MyXmlBean" >
8
+ <field name =" id" >
9
+ <constraint annotation =" jakarta.validation.constraints.Positive" />
10
+ </field >
11
+ <field name =" name" >
12
+ <constraint annotation =" jakarta.validation.constraints.NotNull" />
13
+ </field >
14
+ </bean >
15
+ </constraint-mappings >
Original file line number Diff line number Diff line change @@ -542,4 +542,16 @@ void testClockBasedConstraints() {
542
542
.then ()
543
543
.body (is ("passed" ));
544
544
}
545
+
546
+ @ Test
547
+ void testConstraintsDefinedInXml () {
548
+ RestAssured .given ()
549
+ .when ()
550
+ .get ("/hibernate-validator/test/constraints-defined-in-xml" )
551
+ .then ()
552
+ .statusCode (200 )
553
+ .body (containsString ("failed" ),
554
+ containsString ("id (must be greater than 0)" ),
555
+ containsString ("name (must not be null)" ));
556
+ }
545
557
}
You can’t perform that action at this time.
0 commit comments