Skip to content

Commit

Permalink
FLAG-78: added test for priority services (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManojLL committed Jul 20, 2024
1 parent a95d244 commit 92f1722
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;
import org.openmrs.Cohort;
import org.openmrs.Patient;
import org.openmrs.api.APIException;
import org.openmrs.api.PatientService;
import org.openmrs.api.context.Context;

Expand Down Expand Up @@ -112,7 +114,73 @@ public void savePriority_shouldSaveNewPriority() {
assertNotNull(savedPriority);
assertEquals(priority.getName(), savedPriority.getName());
}


@Test
public void getAllPriorities_shouldGetAllPriorities() {
List<Priority> priorities = flagService.getAllPriorities();
assertFalse(priorities.isEmpty());
}

@Test
public void getPriority_shouldGetPriorityById() {
Integer priorityId = 1;
Priority priority = flagService.getPriority(priorityId);
assertNotNull(priority);
assertEquals(priorityId, priority.getPriorityId());
}

@Test
public void getPriorityByUuid_shouldGetPriorityByUuid() {
String priorityUuid = "da7f524f-27ce-4bb2-86d6-6d1d05312bd5";
Priority priority = flagService.getPriorityByUuid(priorityUuid);
assertNotNull(priority);
assertEquals(priorityUuid, priority.getUuid());
}

@Test
public void getPriorityByName_shouldGetPriorityByName() {
String priorityName = "pr 2";
Priority priority = flagService.getPriorityByName(priorityName);
assertNotNull(priority);
assertEquals(priorityName, priority.getName());
}

@Test
public void purgePriority_shouldPurgePriority() {
Integer priorityId = 2;
flagService.purgePriority(priorityId);
Priority priority = flagService.getPriority(priorityId);
assertNull(priority);
}

@Test(expected = APIException.class)
public void purgePriority_shouldTrowExceptionWhenPriorityAssociatedWithAFlag() {
Integer priorityId = 1;

flagService.purgePriority(priorityId);
Priority purgedPriority = flagService.getPriority(priorityId);
assertNotNull(purgedPriority);
}

@Test
public void retirePriority_shouldRetirePriorityWithReason() {
String reason = "reason";
Priority priority = flagService.getPriority(2);
flagService.retirePriority(priority, reason);
Priority retiredpriority = flagService.getPriority(2);
assertTrue(retiredpriority.getRetired());
assertEquals(reason, retiredpriority.getRetireReason());
}

@Test(expected = APIException.class)
public void retirePriority_shouldNotRetirePriorityWithoutReason() {
String reason = "";
Priority priority = flagService.getPriority(2);
flagService.retirePriority(priority, reason);
Priority retiredpriority = flagService.getPriority(2);
assertFalse(retiredpriority.getRetired());
}

/**
* Tests of methods that save and retrieve flags
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
<allergy allergy_id="1" patient_id="2" severity_concept_id="1" coded_allergen="1" allergen_type="DRUG" creator="1" date_created="2007-05-01 00:00:00.0" voided="false" uuid="7d87924e-e8df-4553-a956-95de80529735"/>
<allergy allergy_id="2" patient_id="1" severity_concept_id="1" coded_allergen="1" allergen_type="FOOD" creator="1" date_created="2007-05-01 00:00:00.0" voided="false" uuid="7d89924e-e8df-4553-a956-95de80529735"/>

<patientflags_flag flag_id="1" name="DRUG FLAG" evaluator="org.openmrs.module.patientflags.evaluator.SQLFlagEvaluator" criteria="SELECT a.patient_id FROM allergy a where a.allergen_type = 'DRUG';" message="Test" enabled="1" creator="1" date_created="2005-09-22 00:00:00.0" retired="false" uuid="da7f524f-27ce-4bb2-86d6-6d1d05312bd5"/>
<patientflags_priority priority_id="1" name="pr 1" style="style" p_rank="1" creator="1" date_created="2005-09-22 00:00:00.0" retired="false" uuid="da7f524f-27ce-4bb2-86d6-6d1d05312bd5" />
<patientflags_priority priority_id="2" name="pr 2" style="style" p_rank="1" creator="1" date_created="2005-09-22 00:00:00.0" retired="false" uuid="da7f524f-27ce-4bb2-86d6-6d1d05312bd6" />

<patientflags_flag flag_id="1" name="DRUG FLAG" evaluator="org.openmrs.module.patientflags.evaluator.SQLFlagEvaluator" criteria="SELECT a.patient_id FROM allergy a where a.allergen_type = 'DRUG';" message="Test" enabled="1" creator="1" date_created="2005-09-22 00:00:00.0" retired="false" uuid="da7f524f-27ce-4bb2-86d6-6d1d05312bd5" priority_id="1"/>
<patientflags_flag flag_id="2" name="FOOD FLAG" evaluator="org.openmrs.module.patientflags.evaluator.SQLFlagEvaluator" criteria="SELECT a.patient_id FROM allergy a where a.allergen_type = 'FOOD';" message="Test" enabled="1" creator="1" date_created="2005-09-22 00:00:00.0" retired="false" uuid="da7f524f-28ce-4bb2-86d6-6d1d05312bd5"/>


</dataset>

0 comments on commit 92f1722

Please sign in to comment.