use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class LocationAttributeTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see LocationAttributeTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
LocationAttributeType type = new LocationAttributeType();
type.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");
type.setDatatypeClassname("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");
type.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 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 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 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");
type.setPreferredHandlerClassname("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");
type.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(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("datatypeClassname"));
Assert.assertTrue(errors.hasFieldErrors("description"));
Assert.assertTrue(errors.hasFieldErrors("preferredHandlerClassname"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class LocationAttributeTypeValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.
/**
* @see LocationAttributeTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() {
LocationAttributeType type = new LocationAttributeType();
type.setName(null);
type.setDescription("description");
Errors errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
type.setName("");
errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
type.setName(" ");
errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class LocationAttributeTypeValidatorTest method validate_shouldPassEditingLocationAttributeTypeName.
/**
* @see LocationAttributeTypeValidator#validate(Object, Errors)
*/
@Test
public void validate_shouldPassEditingLocationAttributeTypeName() {
LocationAttributeType et = Context.getLocationService().getLocationAttributeTypeByName("Audit Date");
Assert.assertNotNull(et);
Errors errors = new BindException(et, "locationAttributeType");
new LocationAttributeTypeValidator().validate(et, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class LocationAttributeTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see LocationAttributeTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
LocationAttributeType type = new LocationAttributeType();
type.setName("name");
type.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype");
type.setDescription("description");
type.setRetireReason("retireReason");
Errors errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class VisitValidatorTest method validate_shouldFailIfPatientIsNotSet.
/**
* @see VisitValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfPatientIsNotSet() {
VisitService vs = Context.getVisitService();
Visit visit = new Visit();
visit.setVisitType(vs.getVisitType(1));
visit.setStartDatetime(new Date());
Errors errors = new BindException(visit, "visit");
new VisitValidator().validate(visit, errors);
assertTrue(errors.hasFieldErrors("patient"));
}
Aggregations