use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class CohortValidatorTest method validate_shouldPassIfMembershipStartDateIsAfterEndDate.
@Test
public void validate_shouldPassIfMembershipStartDateIsAfterEndDate() throws Exception {
Cohort cohort = new Cohort(2);
CohortMembership membership = new CohortMembership(patient.getPatientId());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = dateFormat.parse("2016-11-01 00:00:00");
Date endDate = dateFormat.parse("2015-01-01 00:00:00");
membership.setStartDate(startDate);
membership.setEndDate(endDate);
Errors errors = new BindException(cohort, "cohort");
new CohortValidator().validate(cohort, errors);
Assert.assertFalse(errors.hasFieldErrors("memberships"));
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class ConceptClassValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see ConceptClassValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
ConceptClass cc = new ConceptClass();
cc.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
cc.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
cc.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Errors errors = new BindException(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("description"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class ConceptClassValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.
/**
* @see ConceptClassValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
ConceptClass cc = new ConceptClass();
cc.setName("name");
cc.setDescription("some text");
Errors errors = new BindException(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class ConceptClassValidatorTest method validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace.
@Test
public void validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace() {
ConceptClass cc = new ConceptClass();
cc.setName("name");
cc.setDescription(null);
Errors errors = new BindException(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertFalse(errors.hasFieldErrors("description"));
cc.setDescription("");
errors = new BindException(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertFalse(errors.hasFieldErrors("description"));
cc.setDescription(" ");
errors = new BindException(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertFalse(errors.hasFieldErrors("description"));
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class ConceptClassValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see ConceptClassValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
ConceptClass cc = new ConceptClass();
cc.setName("name");
cc.setDescription("some text");
cc.setRetireReason("some text");
Errors errors = new BindException(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations