use of javax.validation.ConstraintDeclarationException in project validators by xlate.
the class ExpressionValidatorTest method testNonBooleanInWhenCondition.
@Test
void testNonBooleanInWhenCondition() {
Mockito.when(annotation.value()).thenReturn("self.earlier lt self.later");
Mockito.when(annotation.when()).thenReturn("'0'");
Map<String, Date> data = new HashMap<>();
data.put("earlier", new Date(1));
data.put("later", new Date());
target.initialize(annotation);
ConstraintDeclarationException ex = assertThrows(ConstraintDeclarationException.class, () -> {
target.isValid(data, context);
});
Assertions.assertTrue(ex.getMessage().contains("`'0'` does not evaluate to Boolean"));
}
use of javax.validation.ConstraintDeclarationException in project validators by xlate.
the class JdbcStatementValidatorTest method testSetParametersSQLException.
@Test
void testSetParametersSQLException() throws SQLException {
TestSetParametersSQLException self = new TestSetParametersSQLException();
String[] parameters = { "self" };
PreparedStatement statement = Mockito.mock(PreparedStatement.class);
Mockito.doThrow(java.sql.SQLException.class).when(statement).setObject(1, self);
ELProcessor processor = new ELProcessor();
processor.defineBean("self", self);
ConstraintDeclarationException ex = assertThrows(ConstraintDeclarationException.class, () -> {
target.setParameters(processor, parameters, statement);
});
Throwable cause = ex.getCause();
assertNotNull(cause);
assertEquals(java.sql.SQLException.class, cause.getClass());
}
use of javax.validation.ConstraintDeclarationException in project validators by xlate.
the class DateTimeValidator method initialize.
@Override
public void initialize(DateTime constraintAnnotation) {
formatterType = constraintAnnotation.parserType();
final DateTime annotation = constraintAnnotation;
final String[] patterns = annotation.patterns();
if (patterns.length == 0) {
throw new ConstraintDeclarationException("At least one DateFormat pattern must be provided.");
}
if (formatterType == ParserType.JAVA_TEXT) {
formatters = Arrays.stream(patterns).map(p -> toJavaTextDateFormat(p, annotation)).collect(Collectors.toList());
} else {
formatters = Arrays.stream(patterns).map(p -> toJavaTimeDateTimeFormatter(p, annotation)).collect(Collectors.toList());
}
}
use of javax.validation.ConstraintDeclarationException in project validators by xlate.
the class DateTimeValidatorTest method testMissingPatterns.
@Test
void testMissingPatterns() {
Mockito.when(annotation.patterns()).thenReturn(new String[0]);
ConstraintDeclarationException ex = assertThrows(ConstraintDeclarationException.class, () -> {
target.initialize(annotation);
});
assertEquals("At least one DateFormat pattern must be provided.", ex.getMessage());
}
use of javax.validation.ConstraintDeclarationException in project validators by xlate.
the class DateTimeValidatorTest method testInvalidPattern.
@ParameterizedTest
@ValueSource(strings = { "JAVA_TEXT", "JAVA_TIME" })
void testInvalidPattern(DateTime.ParserType type) {
Mockito.when(annotation.parserType()).thenReturn(type);
Mockito.when(annotation.patterns()).thenReturn(new String[] { " NOT A VALID DATE PATTERN " });
ConstraintDeclarationException ex = assertThrows(ConstraintDeclarationException.class, () -> {
target.initialize(annotation);
});
assertTrue(ex.getMessage().startsWith("Invalid format pattern "));
}
Aggregations