Search in sources :

Example 1 with Configuration

use of jakarta.validation.Configuration in project hibernate-validator by hibernate.

the class URLValidatorTest method url_validator_using_regexp_only_can_be_configured_via_xml.

@Test
@TestForIssue(jiraKey = "HV-920")
public void url_validator_using_regexp_only_can_be_configured_via_xml() {
    Configuration config = ValidatorUtil.getConfiguration();
    InputStream mappingStream = URLValidatorTest.class.getResourceAsStream("mapping.xml");
    config.addMapping(mappingStream);
    DelegatingConstraintValidatorFactory constraintValidatorFactory = new DelegatingConstraintValidatorFactory(config.getDefaultConstraintValidatorFactory());
    config.constraintValidatorFactory(constraintValidatorFactory);
    assertDefaultURLConstraintValidatorOverridden(config, constraintValidatorFactory);
}
Also used : HibernateValidatorConfiguration(org.hibernate.validator.HibernateValidatorConfiguration) Configuration(jakarta.validation.Configuration) InputStream(java.io.InputStream) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 2 with Configuration

use of jakarta.validation.Configuration in project hibernate-validator by hibernate.

the class ValidatorFactoryBean method createValidationXmlValueExtractors.

private Set<ValueExtractorDescriptor> createValidationXmlValueExtractors(Configuration<?> config) {
    BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
    Set<String> valueExtractorFqcns = bootstrapConfiguration.getValueExtractorClassNames();
    @SuppressWarnings("unchecked") Set<ValueExtractorDescriptor> valueExtractorDescriptors = valueExtractorFqcns.stream().map(fqcn -> createInstance((Class<? extends ValueExtractor<?>>) run(LoadClass.action(fqcn, null)))).map(ve -> new ValueExtractorDescriptor(ve)).collect(Collectors.toSet());
    return valueExtractorDescriptors;
}
Also used : GetClassLoader(org.hibernate.validator.internal.util.privilegedactions.GetClassLoader) ConstraintValidatorFactory(jakarta.validation.ConstraintValidatorFactory) ValueExtractorDescriptor(org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor) BeanNames(org.hibernate.validator.cdi.spi.BeanNames) ClassHierarchyHelper(org.hibernate.validator.internal.util.classhierarchy.ClassHierarchyHelper) ApplicationScoped(jakarta.enterprise.context.ApplicationScoped) TraversableResolver(jakarta.validation.TraversableResolver) Function(java.util.function.Function) Instance(jakarta.enterprise.inject.Instance) ValidatorFactory(jakarta.validation.ValidatorFactory) Bean(jakarta.enterprise.inject.spi.Bean) HashSet(java.util.HashSet) ValueExtractor(jakarta.validation.valueextraction.ValueExtractor) CollectionHelper.newHashSet(org.hibernate.validator.internal.util.CollectionHelper.newHashSet) GetInstancesFromServiceLoader(org.hibernate.validator.internal.util.privilegedactions.GetInstancesFromServiceLoader) Map(java.util.Map) PassivationCapable(jakarta.enterprise.inject.spi.PassivationCapable) CollectionHelper(org.hibernate.validator.internal.util.CollectionHelper) BeanManager(jakarta.enterprise.inject.spi.BeanManager) Validation(jakarta.validation.Validation) BootstrapConfiguration(jakarta.validation.BootstrapConfiguration) BeanMetaDataClassNormalizer(org.hibernate.validator.metadata.BeanMetaDataClassNormalizer) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) NamedLiteral(jakarta.enterprise.inject.literal.NamedLiteral) LoadClass(org.hibernate.validator.internal.util.privilegedactions.LoadClass) Set(java.util.Set) CreationalContext(jakarta.enterprise.context.spi.CreationalContext) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) ParameterNameProvider(jakarta.validation.ParameterNameProvider) List(java.util.List) ClockProvider(jakarta.validation.ClockProvider) MessageInterpolator(jakarta.validation.MessageInterpolator) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) HibernateValidatorConfiguration(org.hibernate.validator.HibernateValidatorConfiguration) AccessController(java.security.AccessController) Collections(java.util.Collections) IgnoreForbiddenApisErrors(org.hibernate.validator.internal.IgnoreForbiddenApisErrors) Configuration(jakarta.validation.Configuration) ValueExtractorDescriptor(org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor) BootstrapConfiguration(jakarta.validation.BootstrapConfiguration) LoadClass(org.hibernate.validator.internal.util.privilegedactions.LoadClass) ValueExtractor(jakarta.validation.valueextraction.ValueExtractor)

Example 3 with Configuration

use of jakarta.validation.Configuration in project beanvalidation-tck by eclipse-ee4j.

the class ConfigurationTest method testProviderUnderTestDefinesSubInterfaceOfConfiguration.

@Test
@SpecAssertion(section = Sections.VALIDATIONAPI_BOOTSTRAPPING_CONFIGURATION, id = "l")
public void testProviderUnderTestDefinesSubInterfaceOfConfiguration() {
    boolean foundSubinterfaceOfConfiguration = false;
    Type[] types = TestUtil.getValidationProviderUnderTest().getClass().getGenericInterfaces();
    for (Type type : types) {
        if (type instanceof ParameterizedType) {
            ParameterizedType paramType = (ParameterizedType) type;
            Type[] typeArguments = paramType.getActualTypeArguments();
            for (Type typeArgument : typeArguments) {
                if (typeArgument instanceof Class && Configuration.class.isAssignableFrom((Class<?>) typeArgument)) {
                    foundSubinterfaceOfConfiguration = true;
                }
            }
        }
    }
    assertTrue(foundSubinterfaceOfConfiguration, "Could not find subinterface of Configuration");
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Configuration(jakarta.validation.Configuration) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 4 with Configuration

use of jakarta.validation.Configuration in project resteasy by resteasy.

the class AbstractValidatorContextResolver method getValidatorFactory.

// this used to be initialized in a static block, but I was having trouble class loading the context resolver in some
// environments.  So instead of failing and logging a warning when the resolver is instantiated at deploy time
// we log any validation warning when trying to obtain the ValidatorFactory.
ValidatorFactory getValidatorFactory() {
    ValidatorFactory tmpValidatorFactory = validatorFactory;
    if (tmpValidatorFactory == null) {
        synchronized (RD_LOCK) {
            tmpValidatorFactory = validatorFactory;
            if (tmpValidatorFactory == null) {
                try {
                    // Also look up java:comp/env
                    Context context = new InitialContext();
                    validatorFactory = tmpValidatorFactory = ValidatorFactory.class.cast(context.lookup("java:comp/ValidatorFactory"));
                    LogMessages.LOGGER.debug(Messages.MESSAGES.usingValidatorFactorySupportsCDI(validatorFactory));
                } catch (NamingException e) {
                    LogMessages.LOGGER.info(Messages.MESSAGES.usingValidatorFactoryDoesNotSupportCDI());
                    Configuration<?> config = Validation.byDefaultProvider().configure();
                    validatorFactory = tmpValidatorFactory = config.buildValidatorFactory();
                }
            }
        }
    }
    return tmpValidatorFactory;
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) ValidatorFactory(jakarta.validation.ValidatorFactory) BootstrapConfiguration(jakarta.validation.BootstrapConfiguration) Configuration(jakarta.validation.Configuration) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 5 with Configuration

use of jakarta.validation.Configuration in project today-framework by TAKETODAY.

the class BeanValidationConfig method hibernateValidator.

@MissingBean
@SuppressWarnings({ "unchecked", "rawtypes" })
@ConditionalOnClass(name = "org.hibernate.validator.HibernateValidator")
DefaultJavaxValidator hibernateValidator(ApplicationContext context) {
    final Class<ValidationProvider> aClass = ClassUtils.load("org.hibernate.validator.HibernateValidator");
    final Configuration hibernateValidatorConfig = Validation.byProvider(aClass).configure().messageInterpolator(new ContextMessageInterpolator(context)).parameterNameProvider(new ContextParameterNameProvider());
    return new DefaultJavaxValidator(hibernateValidatorConfig);
}
Also used : ValidationProvider(jakarta.validation.spi.ValidationProvider) Configuration(jakarta.validation.Configuration) ConditionalOnClass(cn.taketoday.context.condition.ConditionalOnClass) MissingBean(cn.taketoday.context.annotation.MissingBean)

Aggregations

Configuration (jakarta.validation.Configuration)5 BootstrapConfiguration (jakarta.validation.BootstrapConfiguration)2 ValidatorFactory (jakarta.validation.ValidatorFactory)2 Type (java.lang.reflect.Type)2 HibernateValidatorConfiguration (org.hibernate.validator.HibernateValidatorConfiguration)2 Test (org.testng.annotations.Test)2 MissingBean (cn.taketoday.context.annotation.MissingBean)1 ConditionalOnClass (cn.taketoday.context.condition.ConditionalOnClass)1 ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)1 CreationalContext (jakarta.enterprise.context.spi.CreationalContext)1 Instance (jakarta.enterprise.inject.Instance)1 NamedLiteral (jakarta.enterprise.inject.literal.NamedLiteral)1 Bean (jakarta.enterprise.inject.spi.Bean)1 BeanManager (jakarta.enterprise.inject.spi.BeanManager)1 InjectionPoint (jakarta.enterprise.inject.spi.InjectionPoint)1 PassivationCapable (jakarta.enterprise.inject.spi.PassivationCapable)1 ClockProvider (jakarta.validation.ClockProvider)1 ConstraintValidatorFactory (jakarta.validation.ConstraintValidatorFactory)1 MessageInterpolator (jakarta.validation.MessageInterpolator)1 ParameterNameProvider (jakarta.validation.ParameterNameProvider)1