use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramValidator method validate.
/**
* Checks the form object for any inconsistencies/errors
*
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
* @should fail validation if name is null or empty or whitespace
* @should pass validation if description is null or empty or whitespace
* @should fail validation if program name already in use
* @should fail validation if concept is null or empty or whitespace
* @should pass validation if all required fields have proper values
* @should pass validation and save edited program
* @should pass validation if field lengths are correct
* @should fail validation if field lengths are not correct
*/
@Override
public void validate(Object obj, Errors errors) {
Program p = (Program) obj;
if (p == null) {
errors.rejectValue("program", "error.general");
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "concept", "error.concept");
Program existingProgram = Context.getProgramWorkflowService().getProgramByName(p.getName());
if (existingProgram != null && !existingProgram.getUuid().equals(p.getUuid())) {
errors.rejectValue("name", "general.error.nameAlreadyInUse");
}
if (existingProgram != null && existingProgram.getUuid().equals(p.getUuid())) {
Context.evictFromSession(existingProgram);
}
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name");
}
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramValidatorTest method validate_shouldPassValidationAndSaveEditedProgram.
/**
* @see ProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationAndSaveEditedProgram() {
Program program = Context.getProgramWorkflowService().getProgram(3);
program.setDescription("Edited description");
Errors errors = new BindException(program, "program");
programValidator.validate(program, errors);
Assert.assertFalse(errors.hasErrors());
Context.getProgramWorkflowService().saveProgram(program);
program = Context.getProgramWorkflowService().getProgram(3);
Assert.assertTrue(program.getDescription().equals("Edited description"));
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.
/**
* @see ProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
Program prog = new Program();
prog.setName("Hypochondriasis program");
prog.setDescription("This is Hypochondriasis program");
prog.setConcept(Context.getConceptService().getConcept(3));
Errors errors = new BindException(prog, "prog");
programValidator.validate(prog, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see ProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
Program prog = new Program();
prog.setName("Hypochondriasis program");
prog.setConcept(Context.getConceptService().getConcept(3));
Errors errors = new BindException(prog, "prog");
programValidator.validate(prog, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class SerializedObjectDAOTest method getObjectByUuid_shouldReturnTheSavedObject.
@Test
public void getObjectByUuid_shouldReturnTheSavedObject() {
Program data = dao.getObjectByUuid(Program.class, "83b452ca-a4c8-4bf2-9e0b-8bbddf2f9901");
assertEquals(data.getId().intValue(), 2);
assertEquals(data.getName(), "TestProgram2");
}
Aggregations