Advertisement
Guest User

Untitled

a guest
Aug 16th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 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.encounter;
  15.  
  16. import javax.servlet.http.HttpServletResponse;
  17.  
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.openmrs.api.EncounterService;
  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 EncounterTypeFormControllerTest extends BaseWebContextSensitiveTest {
  29.  
  30. @Test
  31. public void shouldNotDeleteEncounterTypeWhenEncounterTypesAreLocked() throws Exception {
  32. // dataset to lock encounter types
  33. executeDataSet("org/openmrs/web/encounter/include/EncounterTypeFormControllerTest.xml");
  34.  
  35. EncounterService es = Context.getEncounterService();
  36.  
  37. EncounterTypeFormController controller = (EncounterTypeFormController) applicationContext.getBean("encounterForm");
  38. controller.setApplicationContext(applicationContext);
  39. controller.setSuccessView("index.htm");
  40. controller.setFormView("EncounterType.form");
  41.  
  42. // setting up the request and doing an initial "get" equivalent to the user loading the page for the first time
  43. MockHttpServletRequest request = new MockHttpServletRequest("GET", "/admin/encounters/encounterType.form?encounterTypeId=1");
  44. request.setSession(new MockHttpSession(null));
  45. HttpServletResponse response = new MockHttpServletResponse();
  46. controller.handleRequest(request, response);
  47.  
  48. // set this to be a page submission
  49. request.setMethod("POST");
  50.  
  51. request.addParameter("action", "Delete EncounterType"); // so that the form is processed
  52.  
  53. // send the parameters to the controller
  54. ModelAndView mav = controller.handleRequest(request, response);
  55.  
  56. Assert.assertNotSame("The purge attempt should have failed!", "index.htm", mav.getViewName());
  57. Assert.assertNotNull(es.getEncounterType(1));
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement