use of jakarta.validation.constraints.Email in project jsonschema-generator by victools.
the class JakartaValidationModule method resolveStringPattern.
/**
* Determine a given text type's pattern.
*
* @param member the field or method to check
* @return specified pattern (or null)
* @see Pattern
*/
protected String resolveStringPattern(MemberScope<?, ?> member) {
if (member.getType().isInstanceOf(CharSequence.class)) {
Pattern patternAnnotation = this.getAnnotationFromFieldOrGetter(member, Pattern.class, Pattern::groups);
if (patternAnnotation != null) {
// @Pattern annotation was found, return its (mandatory) regular expression
return patternAnnotation.regexp();
}
Email emailAnnotation = this.getAnnotationFromFieldOrGetter(member, Email.class, Email::groups);
if (emailAnnotation != null && !".*".equals(emailAnnotation.regexp())) {
// non-default regular expression on @Email annotation should also be considered
return emailAnnotation.regexp();
}
}
return null;
}
use of jakarta.validation.constraints.Email in project hibernate-validator by hibernate.
the class PredefinedScopeValidatorFactoryTest method testUnavailableInitializedLocale.
@Test
public void testUnavailableInitializedLocale() {
Locale defaultLocale = Locale.getDefault();
try {
Locale georgianLocale = new Locale("ka", "GE");
Locale.setDefault(georgianLocale);
Validator validator = getValidatorWithInitializedLocale(georgianLocale);
Set<ConstraintViolation<Bean>> violations = validator.validate(new Bean("", "invalid"));
assertThat(violations).containsOnlyViolations(violationOf(Email.class).withProperty("email").withMessage("must be a well-formed email address"));
} finally {
Locale.setDefault(defaultLocale);
}
}
use of jakarta.validation.constraints.Email in project hibernate-validator by hibernate.
the class PredefinedScopeValidatorFactoryTest method testUninitializedLocale.
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000250:.*")
public void testUninitializedLocale() {
Locale defaultLocale = Locale.getDefault();
try {
Locale.setDefault(Locale.FRANCE);
ValidatorFactory validatorFactory = getValidatorFactoryWithInitializedLocale(Locale.ENGLISH);
Validator validator = validatorFactory.usingContext().messageInterpolator(new MessageInterpolator() {
@Override
public String interpolate(String messageTemplate, Context context, Locale locale) {
return validatorFactory.getMessageInterpolator().interpolate(messageTemplate, context, locale);
}
@Override
public String interpolate(String messageTemplate, Context context) {
return validatorFactory.getMessageInterpolator().interpolate(messageTemplate, context, Locale.GERMAN);
}
}).getValidator();
Set<ConstraintViolation<Bean>> violations = validator.validate(new Bean("", "invalid"));
assertThat(violations).containsOnlyViolations(violationOf(Email.class).withProperty("email").withMessage("doit être une adresse électronique syntaxiquement correcte"));
} finally {
Locale.setDefault(defaultLocale);
}
}
use of jakarta.validation.constraints.Email in project hibernate-validator by hibernate.
the class PredefinedScopeValidatorFactoryTest method testExistingInitializedLocale.
@Test
public void testExistingInitializedLocale() {
Locale defaultLocale = Locale.getDefault();
try {
Locale.setDefault(Locale.FRANCE);
Validator validator = getValidatorWithInitializedLocale(Locale.FRANCE);
Set<ConstraintViolation<Bean>> violations = validator.validate(new Bean("", "invalid"));
assertThat(violations).containsOnlyViolations(violationOf(Email.class).withProperty("email").withMessage("doit être une adresse électronique syntaxiquement correcte"));
} finally {
Locale.setDefault(defaultLocale);
}
}
Aggregations