@Override public int getGlobalErrorCount() { return this.source.getGlobalErrorCount(); }
@Override public int getGlobalErrorCount() { return this.source.getGlobalErrorCount(); }
@Test public void testNestedValidatorWithoutNestedPath() { TestBean tb = new TestBean(); tb.setName("XXX"); Errors errors = new BeanPropertyBindingResult(tb, "tb"); Validator spouseValidator = new SpouseValidator(); spouseValidator.validate(tb, errors); assertTrue(errors.hasGlobalErrors()); assertEquals(1, errors.getGlobalErrorCount()); assertEquals("SPOUSE_NOT_AVAILABLE", errors.getGlobalError().getCode()); assertEquals("tb", (errors.getGlobalErrors().get(0)).getObjectName()); }
assertTrue("Correct number of global errors", errors.getGlobalErrorCount() == 1); ObjectError globalError = errors.getGlobalError(); String defaultMessage = globalError.getDefaultMessage();
assertEquals(6, errors.getErrorCount()); assertEquals(2, errors.getGlobalErrorCount()); assertEquals("NAME_TOUCHY_MISMATCH", errors.getGlobalError().getCode()); assertEquals("NAME_TOUCHY_MISMATCH", (errors.getGlobalErrors().get(0)).getCode());
@Override public int getGlobalErrorCount() { return this.source.getGlobalErrorCount(); }
@Override public int getGlobalErrorCount() { return this.source.getGlobalErrorCount(); }
public int getGlobalErrorCount() { return this.source.getGlobalErrorCount(); }
/** * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailIfObsHasNoValuesAndNotParent() { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setConcept(Context.getConceptService().getConcept(18)); obs.setObsDatetime(new Date()); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertTrue(errors.getGlobalErrorCount() > 0); }
public void testMessageCodesOnBindFailure() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setPathInfo("/fooFlow"); request.setMethod("POST"); request.addParameter("prop", "A"); MockHttpServletResponse response = new MockHttpServletResponse(); MockRequestContext context = new MockRequestContext(); context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response)); context.setAttribute("method", "bindAndValidate"); // use a FormAction to do the binding FormAction formAction = new FormAction(); formAction.setFormObjectClass(TestBean.class); formAction.setFormObjectName("formObject"); formAction.execute(context); Errors formActionErrors = new FormObjectAccessor(context).getCurrentFormErrors(formAction.getFormErrorsScope()); assertNotNull(formActionErrors); assertTrue(formActionErrors.hasErrors()); assertEquals(1, formActionErrors.getErrorCount()); assertEquals(0, formActionErrors.getGlobalErrorCount()); assertEquals(1, formActionErrors.getFieldErrorCount("prop")); }