List of usage examples for org.springframework.validation BeanPropertyBindingResult hasFieldErrors
@Override
public boolean hasFieldErrors(String field)
From source file:org.openmrs.web.controller.encounter.LocationFormControllerTest.java
/** * @see LocationFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) *//*from w w w .j av a2 s. c om*/ @Test @Verifies(value = "should not retire location if reason is empty", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)") public void onSubmit_shouldNotRetireLocationIfReasonIsEmpty() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("POST", ""); request.setParameter("locationId", "1"); request.setParameter("retireReason", ""); request.setParameter("retired", "true"); request.setParameter("retireLocation", "true"); HttpServletResponse response = new MockHttpServletResponse(); LocationFormController controller = getLocationFormController(); ModelAndView modelAndView = controller.handleRequest(request, response); // make sure an error is returned because of the empty retire reason BeanPropertyBindingResult bindingResult = (BeanPropertyBindingResult) modelAndView.getModel() .get("org.springframework.validation.BindingResult.location"); Assert.assertTrue(bindingResult.hasFieldErrors("retireReason")); }
From source file:de.blizzy.documentr.web.access.UserControllerTest.java
@Test public void saveUserPassword1Blank() throws IOException { UserForm user = new UserForm("user", "user", StringUtils.EMPTY, "pw", "email", true, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(user, "userForm"); //$NON-NLS-1$ String view = userController.saveUser(user, bindingResult, authentication); assertEquals("/user/edit", view); //$NON-NLS-1$ assertTrue(bindingResult.hasErrors()); assertTrue(bindingResult.hasFieldErrors("password1")); //$NON-NLS-1$ }
From source file:de.blizzy.documentr.web.access.UserControllerTest.java
@Test public void saveUserPassword2Blank() throws IOException { UserForm user = new UserForm("user", "user", "pw", StringUtils.EMPTY, "email", true, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(user, "userForm"); //$NON-NLS-1$ String view = userController.saveUser(user, bindingResult, authentication); assertEquals("/user/edit", view); //$NON-NLS-1$ assertTrue(bindingResult.hasErrors()); assertTrue(bindingResult.hasFieldErrors("password2")); //$NON-NLS-1$ }
From source file:de.blizzy.documentr.web.access.UserControllerTest.java
@Test public void saveUserPasswordsDiffer() throws IOException { UserForm user = new UserForm("user", "user", "pw", "pw2", "email", true, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(user, "userForm"); //$NON-NLS-1$ String view = userController.saveUser(user, bindingResult, authentication); assertEquals("/user/edit", view); //$NON-NLS-1$ assertTrue(bindingResult.hasErrors()); assertTrue(bindingResult.hasFieldErrors("password1")); //$NON-NLS-1$ assertTrue(bindingResult.hasFieldErrors("password2")); //$NON-NLS-1$ }