use of org.springframework.validation.MapBindingResult in project openmrs-core by openmrs.
the class RelationshipValidatorTest method validate_shouldFailIfEndDateIsBeforeStartDate.
/**
* @throws ParseException
* @see RelationshipValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfEndDateIsBeforeStartDate() throws ParseException {
Relationship relationship = new Relationship(1);
relationship.setStartDate(Context.getDateFormat().parse("18/02/2012"));
relationship.setEndDate(Context.getDateFormat().parse("18/02/2001"));
Map<String, String> map = new HashMap<>();
MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName());
new RelationshipValidator().validate(relationship, errors);
Assert.assertEquals(true, errors.hasErrors());
}
use of org.springframework.validation.MapBindingResult in project openmrs-core by openmrs.
the class RelationshipValidatorTest method validate_shouldPassIfStartDateIsNotInFuture.
/**
* @see RelationshipValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassIfStartDateIsNotInFuture() {
Relationship relationship = new Relationship(1);
Map<String, String> map = new HashMap<>();
MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName());
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, -1);
Date lastYear = cal.getTime();
relationship.setStartDate(lastYear);
new RelationshipValidator().validate(relationship, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.MapBindingResult in project openmrs-core by openmrs.
the class RelationshipValidatorTest method validate_shouldPassIfEndDateIsAfterStartDate.
/**
* @throws ParseException
* @see RelationshipValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassIfEndDateIsAfterStartDate() throws ParseException {
Relationship relationship = new Relationship(1);
relationship.setStartDate(Context.getDateFormat().parse("18/02/2012"));
relationship.setEndDate(Context.getDateFormat().parse("18/03/2012"));
Map<String, String> map = new HashMap<>();
MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName());
new RelationshipValidator().validate(relationship, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.MapBindingResult in project openmrs-core by openmrs.
the class RelationshipValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see RelationshipValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
Relationship relationship = new Relationship(1);
relationship.setVoidReason("voidReason");
Map<String, String> map = new HashMap<>();
MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName());
new RelationshipValidator().validate(relationship, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.MapBindingResult in project yyl_example by Relucent.
the class CustomValidatorExample method main.
public static void main(String[] args) {
CustomValidatorBean validator = new CustomValidatorBean();
validator.afterPropertiesSet();
Sample sample = new Sample();
Errors errors = new MapBindingResult(new HashMap<>(), Sample.class.getName());
validator.validate(sample, errors);
for (ObjectError error : errors.getAllErrors()) {
System.out.println(error.getDefaultMessage());
}
}
Aggregations