Advertisement
Guest User

Untitled

a guest
Mar 4th, 2014
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 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.form;
  15.  
  16. import javax.servlet.http.HttpServletResponse;
  17.  
  18. import org.junit.Assert;
  19. import org.junit.Before;
  20. import org.junit.Ignore;
  21. import org.junit.Test;
  22. import org.openmrs.api.FormService;
  23. import org.openmrs.api.context.Context;
  24. import org.openmrs.web.test.BaseWebContextSensitiveTest;
  25. import org.springframework.mock.web.MockHttpServletRequest;
  26. import org.springframework.mock.web.MockHttpServletResponse;
  27. import org.springframework.mock.web.MockHttpSession;
  28. import org.springframework.web.servlet.ModelAndView;
  29.  
  30. public class FormFormControllerTest extends BaseWebContextSensitiveTest {
  31.  
  32. private FormService formService;
  33.  
  34. @Before
  35. public void setup() {
  36. if (formService == null) {
  37. formService = Context.getFormService();
  38. }
  39. }
  40.  
  41. @Test
  42. public void shouldDeleteFormWhenFormsAreNotLocked() throws Exception {
  43. //setting the controller
  44. FormFormController controller = (FormFormController) applicationContext.getBean("formEditForm");
  45. controller.setApplicationContext(applicationContext);
  46. controller.setFormView("index.htm");
  47. controller.setSuccessView("formEdit.form");
  48.  
  49. MockHttpServletRequest request = new MockHttpServletRequest("GET", "/forms/formEdit.form?formId=1");
  50. request.setSession(new MockHttpSession(null));
  51. HttpServletResponse response = new MockHttpServletResponse();
  52. controller.handleRequest(request, response);
  53.  
  54. request.setMethod("POST");
  55.  
  56. request.addParameter("action", "Form.delete");
  57.  
  58. ModelAndView mav = controller.handleRequest(request, response);
  59.  
  60. Assert.assertSame(controller.getFormView(), mav.getViewName());
  61. Assert.assertEquals("The form should have been deleted!!!", "formEdit.form", mav.getViewName());
  62. Assert.assertNull(formService.getForm(1));
  63. }
  64.  
  65. @Test
  66. public void shouldNotSaveAFormWhenFormsAreLocked() throws Exception {
  67. // dataset to locks forms
  68. executeDataSet("org/openmrs/web/controller/include/FormFormControllerTest.xml");
  69.  
  70. //setting the controller
  71. FormFormController controller = (FormFormController) applicationContext.getBean("formEditForm");
  72. controller.setApplicationContext(applicationContext);
  73. controller.setFormView("index.htm");
  74. controller.setSuccessView("formEdit.form");
  75.  
  76. MockHttpServletRequest request = new MockHttpServletRequest("GET", "/forms/formEdit.form?formId=1");
  77. request.setSession(new MockHttpSession(null));
  78. HttpServletResponse response = new MockHttpServletResponse();
  79. controller.handleRequest(request, response);
  80.  
  81. request.setMethod("POST");
  82.  
  83. request.addParameter("action", "Save Form");
  84.  
  85. ModelAndView mav = controller.handleRequest(request, response);
  86.  
  87. Assert.assertEquals("The save attempt should have failed!", "index.htm", mav.getViewName());
  88. Assert.assertNotEquals("formEdit.form", mav.getViewName());
  89. Assert.assertSame(controller.getFormView(), mav.getViewName());
  90. Assert.assertNotNull(formService.getForm(1));
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement