Example usage for org.springframework.validation BindingResult getErrorCount

List of usage examples for org.springframework.validation BindingResult getErrorCount

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult getErrorCount.

Prototype

int getErrorCount();

Source Link

Document

Return the total number of errors.

Usage

From source file:cherry.foundation.validator.TelNoValidatorTest.java

@Test
public void testNG() {

    Map<String, String> val = new HashMap<>();
    val.put("telNo0", "01-234-567");
    val.put("telNo1", "0123-1234-5678");
    val.put("telNo2", "0a-2345-6789");
    val.put("telNo3", "01-a345-6789");
    val.put("telNo4", "01-234a-6789");
    val.put("telNo5", "01-2345-a789");
    val.put("telNo6", "01-2345-678a");

    TestDto dto = new TestDto();

    WebDataBinder binder = new WebDataBinder(dto);
    binder.setConversionService(conversionService);
    binder.addValidators(validator);//w w w  . ja v a  2  s.  c o m
    binder.bind(new MutablePropertyValues(val));
    binder.validate();
    BindingResult result = binder.getBindingResult();
    assertEquals(7, result.getErrorCount());
}

From source file:cherry.foundation.validator.CharTypeValidatorTest.java

@Test
public void testNG() {

    Map<String, String> val = new HashMap<>();
    val.put("none", "0");
    val.put("space", " \t\r\n0");
    val.put("numeric", "0123456789A");
    val.put("alpha", "ABCabc0");
    val.put("upper", "ABCa");
    val.put("lower", "abcA");

    TestDto dto = new TestDto();

    WebDataBinder binder = new WebDataBinder(dto);
    binder.setConversionService(conversionService);
    binder.addValidators(validator);// w  ww .j  ava  2  s .  c o  m
    binder.bind(new MutablePropertyValues(val));
    binder.validate();
    BindingResult result = binder.getBindingResult();
    assertThat(result.getErrorCount(), is(6));
}

From source file:cherry.foundation.validator.CharTypeValidatorTest.java

@Test
public void testOK() {

    Map<String, String> val = new HashMap<>();
    val.put("none", "");
    val.put("space", " \t\r\n");
    val.put("numeric", "0123456789");
    val.put("alpha", "ABCabc");
    val.put("upper", "ABC");
    val.put("lower", "abc");
    val.put("surrogate", "\uD842\uDF9F");

    TestDto dto = new TestDto();

    WebDataBinder binder = new WebDataBinder(dto);
    binder.setConversionService(conversionService);
    binder.addValidators(validator);/*from   w w w. j a  v a2  s .com*/
    binder.bind(new MutablePropertyValues(val));
    binder.validate();
    BindingResult result = binder.getBindingResult();
    assertThat(result.getErrorCount(), is(0));
    assertThat(dto.getSpace(), is(" \t\r\n"));
    assertThat(dto.getNumeric(), is("0123456789"));
    assertThat(dto.getAlpha(), is("ABCabc"));
    assertThat(dto.getUpper(), is("ABC"));
    assertThat(dto.getLower(), is("abc"));
    assertThat(dto.getSurrogate(), is("\uD842\uDF9F"));
}

From source file:es.unileon.ulebank.service.SearchClientControllerTest.java

/**
 * Test of onSubmit method, of class SearchClientController.
 *//*from ww w  . j  av  a2 s  .co  m*/
@Test
public void testOnSubmit() {
    System.out.println("onSubmit");
    DniClient dniCorrect = new DniClient();
    DniClient dniIncorrect = new DniClient();

    dniIncorrect.setDni("incorrect");
    dniCorrect.setDni("96443956B");

    BindingResult bindingResult = new BeanPropertyBindingResult(dniCorrect, "dniCorrect");
    System.out.println(bindingResult.getErrorCount());

    //problems with bindingResult, can not make working this test
    //tried to move source code to SearchManager without sucess-> at least, I can test
    //that piece of source code in another test file
    //        ModelAndView result = instance.onSubmit(dniCorrect, bindingResult);
    //        assertEquals("showClient", result.getViewName());

    //        result = instance.onSubmit(dniIncorrect, bindingResult);
    //        assertEquals("searchClient", result.getViewName());

}

From source file:cherry.foundation.validator.TelNoValidatorTest.java

@Test
public void testOK() {

    Map<String, String> val = new HashMap<>();
    val.put("telNo0", null);
    val.put("telNo1", "");
    val.put("telNo2", "01-234-5678");
    val.put("telNo3", "01-2345-6789");
    val.put("telNo4", "012-345-6789");
    val.put("telNo5", "0123-45-6789");
    val.put("telNo6", "01234-5-6789");
    val.put("telNo7", "090-1234-5678");
    val.put("telNo8", "0120-123-456");

    TestDto dto = new TestDto();

    WebDataBinder binder = new WebDataBinder(dto);
    binder.setConversionService(conversionService);
    binder.addValidators(validator);//from  w  ww . j  a  v a  2 s  . co m
    binder.bind(new MutablePropertyValues(val));
    binder.validate();
    BindingResult result = binder.getBindingResult();
    assertEquals(0, result.getErrorCount());
    assertNull(dto.getTelNo0());
    assertEquals("", dto.getTelNo1());
    assertEquals("01-234-5678", dto.getTelNo2());
    assertEquals("01-2345-6789", dto.getTelNo3());
    assertEquals("012-345-6789", dto.getTelNo4());
    assertEquals("0123-45-6789", dto.getTelNo5());
    assertEquals("01234-5-6789", dto.getTelNo6());
    assertEquals("090-1234-5678", dto.getTelNo7());
    assertEquals("0120-123-456", dto.getTelNo8());
}

From source file:org.mifos.user.service.StandardUserService.java

private void validateDetails(UserDto userDto) throws MifosValidationException {
    BindingResult errors = new BeanPropertyBindingResult(userDto, "user");
    userDetailsValidator.validate(userDto, errors);
    if (errors.getErrorCount() > 0) {
        throw new MifosValidationException("User validation error", errors);
    }/*www .  j  av  a 2  s.  co  m*/
}

From source file:org.easy.spring.web.ValidationSupport.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)//from www. jav  a2 s . c o  m
@ResponseBody
public ValidationError processValidationError(MethodArgumentNotValidException ex) {
    BindingResult errors = ex.getBindingResult();
    ValidationError result = new ValidationError(errors.getObjectName(), errors.getNestedPath(),
            errors.getErrorCount(), errors.getFieldErrors());

    return result;//processFieldErrors(fieldErrors);
}

From source file:web.Integration.TrialAccountCreationTest.java

public BindingResult valid(TenantForm form) throws Exception {
    // Validate form
    BindingResult result = validate(form);
    Assert.assertEquals("validating that the form has no errors", 0, result.getErrorCount());
    return result;
}

From source file:org.frat.common.validation.ValidateException.java

/**
 * //from ww  w .j  a  v a  2 s  .c om
 * Description: TODO.
 * 
 * @return
 */
public int getErrorCount() {
    int errorCount = 0;
    if (bindingResults != null && bindingResults.size() > 0) {
        for (BindingResult bindingResult : bindingResults) {
            if (bindingResult.hasErrors()) {
                errorCount += bindingResult.getErrorCount();
            }
        }
    }
    return errorCount;
}

From source file:com.google.ie.web.controller.AuditController.java

/**
 * Handles the request for saving Audit entity.
 * This request is initiated by TaskQueue for auditing the user actions on
 * the entity.//w  ww . j  a  v  a  2s .  c o m
 */
@RequestMapping("/audits/save")
public String saveAudit(@ModelAttribute Audit audit, BindingResult result, Map<String, Object> model) {

    ViewStatus viewstStatus = new ViewStatus();

    if (result.hasErrors()) {
        log.warn("Audit object has " + result.getErrorCount() + " validation errors");
        viewstStatus.setStatus(WebConstants.ERROR);
        viewstStatus.addMessage(WebConstants.ERROR, "Audit object has validation errors");
    } else {
        auditService.saveAudit(audit);
        viewstStatus.setStatus(WebConstants.SUCCESS);
        viewstStatus.addMessage(WebConstants.SUCCESS, "Auditing is successfully done.");
    }
    model.put(WebConstants.AUDIT, viewstStatus);
    return "queue/queue";
}