use of org.springframework.validation.Errors 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.Errors 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.Errors 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());
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType() {
DrugOrder order = new DrugOrder();
order.setDosingType(SimpleDosingInstructions.class);
order.setDose(null);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("dose"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class EncounterRoleValidatorTest method validate_shouldFailIfTheNameOfTheEncounterRoleIsNullEmptyOrWhitespace.
/**
* @see org.openmrs.validator.EncounterRoleValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfTheNameOfTheEncounterRoleIsNullEmptyOrWhitespace() {
EncounterRole encounterRoleNo1 = new EncounterRole();
encounterRoleNo1.setName(null);
Errors errorsNo1 = new BindException(encounterRoleNo1, "encounterRole");
new EncounterRoleValidator().validate(encounterRoleNo1, errorsNo1);
Assert.assertTrue(errorsNo1.hasFieldErrors("name"));
EncounterRole encounterRoleNo2 = new EncounterRole();
encounterRoleNo2.setName("");
Errors errorsNo2 = new BindException(encounterRoleNo2, "encounterRole");
new EncounterRoleValidator().validate(encounterRoleNo2, errorsNo2);
Assert.assertTrue(errorsNo2.hasFieldErrors("name"));
EncounterRole encounterRoleNo3 = new EncounterRole();
encounterRoleNo3.setName(" ");
Errors errorsNo3 = new BindException(encounterRoleNo3, "encounterRole");
new EncounterRoleValidator().validate(encounterRoleNo3, errorsNo3);
Assert.assertTrue(errorsNo3.hasFieldErrors("name"));
}
Aggregations