Advertisement
k-joseph

Untitled

Sep 20th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. *
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. * License for the specific language governing rights and limitations
  10. * under the License.
  11. *
  12. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  13. */
  14. package org.openmrs.web.controller.patient;
  15.  
  16. import javax.servlet.http.HttpServletResponse;
  17.  
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.openmrs.api.PatientService;
  21. import org.openmrs.api.context.Context;
  22. import org.openmrs.web.test.BaseWebContextSensitiveTest;
  23. import org.springframework.mock.web.MockHttpServletRequest;
  24. import org.springframework.mock.web.MockHttpServletResponse;
  25. import org.springframework.mock.web.MockHttpSession;
  26. import org.springframework.web.servlet.ModelAndView;
  27.  
  28. public class PatientIdentifierTypeFormControllerTest extends BaseWebContextSensitiveTest {
  29.  
  30. PatientService patientService = Context.getPatientService();
  31.  
  32. @Test
  33. public void shouldSavePAtientIdentifierTypeWhenPatientIdentifierTypesAreNotLocked() throws Exception {
  34.  
  35. PatientIdentifierTypeFormController controller = (PatientIdentifierTypeFormController) applicationContext
  36. .getBean("patientIdentifierTypeForm");
  37. controller.setApplicationContext(applicationContext);
  38. controller.setSuccessView("index.htm");
  39. controller.setFormView("PatientIdentifierType.form");
  40.  
  41. MockHttpServletRequest request = new MockHttpServletRequest("GET",
  42. "/admin/patients/patientIdentifierType.form?patientIdentifierTypeId=2");
  43. request.setSession(new MockHttpSession(null));
  44. HttpServletResponse response = new MockHttpServletResponse();
  45. controller.handleRequest(request, response);
  46.  
  47. request.setMethod("POST");
  48.  
  49. request.addParameter("action", "Save PatientIdentifierType");
  50.  
  51. ModelAndView mav = controller.handleRequest(request, response);
  52.  
  53. Assert.assertSame(controller.getFormView(), mav.getViewName());
  54. Assert.assertNotEquals("The save attempt should have succeeded!", "index.htm", mav.getViewName());
  55. Assert.assertNotNull(patientService.getPatientIdentifierType(2));
  56. }
  57.  
  58. @Test
  59. public void shouldNotDeletePatientIdentifierTypeWhenPatientIdentifierTypesAreLocked() throws Exception {
  60. // dataset locks patient identifier types
  61. executeDataSet("org/openmrs/web/patient/include/PatientIdentifierTypeFormControllerTest.xml");
  62.  
  63. PatientIdentifierTypeFormController controller = (PatientIdentifierTypeFormController) applicationContext
  64. .getBean("patientIdentifierTypeForm");
  65. controller.setApplicationContext(applicationContext);
  66. controller.setSuccessView("index.htm");
  67. controller.setFormView("PatientIdentifierType.form");
  68.  
  69. MockHttpServletRequest request = new MockHttpServletRequest("GET",
  70. "/admin/patients/patientIdentifierType.form?patientIdentifierTypeId=2");
  71. request.setSession(new MockHttpSession(null));
  72. HttpServletResponse response = new MockHttpServletResponse();
  73. controller.handleRequest(request, response);
  74.  
  75. request.setMethod("POST");
  76.  
  77. request.addParameter("action", "Delete PatientIdentifierType");
  78.  
  79. // send the parameters to the controller
  80. ModelAndView mav = controller.handleRequest(request, response);
  81.  
  82. Assert.assertEquals("The purge attempt should have failed!", "PatientIdentifierType.form", mav.getViewName());
  83. Assert.assertSame(controller.getFormView(), mav.getViewName());
  84. Assert.assertNotNull(patientService.getPatientIdentifierType(2));
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement