use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class LocationValidatorTest method validate_shouldFailValidationIfLocationNameAlreadyExist.
/**
* @see org.openmrs.validator.LocationValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfLocationNameAlreadyExist() {
Location location = new Location();
location.setName("Unknown Location");
location.setDescription("desc");
Errors errors = new BindException(location, "location");
new LocationValidator().validate(location, errors);
Assert.assertTrue(errors.hasErrors());
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldFailIfConceptIsUsedByAnotherFrequency.
/**
* @see OrderFrequencyValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfConceptIsUsedByAnotherFrequency() {
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(Context.getConceptService().getConcept(113));
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertTrue(errors.hasFieldErrors("concept"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
ConceptService cs = Context.getConceptService();
Concept concept = new Concept();
ConceptName cn = new ConceptName("new name", Context.getLocale());
concept.setDatatype(cs.getConceptDatatype(1));
concept.setConceptClass(cs.getConceptClass(19));
concept.addName(cn);
concept.addDescription(new ConceptDescription("some description", null));
cs.saveConcept(concept);
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
orderFrequency.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(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldFailIfConceptIsNull.
/**
* @see OrderFrequencyValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfConceptIsNull() {
OrderFrequency orderFrequency = new OrderFrequency();
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertTrue(errors.hasFieldErrors("concept"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldPassForAValidNewOrderFrequency.
/**
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassForAValidNewOrderFrequency() {
ConceptService cs = Context.getConceptService();
Concept concept = new Concept();
ConceptName cn = new ConceptName("new name", Context.getLocale());
concept.setDatatype(cs.getConceptDatatype(1));
concept.setConceptClass(cs.getConceptClass(19));
concept.addName(cn);
concept.addDescription(new ConceptDescription("some description", null));
cs.saveConcept(concept);
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations