-
Notifications
You must be signed in to change notification settings - Fork 4.1k
TRUNK-5068: Add tests to ProgramWorkflowService #4600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 10 commits
9446023
d3e735c
697c3dd
9146080
40d2592
b60abc1
83a75bd
bd48688
3e21950
8740c33
596c5c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ | |
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
@@ -42,6 +44,7 @@ | |
| import org.openmrs.ProgramWorkflow; | ||
| import org.openmrs.ProgramWorkflowState; | ||
| import org.openmrs.User; | ||
| import org.openmrs.PatientProgramAttribute; | ||
| import org.openmrs.api.context.Context; | ||
| import org.openmrs.api.db.ProgramWorkflowDAO; | ||
| import org.openmrs.api.impl.ProgramWorkflowServiceImpl; | ||
|
|
@@ -62,7 +65,9 @@ public class ProgramWorkflowServiceTest extends BaseContextSensitiveTest { | |
| protected static final String PROGRAM_ATTRIBUTES_XML = "org/openmrs/api/include/ProgramAttributesDataset.xml"; | ||
|
|
||
| protected static final String OTHER_PROGRAM_WORKFLOWS = "org/openmrs/api/include/ProgramWorkflowServiceTest-otherProgramWorkflows.xml"; | ||
|
|
||
|
|
||
| protected static final String PATIENT_PROGRAM_ATTRIBUTE_DATASET = "org/openmrs/api/include/PatientProgramAttributeTestDataset.xml"; | ||
|
|
||
| protected ProgramWorkflowService pws = null; | ||
|
|
||
| @Autowired | ||
|
|
@@ -82,6 +87,7 @@ public void runBeforeEachTest() { | |
| executeDataSet(CREATE_PATIENT_PROGRAMS_XML); | ||
| executeDataSet(PROGRAM_ATTRIBUTES_XML); | ||
| executeDataSet(OTHER_PROGRAM_WORKFLOWS); | ||
| executeDataSet(PATIENT_PROGRAM_ATTRIBUTE_DATASET); | ||
|
|
||
| if (pws == null) { | ||
| pws = Context.getProgramWorkflowService(); | ||
|
|
@@ -733,7 +739,7 @@ public void purgeProgram_shouldPurgeProgramWithPatientsEnrolled() { | |
| } | ||
| @Test | ||
| public void shouldTestGetAllProgramAttributeTypes() throws Exception { | ||
| assertEquals(1, pws.getAllProgramAttributeTypes().size()); | ||
| assertEquals(3, pws.getAllProgramAttributeTypes().size()); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -751,11 +757,11 @@ public void shouldTestGetProgramAttributeTypeByUuid() throws Exception { | |
|
|
||
| @Test | ||
| public void shouldTestSaveProgramAttributeType() throws Exception { | ||
| assertEquals(1,pws.getAllProgramAttributeTypes().size()); | ||
| assertEquals(3,pws.getAllProgramAttributeTypes().size()); | ||
| ProgramAttributeType programAttributeType = new ProgramAttributeType(); | ||
| programAttributeType.setName("test"); | ||
| pws.saveProgramAttributeType(programAttributeType); | ||
| assertEquals(2,pws.getAllProgramAttributeTypes().size()); | ||
| assertEquals(4,pws.getAllProgramAttributeTypes().size()); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -1095,6 +1101,42 @@ public void triggerStateConversion_shouldTestTransitionToState(){ | |
| pwsi.triggerStateConversion(patient, trigger, dateConverted); | ||
| assertEquals(patientProgram.getStates().size(), (patientStatesSize + 1)); | ||
| } | ||
|
|
||
| /** | ||
| * Test to check the implementation of Patient Program Attribute Type by Uuid | ||
|
||
| * from Program Workflow Service | ||
| * @see ProgramWorkflowService#getPatientProgramAttributeByUuid(String) | ||
| */ | ||
| @Test | ||
| public void getProgramAttributeType_shouldReturnAttributeThatMatchesGivenUuid(){ | ||
|
|
||
| PatientProgramAttribute patientProgramAttribute = pws.getPatientProgramAttributeByUuid("dd8793dc-e9d2-11ee-9b67-333dbdea27a2"); | ||
| assertNotNull(patientProgramAttribute); | ||
| assertEquals(2, patientProgramAttribute.getId()); | ||
| } | ||
|
|
||
| /** | ||
| * Test to check the number of Patient Program attributes by given name | ||
| * @see ProgramWorkflowService#getPatientProgramAttributeByAttributeName(List, String) | ||
| */ | ||
| @Test | ||
| public void getProgramAttributeByAttributeName_shouldReturnAttributeThatMatchesGivenName(){ | ||
| Map<Object, Object> results = pws.getPatientProgramAttributeByAttributeName( | ||
| Collections.singletonList(2),"programName"); | ||
| assertEquals(1,results.size()); | ||
| } | ||
|
|
||
| /** | ||
| * Test to get a patient Program by its Attribute Name and Value Reference | ||
| * @see ProgramWorkflowService#getPatientProgramByAttributeNameAndValue(String, String) | ||
| */ | ||
| @Test | ||
| public void getPatientProgramByAttributeNameAndValue_shouldReturnProgramsThatMatchesParameters(){ | ||
|
|
||
| List<PatientProgram> patientPrograms = | ||
| pws.getPatientProgramByAttributeNameAndValue("programName", "programReference"); | ||
| assertEquals(1, patientPrograms.size()); | ||
| } | ||
|
|
||
| // /** | ||
| // * This method should be uncommented when you want to examine the actual hibernate | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
|
|
||
| This Source Code Form is subject to the terms of the Mozilla Public License, | ||
| v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
| obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
| the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
|
|
||
| Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
| graphic logo is a trademark of OpenMRS Inc. | ||
|
|
||
| --> | ||
| <dataset> | ||
| <person person_id="2" | ||
| gender="M" | ||
| birthdate="1998-12-25" | ||
| birthdate_estimated="false" | ||
| dead="false" | ||
| creator="1" | ||
| date_created="2006-02-15 00:00:00.0" | ||
| voided="false" | ||
| uuid="6013a8cd-c6a0-4140-bfac-0af565704420"/> | ||
|
|
||
| <patient patient_id="2" | ||
| creator="1" | ||
| date_created="2016-05-15 00:00:00.0" | ||
| voided="false"/> | ||
|
|
||
| <patient_program patient_program_id="1" | ||
| patient_id="2" | ||
| program_id="1" | ||
| date_enrolled="2006-10-14 00:00:00.0" | ||
| creator="1" | ||
| date_created="2007-09-20 00:00:00.0" | ||
| voided="false" | ||
| uuid="9119b9f8-af3d-4ad8-9e2e-2317c3de91c6"/> | ||
|
|
||
| <patient_program_attribute | ||
| patient_program_attribute_id = "2" | ||
| patient_program_id = "1" | ||
| attribute_type_id = "3" | ||
| uuid = "dd8793dc-e9d2-11ee-9b67-333dbdea27a2" | ||
| creator="1" | ||
| date_created="2021-09-20 00:00:00.0" | ||
| voided="false"/> | ||
|
|
||
| <patient_program_attribute | ||
| patient_program_attribute_id = "3" | ||
| patient_program_id = "1" | ||
| attribute_type_id = "2" | ||
| value_reference = "programReference" | ||
| uuid = "da88c81a-e9da-11ee-8b19-6f54994ac15c" | ||
| creator="1" | ||
| date_created="2021-12-20 00:00:00.0" | ||
| voided="false"/> | ||
|
|
||
| </dataset> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this change also related to the ticket you were working on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, because after my changes, some other tests were failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this mean that it was some sort of bug that your tests exposed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No! for this particular case, my task was to implement tests for this method
getPatientProgramByAttributeNameAndValuefromProgramWorkflowServiceclass. But after implementing the test, I faced an error related to the table mappingspatient_program pp is not mapped [select pp from....So I applied this changes to deal with the related issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still do not get it. If it was not a bug, why do you need to fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was, but not related to any code added by me. The
sessionfactoryquery was there, but was not covered by the tests. once I wrote a test, the error came up.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, that makes perfect sense. Thanks for the clarification. 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank for your time.
I will be pushing the last changes (naming conventions) shortly