Search in sources :

Example 41 with Validator

use of javax.validation.Validator in project podam by devopsfolks.

the class ValidatedPojoTest method podamShouldAllowValidationAnnotationsCustomization.

@Test
@Title("Podam should allow validation annotations customization")
public void podamShouldAllowValidationAnnotationsCustomization() throws Exception {
    AttributeStrategy<?> strategy = new PatternStrategy();
    PodamFactory podamFactory = podamFactorySteps.givenAPodamFactoryWithCustomStrategy(Pattern.class, strategy);
    ValidatedPatternPojo pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(ValidatedPatternPojo.class, podamFactory);
    podamValidationSteps.thePojoMustBeOfTheType(pojo, ValidatedPatternPojo.class);
    podamValidationSteps.thePojoMustBeOfTheType(pojo.getNumber(), String.class);
    podamValidationSteps.thePojoMustBeOfTheType(pojo.getIdentifier(), String.class);
    Validator validator = podamFactorySteps.givenAJavaxValidator();
    validatorSteps.thePojoShouldNotViolateAnyValidations(validator, pojo);
    podamFactorySteps.removeCustomStrategy(podamFactory, Pattern.class);
}
Also used : PodamFactory(uk.co.jemos.podam.api.PodamFactory) ValidatedPatternPojo(uk.co.jemos.podam.test.dto.ValidatedPatternPojo) PatternStrategy(uk.co.jemos.podam.test.strategies.PatternStrategy) Validator(javax.validation.Validator) Test(org.junit.Test) Title(net.thucydides.core.annotations.Title)

Example 42 with Validator

use of javax.validation.Validator in project javaee7-firstcup by ecabrerar.

the class BooksCollectionTest method shouldReturnAValidationError.

@Test
public void shouldReturnAValidationError() {
    Book book = new Book("Effective Java", "2234555568", "");
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    Set<ConstraintViolation<Book>> violations = validator.validate(book);
    Assert.assertEquals(2, violations.size());
    System.out.println(violations.stream().map(error -> error.getMessage()).collect(Collectors.joining(", ")));
}
Also used : Book(org.ecabrerar.examples.javax.rs.validation.domain.Book) ConstraintViolation(javax.validation.ConstraintViolation) Validator(javax.validation.Validator) Test(org.junit.Test)

Aggregations

Validator (javax.validation.Validator)42 Test (org.junit.Test)25 ConstraintViolation (javax.validation.ConstraintViolation)19 ValidatorFactory (javax.validation.ValidatorFactory)13 InitialContext (javax.naming.InitialContext)8 ArrayList (java.util.ArrayList)5 HibernateValidator (org.hibernate.validator.HibernateValidator)5 File (java.io.File)4 NamingException (javax.naming.NamingException)4 ConstraintViolationException (javax.validation.ConstraintViolationException)4 Title (net.thucydides.core.annotations.Title)4 HibernateValidatorConfiguration (org.hibernate.validator.HibernateValidatorConfiguration)4 PodamFactory (uk.co.jemos.podam.api.PodamFactory)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashSet (java.util.HashSet)3 Context (javax.naming.Context)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 HibernateValidatorFactory (org.hibernate.validator.HibernateValidatorFactory)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2