Had a quick look, the VF type we actually get in the test is LazyValidatorFactory which basically is good news, as it means WFLY-1705 works as expected.
I think instead of getting the VF from the EM property map (which isn't portable as the comment in the code says) and asserting its type, we e.g. could use a custom XML constraint mapping, persist a test entity and assert the resulting violations raised by JPA lifecycle validation. That way we're sure validation triggered via JPA obeys to the configuration in META-INF/validation.xml (that's what I think is the purpose of this test).
Btw. there is another issue with using a custom VF with no-op methods during the test. On the console I see this stack trace when running CustomValidatorFactoryInPersistenceUnitIT (WARN level, i.e. no failure):
09:32:14,502 WARN [org.hibernate.cfg.beanvalidation.TypeSafeActivator] (ServerService Thread Pool – 21) HHH000274: Unable to apply constraints on DDL for org.hibernate.validator.integration.wildfly.User: java.lang.UnsupportedOperationException at org.hibernate.validator.integration.util.MyValidator.getConstraintsForClass(MyValidator.java:47) [dummy-bean-validation-provider.jar:] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:207) [hibernate-core-4.3.0.Beta4.jar:4.3.0.Beta4] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:191) [hibernate-core-4.3.0.Beta4.jar:4.3.0.Beta4] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:159) [hibernate-core-4.3.0.Beta4.jar:4.3.0.Beta4] at org.hibernate.cfg.beanvalidation.TypeSafeActivator.activate(TypeSafeActivator.java:111) [hibernate-core-4.3.0.Beta4.jar:4.3.0.Beta4] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_45] at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_45] at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:150) [hibernate-core-4.3.0.Beta4.jar:4.3.0.Beta4] at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310) [hibernate-core-4.3.0.Beta4.jar:4.3.0.Beta4] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1837) [hibernate-core-4.3.0.Beta4.jar:4.3.0.Beta4] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:854) [hibernate-entitymanager-4.3.0.Beta4.jar:4.3.0.Beta4] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:847) [hibernate-entitymanager-4.3.0.Beta4.jar:4.3.0.Beta4] at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:396) [hibernate-core-4.3.0.Beta4.jar:4.3.0.Beta4] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:846) [hibernate-entitymanager-4.3.0.Beta4.jar:4.3.0.Beta4] ...
The test registers a custom ValidatorFactory whose methods all throw an UnsupportedOperationException. The exception is raised when Hibernate access this validator to retrieve constraint metadata in order to generate DDL.
The exception is raised when Hibernate access this validator to retrieve constraint metadata in order to generate DDL. This issue will also go away when doing the assertion on a constraint violation.
|