use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramWorkflowDAOTest method getProgramsByName_whenThereAreNoProgramsWithTheGivenName_shouldReturnAnEmptyList.
@Test
public void getProgramsByName_whenThereAreNoProgramsWithTheGivenName_shouldReturnAnEmptyList() {
Program program = createProgram();
program.setName("wrongProgramName");
dao.saveProgram(program);
clearHibernateCache();
List<Program> programs = dao.getProgramsByName("testProgramName", true);
Assert.assertNotNull(programs);
Assert.assertEquals(0, programs.size());
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramWorkflowDAOTest method getProgramsByName_whenThereAreProgramsWithTheGivenName_shouldReturnAllProgramsWithTheGivenName.
@Test
public void getProgramsByName_whenThereAreProgramsWithTheGivenName_shouldReturnAllProgramsWithTheGivenName() {
Program program1 = createProgram();
program1.setName("testProgramName");
dao.saveProgram(program1);
Program program2 = createProgram();
program2.setName("testProgramName");
dao.saveProgram(program2);
Program program3 = createProgram();
program3.setName("wrongProgramName");
dao.saveProgram(program3);
clearHibernateCache();
List<Program> programs = dao.getProgramsByName("testProgramName", true);
Assert.assertEquals(2, programs.size());
Assert.assertEquals(program1, programs.get(0));
Assert.assertEquals(program2, programs.get(1));
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramWorkflowDAOTest method createProgram.
private Program createProgram() {
Program program = new Program();
program.setName("OpenMRS");
program.setDescription("An opensource medical record system");
program.setDateCreated(new Date());
return program;
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.
/**
* @see ProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() {
Program prog = new Program();
prog.setName(null);
prog.setConcept(Context.getConceptService().getConcept(3));
Errors errors = new BindException(prog, "prog");
programValidator.validate(prog, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
prog.setName("");
errors = new BindException(prog, "prog");
programValidator.validate(prog, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
prog.setName(" ");
errors = new BindException(prog, "prog");
programValidator.validate(prog, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramValidatorTest method validate_shouldFailValidationIfProgramNameAlreadyInUse.
/**
* @see ProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfProgramNameAlreadyInUse() {
Program prog = new Program();
prog.setName("MDR-TB PROGRAM");
prog.setConcept(Context.getConceptService().getConcept(3));
Errors errors = new BindException(prog, "prog");
programValidator.validate(prog, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
Aggregations