Search in sources :

Example 46 with ValidatorFactory

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

the class CarTest method setUpValidator.

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

Example 47 with ValidatorFactory

use of javax.validation.ValidatorFactory in project irida by phac-nml.

the class CRUDServiceImplTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    validator = factory.getValidator();
    crudRepository = mock(IridaJpaRepository.class);
    crudService = new CRUDServiceImpl<>(crudRepository, validator, IdentifiableTestEntity.class);
}
Also used : IridaJpaRepository(ca.corefacility.bioinformatics.irida.repositories.IridaJpaRepository) IdentifiableTestEntity(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity) ValidatorFactory(javax.validation.ValidatorFactory) Before(org.junit.Before)

Example 48 with ValidatorFactory

use of javax.validation.ValidatorFactory in project irida by phac-nml.

the class SampleServiceImplTest method setUp.

@Before
public void setUp() {
    sampleRepository = mock(SampleRepository.class);
    psjRepository = mock(ProjectSampleJoinRepository.class);
    analysisRepository = mock(AnalysisRepository.class);
    ssoRepository = mock(SampleSequencingObjectJoinRepository.class);
    qcEntryRepository = mock(QCEntryRepository.class);
    sequencingObjectRepository = mock(SequencingObjectRepository.class);
    sampleGenomeAssemblyJoinRepository = mock(SampleGenomeAssemblyJoinRepository.class);
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    validator = factory.getValidator();
    sampleService = new SampleServiceImpl(sampleRepository, psjRepository, analysisRepository, ssoRepository, qcEntryRepository, sequencingObjectRepository, sampleGenomeAssemblyJoinRepository, userRepository, validator);
}
Also used : SampleRepository(ca.corefacility.bioinformatics.irida.repositories.sample.SampleRepository) QCEntryRepository(ca.corefacility.bioinformatics.irida.repositories.sample.QCEntryRepository) ValidatorFactory(javax.validation.ValidatorFactory) SampleGenomeAssemblyJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.sample.SampleGenomeAssemblyJoinRepository) ProjectSampleJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository) SampleServiceImpl(ca.corefacility.bioinformatics.irida.service.impl.sample.SampleServiceImpl) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) AnalysisRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.AnalysisRepository) SampleSequencingObjectJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.sample.SampleSequencingObjectJoinRepository) Before(org.junit.Before)

Example 49 with ValidatorFactory

use of javax.validation.ValidatorFactory in project irida by phac-nml.

the class ControllerExceptionHandlerTest method testHandleConstraintViolations.

@Test
public void testHandleConstraintViolations() {
    final String MESSAGES_BASENAME = "ValidationMessages";
    Configuration<?> configuration = Validation.byDefaultProvider().configure();
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename(MESSAGES_BASENAME);
    configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(MESSAGES_BASENAME)));
    ValidatorFactory factory = configuration.buildValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<?>> constraintViolations = new HashSet<>();
    Set<ConstraintViolation<IdentifiableTestEntity>> violations = validator.validate(new IdentifiableTestEntity());
    for (ConstraintViolation<IdentifiableTestEntity> v : violations) {
        constraintViolations.add(v);
    }
    ResponseEntity<Map<String, List<String>>> response = controller.handleConstraintViolations(new ConstraintViolationException(constraintViolations));
    assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
    // assertEquals("{\"label\":[\"You must provide a label.\"]}", response.getBody());
    Map<String, List<String>> body = response.getBody();
    assertTrue("The response must contain an error about a missing label.", body.containsKey("label"));
    List<String> labels = body.get("label");
    assertEquals("There must only be one error with the label.", 1, labels.size());
    String error = labels.get(0);
    assertEquals("The error must be 'You must provide a label.'", "You must provide a label.", error);
}
Also used : IdentifiableTestEntity(ca.corefacility.bioinformatics.irida.web.controller.test.unit.support.IdentifiableTestEntity) ValidatorFactory(javax.validation.ValidatorFactory) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) ResourceBundleMessageInterpolator(org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator) PlatformResourceBundleLocator(org.hibernate.validator.resourceloading.PlatformResourceBundleLocator) ConstraintViolation(javax.validation.ConstraintViolation) ConstraintViolationException(javax.validation.ConstraintViolationException) List(java.util.List) Map(java.util.Map) Validator(javax.validation.Validator) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 50 with ValidatorFactory

use of javax.validation.ValidatorFactory in project irida by phac-nml.

the class GalaxyProjectNameTest method setUp.

@Before
public void setUp() {
    b = ResourceBundle.getBundle(MESSAGES_BASENAME);
    Configuration<?> configuration = Validation.byDefaultProvider().configure();
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename(MESSAGES_BASENAME);
    configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(MESSAGES_BASENAME)));
    ValidatorFactory factory = configuration.buildValidatorFactory();
    validator = factory.getValidator();
}
Also used : ResourceBundleMessageInterpolator(org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator) ValidatorFactory(javax.validation.ValidatorFactory) PlatformResourceBundleLocator(org.hibernate.validator.resourceloading.PlatformResourceBundleLocator) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Before(org.junit.Before)

Aggregations

ValidatorFactory (javax.validation.ValidatorFactory)106 Validator (javax.validation.Validator)31 Before (org.junit.Before)28 ConstraintViolation (javax.validation.ConstraintViolation)25 Test (org.junit.Test)17 BeforeClass (org.junit.BeforeClass)13 ConstraintViolationException (javax.validation.ConstraintViolationException)7 HibernateValidatorConfiguration (org.hibernate.validator.HibernateValidatorConfiguration)6 ResourceBundleMessageInterpolator (org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator)6 PlatformResourceBundleLocator (org.hibernate.validator.resourceloading.PlatformResourceBundleLocator)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 BeanManager (javax.enterprise.inject.spi.BeanManager)5 InitialContext (javax.naming.InitialContext)5 ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)5 HashSet (java.util.HashSet)4 NamingException (javax.naming.NamingException)4 ConstraintValidatorFactory (javax.validation.ConstraintValidatorFactory)4 ValidatorContext (javax.validation.ValidatorContext)4 HibernateValidator (org.hibernate.validator.HibernateValidator)4