Search in sources :

Example 1 with ValidatorFactory

use of jakarta.validation.ValidatorFactory in project wicket by apache.

the class DefaultPropertyResolverTest method testBundleKeysResolution.

/**
 * Test custom bundle mechanism of jsr 303
 *
 * https://issues.apache.org/jira/browse/WICKET-5654
 *
 * @throws Exception
 */
@Test
void testBundleKeysResolution() throws Exception {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    DefaultViolationTranslator translator = new DefaultViolationTranslator();
    // test with a too short password
    BeanWithPassword bean = new BeanWithPassword("short");
    Set<ConstraintViolation<BeanWithPassword>> constraintViolations = validator.validate(bean);
    assertEquals(1, constraintViolations.size());
    @SuppressWarnings("unchecked") ConstraintViolation<BeanWithPassword> shortViolation = (ConstraintViolation<BeanWithPassword>) constraintViolations.toArray()[0];
    ValidationError error = translator.convert(shortViolation);
    checkErrorBundleKeys(error, DEFAULT_BUNDLE_KEY + ".String", DEFAULT_BUNDLE_KEY);
    // test with a password containing non-word chars
    bean.setPassword("notWord&%$£");
    constraintViolations = validator.validate(bean);
    assertEquals(1, constraintViolations.size());
    @SuppressWarnings("unchecked") ConstraintViolation<BeanWithPassword> nonWordviolation = (ConstraintViolation<BeanWithPassword>) constraintViolations.toArray()[0];
    error = translator.convert(nonWordviolation);
    checkErrorBundleKeys(error, CUSTOM_BUNDLE_KEY + ".String", CUSTOM_BUNDLE_KEY, DEFAULT_BUNDLE_KEY + ".String", DEFAULT_BUNDLE_KEY);
    // test with a valid password
    bean.setPassword("aValidPassword1234");
    constraintViolations = validator.validate(bean);
    assertEquals(0, constraintViolations.size());
}
Also used : ValidatorFactory(jakarta.validation.ValidatorFactory) ConstraintViolation(jakarta.validation.ConstraintViolation) ValidationError(org.apache.wicket.validation.ValidationError) Validator(jakarta.validation.Validator) Test(org.junit.jupiter.api.Test)

Example 2 with ValidatorFactory

use of jakarta.validation.ValidatorFactory in project spring-cloud-config by spring-cloud.

the class SshPropertyValidatorTest method setUpValidator.

@BeforeClass
public static void setUpValidator() {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    validator = factory.getValidator();
}
Also used : ValidatorFactory(jakarta.validation.ValidatorFactory) BeforeClass(org.junit.BeforeClass)

Example 3 with ValidatorFactory

use of jakarta.validation.ValidatorFactory in project minijax by minijax.

the class CarTest method setUpValidator.

@BeforeAll
public static void setUpValidator() {
    final ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    validator = factory.getValidator();
}
Also used : ValidatorFactory(jakarta.validation.ValidatorFactory) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with ValidatorFactory

use of jakarta.validation.ValidatorFactory in project minijax by minijax.

the class CarTest method setUpValidator.

@BeforeAll
public static void setUpValidator() {
    final ValidatorFactory factory = Validation.byProvider(MinijaxValidationProvider.class).configure().buildValidatorFactory();
    validator = factory.getValidator();
}
Also used : ValidatorFactory(jakarta.validation.ValidatorFactory) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with ValidatorFactory

use of jakarta.validation.ValidatorFactory in project minijax by minijax.

the class CarTest method setUpValidator.

@BeforeAll
public static void setUpValidator() {
    final ValidatorFactory factory = Validation.byProvider(MinijaxValidationProvider.class).configure().buildValidatorFactory();
    validator = factory.getValidator();
}
Also used : ValidatorFactory(jakarta.validation.ValidatorFactory) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

ValidatorFactory (jakarta.validation.ValidatorFactory)161 Validator (jakarta.validation.Validator)79 Test (org.testng.annotations.Test)76 HibernateValidator (org.hibernate.validator.HibernateValidator)74 ConstraintViolation (jakarta.validation.ConstraintViolation)41 TestForIssue (org.hibernate.validator.testutil.TestForIssue)30 HibernateValidatorConfiguration (org.hibernate.validator.HibernateValidatorConfiguration)24 ConstraintValidator (jakarta.validation.ConstraintValidator)23 BeforeClass (org.junit.BeforeClass)23 Test (org.junit.Test)17 MessageInterpolator (jakarta.validation.MessageInterpolator)14 HibernateValidatorFactory (org.hibernate.validator.HibernateValidatorFactory)14 NotNull (jakarta.validation.constraints.NotNull)13 ConstraintValidatorFactory (jakarta.validation.ConstraintValidatorFactory)9 Locale (java.util.Locale)7 BeforeTest (org.testng.annotations.BeforeTest)7 ValidationException (jakarta.validation.ValidationException)6 PredefinedScopeHibernateValidator (org.hibernate.validator.PredefinedScopeHibernateValidator)6 BeforeAll (org.junit.jupiter.api.BeforeAll)6 BeforeMethod (org.testng.annotations.BeforeMethod)6