Advertisement
Guest User

dfg

a guest
Apr 13th, 2012
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 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.person;
  15.  
  16. import javax.servlet.http.HttpServletRequest;
  17. import javax.servlet.http.HttpServletResponse;
  18.  
  19. import org.junit.Assert;
  20. import org.junit.Test;
  21. import org.openmrs.api.context.Context;
  22. import org.openmrs.test.Verifies;
  23. import org.openmrs.web.test.BaseWebContextSensitiveTest;
  24. import org.springframework.mock.web.MockHttpServletRequest;
  25. import org.springframework.mock.web.MockHttpServletResponse;
  26. import org.springframework.validation.BeanPropertyBindingResult;
  27. import org.springframework.validation.BindException;
  28. import org.springframework.web.servlet.ModelAndView;
  29.  
  30. /**
  31.  * Tests for the {@link AddPersonController} which handles the Add Person.form page.
  32.  */
  33. public class AddPersonControllerTest extends BaseWebContextSensitiveTest {
  34.  
  35.    /**
  36.      * @see {@link AddPersonController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)}
  37.      */
  38.     @Test
  39.     @Verifies(value = "check BirthDate is entered properly", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)")
  40.     public void onSubmit_shouldAcceptBirthDateEnteredCorrectly() throws Exception {
  41.  
  42.         MockHttpServletRequest request = new MockHttpServletRequest("POST", "");
  43.  
  44.         request.setParameter("addName", "Gayan Perera");
  45.         request.setParameter("addBirthdate", "03/07/1990");
  46.         request.setParameter("addGender", "Male");
  47.         request.setParameter("personType", "patient");
  48.         request.setParameter("viewType", "edit");
  49.  
  50.         HttpServletResponse response = new MockHttpServletResponse();
  51.         AddPersonController controller = (AddPersonController) applicationContext.getBean("addPerson");
  52.         ModelAndView modelAndView = controller.handleRequest(request, response);
  53.  
  54.         BeanPropertyBindingResult bindingResult = (BeanPropertyBindingResult) modelAndView.getModel().get(
  55.                 "org.springframework.validation.BindingResult.people");
  56.         Assert.assertFalse(bindingResult.hasErrors());
  57.  
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement