@Override public int getErrorCount() { return this.source.getErrorCount(); }
@Override public int getErrorCount() { return this.source.getErrorCount(); }
private int getErrorCount(ModelMap model) { int count = 0; for (Object value : model.values()) { if (value instanceof Errors) { count += ((Errors) value).getErrorCount(); } } return count; }
@ResponseStatus(code = HttpStatus.ACCEPTED) @ResponseBody public String handleAndValidateRequestBody(@Valid TestBean modelAttr, Errors errors) { return "Error count [" + errors.getErrorCount() + "]"; }
logger.debug("Validator found " + errors.getErrorCount() + " errors");
/** * Assert the given model attribute(s) have errors. */ public ResultMatcher attributeErrorCount(final String name, final int expectedCount) { return result -> { ModelAndView mav = getModelAndView(result); Errors errors = getBindingResult(mav, name); assertEquals("Binding/validation error count for attribute '" + name + "', ", expectedCount, errors.getErrorCount()); }; }
public void handleAndValidateRequestPart(@RequestPart @Valid String requestPart, Errors errors, Model model) throws Exception { model.addAttribute("error count", errors.getErrorCount()); }
logger.debug("Validator found " + errors.getErrorCount() + " errors");
assertTrue("Correct number of errors", errors.getErrorCount() == 4); assertTrue("Correct object name", "tb".equals(errors.getObjectName()));
assertEquals(6, errors.getErrorCount());
/** * Validate given form object using a registered validator. If a "validatorMethod" action property is specified for * the currently executing action, the identified validator method will be invoked. When no such property is found, * the defualt <code>validate()</code> method is invoked. * @param context the action execution context, for accessing and setting data in "flow scope" or "request scope" * @param formObject the form object * @param errors the errors instance to record validation errors in * @throws Exception when an unrecoverable exception occurs */ protected void doValidate(RequestContext context, Object formObject, Errors errors) throws Exception { Assert.notNull(getValidator(), "The validator must not be null when attempting validation -- programmer error"); String validatorMethodName = context.getAttributes().getString(VALIDATOR_METHOD_ATTRIBUTE); if (StringUtils.hasText(validatorMethodName)) { if (logger.isDebugEnabled()) { logger.debug("Invoking validation method '" + validatorMethodName + "' on validator " + getValidator()); } invokeValidatorMethod(validatorMethodName, formObject, errors); } else { if (logger.isDebugEnabled()) { logger.debug("Invoking validator " + getValidator()); } getValidator().validate(formObject, errors); } if (logger.isDebugEnabled()) { logger.debug("Validation completed for form object"); logger.debug("There are [" + errors.getErrorCount() + "] errors, details: " + errors.getAllErrors()); } }
assertEquals("spouse.", errors.getNestedPath()); assertEquals(1, errors.getErrorCount()); assertTrue(!errors.hasGlobalErrors()); assertEquals(1, errors.getFieldErrorCount("age"));
@Test public void testSendWithError() throws Exception { QueueChannel requestChannel = new QueueChannel() { @Override protected boolean doSend(Message<?> message, long timeout) { throw new RuntimeException("Planned"); } }; HttpRequestHandlingController controller = new HttpRequestHandlingController(false); controller.setBeanFactory(mock(BeanFactory.class)); controller.setRequestChannel(requestChannel); controller.afterPropertiesSet(); controller.start(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.setContent("hello".getBytes()); request.setContentType("text/plain"); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView modelAndView = controller.handleRequest(request, response); assertEquals(1, modelAndView.getModel().size()); Errors errors = (Errors) modelAndView.getModel().get("errors"); assertEquals(1, errors.getErrorCount()); ObjectError error = errors.getAllErrors().get(0); assertEquals(3, error.getArguments().length); assertTrue("Wrong message: " + error, ((String) error.getArguments()[1]).startsWith("failed to send Message")); }
private int getErrorCount(ModelMap model) { int count = 0; for (Object value : model.values()) { if (value instanceof Errors) { count += ((Errors) value).getErrorCount(); } } return count; }
private int getErrorCount(ModelMap model) { int count = 0; for (Object value : model.values()) { if (value instanceof Errors) { count += ((Errors) value).getErrorCount(); } } return count; }
/** * Assert the given model attribute(s) have errors. */ public ResultMatcher attributeErrorCount(final String name, final int expectedCount) { return result -> { ModelAndView mav = getModelAndView(result); Errors errors = getBindingResult(mav, name); assertEquals("Binding/validation error count for attribute '" + name + "', ", expectedCount, errors.getErrorCount()); }; }
static final Operation populateOperation (Operation op, Errors errors, boolean collectErrorsList) { int numErrors=(errors == null) ? 0 : errors.getErrorCount(); op.put(ERRORS_COUNT, numErrors); if ((numErrors > 0) && collectErrorsList) { populateOperation(op.createList(ERRORS_LIST), errors); } return op; }
public static ValidationErrorBuilder builder(Errors errors) { ValidationErrorBuilder builder = new ValidationErrorBuilder( "Validation failed: " + errors.getErrorCount() + " error(s)"); for (ObjectError objectError : errors.getAllErrors()) { builder.error(objectError.getDefaultMessage()); } return builder; }
public static ValidationErrorBuilder builder(Errors errors) { ValidationErrorBuilder builder = new ValidationErrorBuilder( "Validation failed: " + errors.getErrorCount() + " error(s)"); for (ObjectError objectError : errors.getAllErrors()) { builder.error(objectError.getDefaultMessage()); } return builder; }
@Test public void test_validate_enrollment_state_to_throw_an_error_with_wrong_input() throws Exception { errors = new MapBindingResult(new HashMap<>(), "OrgEnrollmentConfig"); when(request.getState()).thenReturn("not_backoffice_enrolled"); when(stateReader.readParameter("not_backoffice_enrolled", false)) .thenThrow(new InvalidParameterException("state", "Error")); enrollmentValidator.validate(request, errors); assertTrue(errors.getErrorCount() == 1); }