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();
}
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);
}
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);
}
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);
}
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();
}
Aggregations