Guest User

Untitled

a guest
Jul 8th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. package org.openmrs.module.locationbasedaccess.web.controller;
  2.  
  3. import org.junit.Assert;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6.  
  7. import com.fasterxml.jackson.databind.ObjectMapper;
  8. import org.openmrs.Patient;
  9. import org.openmrs.PersonAttribute;
  10. import org.openmrs.api.PatientService;
  11. import org.openmrs.api.context.Context;
  12. import org.openmrs.module.webservices.rest.SimpleObject;
  13. import org.openmrs.module.webservices.rest.web.v1_0.controller.RestControllerTestUtils;
  14. import org.springframework.http.HttpStatus;
  15. import org.springframework.mock.web.MockHttpServletRequest;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17.  
  18. public class PatientsMigrationController_Test extends RestControllerTestUtils{
  19.  
  20. private PatientService patientService;
  21. private final String XML_FILENAME_WITH_PERSON_DATA = "PatientMigrationData.xml";
  22.  
  23. private final String LOCATION_UUID ="ef93c695-ac43-450a-93f8-4b2b4d50a3c9";
  24. private final String PERSON_ATTRIBUTE_NAME = "LocationAttribute";
  25. private final int PATIENT1_ID =1;
  26. private final int PATIENT2_ID =2;
  27. private final int PATIENT3_ID =3;
  28.  
  29. @Before
  30. public void init() throws Exception {
  31. patientService = Context.getPatientService();
  32. executeDataSet(XML_FILENAME_WITH_PERSON_DATA);
  33. }
  34.  
  35. private String getURI(){
  36. return "patient-migration";
  37. }
  38.  
  39. @Test
  40. public void migratePatients_shouldChangePersonLocationAttributeType() throws Exception {
  41.  
  42. Patient patient1 = patientService.getPatient(PATIENT1_ID);
  43. PersonAttribute personAttribute1 = patient1.getAttribute(PERSON_ATTRIBUTE_NAME);
  44. Assert.assertEquals(personAttribute1.getValue(),LOCATION_UUID);
  45. Patient patient3 = patientService.getPatient(PATIENT3_ID);
  46. PersonAttribute personAttribute3 = patient3.getAttribute(PERSON_ATTRIBUTE_NAME);
  47. Assert.assertNotEquals(personAttribute3.getValue(),LOCATION_UUID);
  48. Patient patient2 = patientService.getPatient(PATIENT2_ID);
  49. PersonAttribute personAttribute2 = patient2.getAttribute(PERSON_ATTRIBUTE_NAME);
  50. Assert.assertNull(personAttribute2);
  51. String patientList[] = {patient1.getUuid(),patient2.getUuid(),patient3.getUuid()};
  52. SimpleObject obj = new SimpleObject();
  53. obj.add("locationUuid", LOCATION_UUID);
  54. obj.add("patientList", patientList);
  55. String json = new ObjectMapper().writeValueAsString(obj);
  56. MockHttpServletRequest req = request(RequestMethod.POST, getURI());
  57. req.setContent(json.getBytes());
  58. Assert.assertEquals(handle(req).getStatus(), HttpStatus.OK.value());
  59. Patient newpatient1 = patientService.getPatient(PATIENT1_ID);
  60. Patient newpatient2 = patientService.getPatient(PATIENT2_ID);
  61. Patient newpatient3 = patientService.getPatient(PATIENT3_ID);
  62. Assert.assertEquals(newpatient1.getAttribute(PERSON_ATTRIBUTE_NAME).getValue(),LOCATION_UUID);
  63. Assert.assertEquals(newpatient3.getAttribute(PERSON_ATTRIBUTE_NAME).getValue(),LOCATION_UUID);
  64. Assert.assertEquals(newpatient2.getAttribute(PERSON_ATTRIBUTE_NAME).getValue(),LOCATION_UUID);
  65.  
  66. }
  67.  
  68. }
Add Comment
Please, Sign In to add comment