use of org.openmrs.ProgramWorkflow in project openmrs-core by openmrs.
the class StateConversionValidatorTest method validate_shouldFailValidationIfProgramWorkflowStateIsNullOrEmptyOrWhitespace.
/**
* @see StateConversionValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfProgramWorkflowStateIsNullOrEmptyOrWhitespace() {
ConceptStateConversion csc = new ConceptStateConversion();
ProgramWorkflow workflow = Context.getProgramWorkflowService().getProgram(1).getAllWorkflows().iterator().next();
csc.setConcept(Context.getConceptService().getConcept(3));
csc.setProgramWorkflow(workflow);
csc.setProgramWorkflowState(null);
Errors errors = new BindException(csc, "csc");
new StateConversionValidator().validate(csc, errors);
Assert.assertTrue(errors.hasFieldErrors("programWorkflowState"));
}
use of org.openmrs.ProgramWorkflow in project openmrs-core by openmrs.
the class ProgramWorkflowServiceTest method getWorkflow_shouldGetWorkflowAssociatedWithGivenIdIfWorkflowIdExists.
@Test
public void getWorkflow_shouldGetWorkflowAssociatedWithGivenIdIfWorkflowIdExists() {
final Integer EXISTING_WORKFLOW_ID = 1;
ProgramWorkflow workflow = pws.getWorkflow(EXISTING_WORKFLOW_ID);
assertNotNull("ProgramWorkflow not found", workflow);
assertThat(workflow.getId(), is(EXISTING_WORKFLOW_ID));
}
use of org.openmrs.ProgramWorkflow in project openmrs-core by openmrs.
the class ProgramWorkflowServiceTest method getWorkflowByUuid_shouldFindObjectGivenValidUuid.
/**
* @see ProgramWorkflowService#getWorkflowByUuid(String)
*/
@Test
public void getWorkflowByUuid_shouldFindObjectGivenValidUuid() {
String uuid = "84f0effa-dd73-46cb-b931-7cd6be6c5f81";
ProgramWorkflow programWorkflow = Context.getProgramWorkflowService().getWorkflowByUuid(uuid);
Assert.assertEquals(1, (int) programWorkflow.getProgramWorkflowId());
}
use of org.openmrs.ProgramWorkflow in project openmrs-core by openmrs.
the class ProgramWorkflowServiceTest method retireProgram_shouldSaveTheRetiredProgramWithReason.
@Test
public void retireProgram_shouldSaveTheRetiredProgramWithReason() throws APIException {
String reason = "Feeling well.";
String uuid = "eae98b4c-e195-403b-b34a-82d94103b2c0";
Program program = Context.getProgramWorkflowService().getProgramByUuid(uuid);
Program retireProgram = pws.retireProgram(program, reason);
assertTrue(retireProgram.getRetired());
assertEquals(reason, retireProgram.getRetireReason());
for (ProgramWorkflow programWorkflow : program.getAllWorkflows()) {
assertTrue(programWorkflow.getRetired());
for (ProgramWorkflowState programWorkflowState : programWorkflow.getStates()) {
assertTrue(programWorkflowState.getRetired());
}
}
}
use of org.openmrs.ProgramWorkflow in project openmrs-core by openmrs.
the class ProgramWorkflowServiceTest method getSortedStates_shouldSortNamesContainingNumbersIntelligently.
/**
* THIS TEST SHOULD BE IN THE CLASS 'PROGRAMWORKFLOWTEST.JAVA' BUT IT REQUIRES ACCESS TO THE DAO
* LAYER
*
* @see ProgramWorkflow#getSortedStates()
*/
@Test
public void getSortedStates_shouldSortNamesContainingNumbersIntelligently() {
ProgramWorkflow program = new ProgramWorkflow();
ConceptName state1ConceptName = new ConceptName("Group 10", Context.getLocale());
Concept state1Concept = new Concept();
state1Concept.addName(state1ConceptName);
ProgramWorkflowState state1 = new ProgramWorkflowState();
state1.setConcept(state1Concept);
program.addState(state1);
ConceptName state2ConceptName = new ConceptName("Group 2", Context.getLocale());
Concept state2Concept = new Concept();
state2Concept.addName(state2ConceptName);
ProgramWorkflowState state2 = new ProgramWorkflowState();
state2.setConcept(state2Concept);
program.addState(state2);
Set<ProgramWorkflowState> sortedStates = program.getSortedStates();
int x = 1;
for (ProgramWorkflowState state : sortedStates) {
if (x == 1) {
Assert.assertEquals("Group 2", state.getConcept().getName(Context.getLocale()).getName());
} else if (x == 2) {
Assert.assertEquals("Group 10", state.getConcept().getName(Context.getLocale()).getName());
} else {
Assert.fail("Wha?!");
}
x++;
}
}
Aggregations