use of jakarta.validation.ValidatorFactory in project beanvalidation-tck by eclipse-ee4j.
the class TraversableResolverTest method testCorrectCallsToIsReachableAndIsCascadableForReturnValueValidation.
@Test
@SpecAssertions({ @SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_VALIDATIONROUTINE_TRAVERSABLE, id = "d"), @SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_VALIDATIONROUTINE_TRAVERSABLE, id = "e"), @SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_VALIDATIONROUTINE_TRAVERSABLE, id = "f"), @SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_VALIDATIONROUTINE_TRAVERSABLE, id = "g"), @SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_VALIDATIONROUTINE_TRAVERSABLE, id = "h"), @SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_VALIDATIONROUTINE_TRAVERSABLE, id = "k"), @SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_VALIDATIONROUTINE_TRAVERSABLE, id = "l") })
public void testCorrectCallsToIsReachableAndIsCascadableForReturnValueValidation() throws Exception {
Suit suit = new Suit();
suit.setTrousers(new Trousers());
suit.setJacket(new Jacket());
suit.setSize(3333);
suit.getTrousers().setLength(32321);
suit.getJacket().setWidth(432432);
Set<Call> expectedReachCalls = new HashSet<Call>();
Set<Call> expectedCascadeCalls = new HashSet<Call>();
expectedReachCalls.add(new Call(suit, "size", Gentleman.class, ElementType.FIELD, new String[] { "undress", RETURN_VALUE_NODE_NAME }));
expectedReachCalls.add(new Call(suit, "trousers", Gentleman.class, ElementType.FIELD, new String[] { "undress", RETURN_VALUE_NODE_NAME }));
expectedCascadeCalls.add(new Call(suit, "trousers", Gentleman.class, ElementType.FIELD, new String[] { "undress", RETURN_VALUE_NODE_NAME }));
expectedReachCalls.add(new Call(suit.getTrousers(), "length", Gentleman.class, ElementType.FIELD, new String[] { "undress", RETURN_VALUE_NODE_NAME, "trousers" }));
expectedReachCalls.add(new Call(suit, "jacket", Gentleman.class, ElementType.METHOD, new String[] { "undress", RETURN_VALUE_NODE_NAME }));
expectedCascadeCalls.add(new Call(suit, "jacket", Gentleman.class, ElementType.METHOD, new String[] { "undress", RETURN_VALUE_NODE_NAME }));
expectedReachCalls.add(new Call(suit.getJacket(), "width", Gentleman.class, ElementType.METHOD, new String[] { "undress", RETURN_VALUE_NODE_NAME, "jacket" }));
SnifferTraversableResolver resolver = new SnifferTraversableResolver(expectedReachCalls, expectedCascadeCalls);
Configuration<?> config = TestUtil.getConfigurationUnderTest().traversableResolver(resolver);
ValidatorFactory factory = config.buildValidatorFactory();
ExecutableValidator executableValidator = factory.getValidator().forExecutables();
Gentleman gentleman = new Gentleman();
gentleman.wearSuit(suit);
Method method = Gentleman.class.getMethod("undress");
executableValidator.validateReturnValue(gentleman, method, suit);
assertEquals(resolver.getReachableCallCount(), 5);
assertEquals(resolver.getCascadableCallCount(), 2);
}
use of jakarta.validation.ValidatorFactory in project beanvalidation-tck by eclipse-ee4j.
the class TraversableResolverTest method testResolverExceptionsGetWrappedInValidationException.
@Test(expectedExceptions = ValidationException.class)
@SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_VALIDATIONROUTINE_TRAVERSABLE, id = "j")
public void testResolverExceptionsGetWrappedInValidationException() {
ExceptionThrowingTraversableResolver resolver = new ExceptionThrowingTraversableResolver();
Configuration<?> config = TestUtil.getConfigurationUnderTest().traversableResolver(resolver);
ValidatorFactory factory = config.buildValidatorFactory();
Validator v = factory.getValidator();
v.validate(new Suit());
}
use of jakarta.validation.ValidatorFactory in project beanvalidation-tck by eclipse-ee4j.
the class CustomConstraintValidatorTest method testGetConstraintValidatorFactoryFromValidatorFactory.
@Test
@SpecAssertion(section = Sections.VALIDATIONAPI_BOOTSTRAPPING_VALIDATORFACTORY, id = "d")
public void testGetConstraintValidatorFactoryFromValidatorFactory() {
CustomConstraintValidatorFactory constraintValidatorFactory = new CustomConstraintValidatorFactory();
ValidatorFactory validatorFactory = TestUtil.getConfigurationUnderTest().constraintValidatorFactory(constraintValidatorFactory).buildValidatorFactory();
assertSame(validatorFactory.getConstraintValidatorFactory(), constraintValidatorFactory, "getConstraintValidatorFactory() should return the parameter name provider set via configuration");
}
use of jakarta.validation.ValidatorFactory in project beanvalidation-tck by eclipse-ee4j.
the class ValidationTest method testCustomValidationProviderResolution.
@Test
@SpecAssertions({ @SpecAssertion(section = Sections.VALIDATIONAPI_BOOTSTRAPPING_VALIDATION, id = "b"), @SpecAssertion(section = Sections.VALIDATIONAPI_BOOTSTRAPPING_VALIDATION, id = "e") })
public void testCustomValidationProviderResolution() {
ValidationProviderResolver resolver = new ValidationProviderResolver() {
public List<ValidationProvider<?>> getValidationProviders() {
List<ValidationProvider<?>> list = new ArrayList<ValidationProvider<?>>();
list.add(new TCKValidationProvider());
return list;
}
};
GenericBootstrap bootstrap = Validation.byDefaultProvider();
Configuration<?> config = bootstrap.providerResolver(resolver).configure();
ValidatorFactory factory = config.buildValidatorFactory();
assertTrue(factory instanceof TCKValidationProvider.DummyValidatorFactory);
}
use of jakarta.validation.ValidatorFactory in project beanvalidation-tck by eclipse-ee4j.
the class ValidationTest method testBuildDefaultValidatorFactory.
@Test
@SpecAssertion(section = Sections.VALIDATIONAPI_BOOTSTRAPPING_VALIDATION, id = "a")
public void testBuildDefaultValidatorFactory() {
ValidatorFactory defaultFactory = Validation.buildDefaultValidatorFactory();
assertNotNull(defaultFactory, "We should be able to get a factory.");
ValidatorFactory defaultProviderFactory = Validation.byDefaultProvider().configure().buildValidatorFactory();
assertNotNull(defaultProviderFactory, "We should be able to get a factory.");
assertEquals(defaultFactory.getClass(), defaultFactory.getClass(), "The factories have to be identical.");
}
Aggregations