Search in sources :

Example 26 with Program

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());
}
Also used : Program(org.openmrs.Program) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 27 with Program

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));
}
Also used : Program(org.openmrs.Program) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 28 with Program

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;
}
Also used : Program(org.openmrs.Program) Date(java.util.Date)

Example 29 with 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"));
}
Also used : Errors(org.springframework.validation.Errors) Program(org.openmrs.Program) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 30 with Program

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"));
}
Also used : Errors(org.springframework.validation.Errors) Program(org.openmrs.Program) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Program (org.openmrs.Program)43 Test (org.junit.Test)35 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)26 PatientProgram (org.openmrs.PatientProgram)22 ProgramWorkflow (org.openmrs.ProgramWorkflow)8 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 Concept (org.openmrs.Concept)7 ArrayList (java.util.ArrayList)6 ProgramWorkflowState (org.openmrs.ProgramWorkflowState)6 Date (java.util.Date)4 Patient (org.openmrs.Patient)4 ProgramWorkflowDAO (org.openmrs.api.db.ProgramWorkflowDAO)2 MissingPropertyException (groovy.lang.MissingPropertyException)1 HashMap (java.util.HashMap)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1 Criteria (org.hibernate.Criteria)1 DateTime (org.joda.time.DateTime)1 Ignore (org.junit.Ignore)1