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:org.terasoluna.tourreservation.app.managecustomer.CustomerPassEqualsValidatorTest.java

/**
 * check validate return nothing passConfirm is null
 *///  w  w w  . ja  v  a 2 s. c  o m
@Test
public void testValidate03() {
    CustomerPassEqualsValidator validator = new CustomerPassEqualsValidator();
    CustomerForm customer = new CustomerForm();
    customer.setCustomerPass("12345");

    BindingResult result = new DirectFieldBindingResult(customer, "CustomerForm");

    // run
    validator.validate(customer, result);

    // assert
    assertThat(result.hasErrors(), is(false));
    assertThat(result.getErrorCount(), is(0));
}

From source file:org.terasoluna.tourreservation.app.managecustomer.CustomerPassEqualsValidatorTest.java

/**
 * check validate normal return//  w w  w  .  j  a  v a  2  s .  co  m
 */
@Test
public void testValidate01() {
    CustomerPassEqualsValidator validator = new CustomerPassEqualsValidator();
    CustomerForm customer = new CustomerForm();
    customer.setCustomerPass("12345");
    customer.setCustomerPassConfirm("12345");

    BindingResult result = new DirectFieldBindingResult(customer, "CustomerForm");

    // run
    validator.validate(customer, result);

    // assert
    assertThat(result.hasErrors(), is(false));
    assertThat(result.getErrorCount(), is(0));
}

From source file:org.terasoluna.tourreservation.app.managecustomer.CustomerPassEqualsValidatorTest.java

/**
 * check validate return nothing password is null
 *///from  ww w  .  j a  va  2  s . com
@Test
public void testValidate04() {
    CustomerPassEqualsValidator validator = new CustomerPassEqualsValidator();
    CustomerForm customer = new CustomerForm();
    customer.setCustomerPassConfirm("12345");

    BindingResult result = new DirectFieldBindingResult(customer, "CustomerForm");

    // run
    validator.validate(customer, result);

    // assert
    assertThat(result.hasErrors(), is(false));
    assertThat(result.getErrorCount(), is(0));

}

From source file:com.healthcit.cacure.web.controller.LoginControllerTest.java

@SuppressWarnings("unchecked")
@Test/*from w w  w.  j a va  2 s.c  om*/
public void testOnSubmitForWithtValidationErrors() {
    Map inputMap = new HashMap();
    inputMap.put(ContentElementEditController.FORM_ID_NAME, 2l);
    UserCredentials userCredentials = new UserCredentials();
    userCredentials.setUserName("Testing");
    //userCredentials.setPassword("TestPassword");
    BindingResult bindingResult = new BeanPropertyBindingResult(userCredentials, "userCredentials");
    MockHttpServletRequest req = new MockHttpServletRequest();
    String actual = loginController.onSubmit(userCredentials, bindingResult, req,
            new MockHttpServletResponse());
    Assert.assertNotNull(actual);
    Assert.assertEquals(bindingResult.getErrorCount(), 1);
    Assert.assertEquals(req.getAttribute(ATTR_VALIDATION_ERR), Boolean.TRUE);
}

From source file:org.openmrs.module.cohort.web.controller.AddCohortMemberAttributeTypeController.java

@RequestMapping(value = "/module/cohort/addCohortMemberAttributeType.form", method = RequestMethod.POST)
public String onSubmit(WebRequest request, HttpSession httpSession, ModelMap model,
        @ModelAttribute("cohortattributes") CohortMemberAttributeType cohortMemberAttributeType,
        BindingResult errors) {
    CohortService departmentService = Context.getService(CohortService.class);
    String voided = request.getParameter("voided");
    String format = request.getParameter("format");
    this.validator.validate(cohortMemberAttributeType, errors);
    if (errors.hasErrors()) {
        System.out.println("BR has errors: " + errors.getErrorCount());
        System.out.println(errors.getAllErrors());
        return "/module/cohort/addCohortMemberAttributeType";
    } else {//from ww w.j  ava2s . co m
        cohortMemberAttributeType.setFormat(format);
        departmentService.saveCohortMemberAttributeType(cohortMemberAttributeType);
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success");
    }
    return null;
}

From source file:org.cloudfoundry.identity.uaa.config.YamlBindingTests.java

@Test
public void testSimpleValidation() {
    ValidatedTarget target = new ValidatedTarget();
    BindingResult result = bind(target, "");
    assertEquals(1, result.getErrorCount());
}

From source file:com.github.javarch.jsf.mbeans.AbstractFormManagedBean.java

public String performAction() {

    log.debug("Iniciando performAction na entidade {}.", getEntityName());

    try {/*from  w  w  w  . ja va 2s.co  m*/
        checkPreconditions();

        Validator validator = useValidator();

        if (Optional.fromNullable(validator).isPresent()) {

            BindingResult errors = new BindException(getEntity(), getEntityName());
            validator.validate(getEntity(), errors);

            if (errors.hasErrors()) {
                log.debug("Gerando erros {} mensagens de erros no objeto FacesMessage.",
                        errors.getErrorCount());

                messageContext.addError(errors);

                return outcomeOnValidationsError;
            }
        }

        log.debug("execute onAction({}) ", entity);

        onAction(entity);

        log.debug("execute onAction {} with success!", entity);

        messageContext.addInfo(messageContext.getMessageI18n(getClass().getSimpleName() + ".create.success"));

        log.debug("outcome after action = {}", outcomeSuccess);

        return outcomeSuccess;

    } catch (Exception e) {
        log.error("Entity: " + entity + ". Detalhes do erro so:", e);

        messageContext.addError(
                messageContext.getMessageI18n(getClass().getSimpleName() + ".save.exception", e.getMessage()));

        return outcomeOnError;
    }
}

From source file:org.codeqinvest.web.sonar.SonarController.java

/**
 * This route can be used by JavaScript frontend code to verify if a
 * given Sonar server is reachable./* w  w w. j  a v a 2 s .  c  om*/
 */
@RequestMapping(value = "/reachable", method = RequestMethod.PUT)
@ResponseBody
SonarReachableStatus isSonarServerReachable(@RequestBody SonarServer sonarServer, BindingResult errors,
        HttpServletResponse response) {
    sonarServerValidator.validate(sonarServer, errors);
    if (errors.hasErrors()) {
        // TODO could be improved with exception and corresponding exception handler
        log.info("Rejected checking Sonar server {} due {} validation errors", sonarServer,
                errors.getErrorCount());
        response.setStatus(BAD_REQUEST);
        return null;
    }

    boolean isReachable = sonarConnectionCheckerService.isReachable(sonarServer.getConnectionSettings());
    log.info("Sonar server at {} is reachable: {}", sonarServer, isReachable);
    return new SonarReachableStatus(isReachable);
}

From source file:org.cloudfoundry.identity.uaa.config.YamlBindingTests.java

@Test
public void testRequiredFieldsValidation() {
    TargetWithValidatedMap target = new TargetWithValidatedMap();
    BindingResult result = bind(target, "info:\n  foo: bar");
    assertEquals(2, result.getErrorCount());
    for (FieldError error : result.getFieldErrors()) {
        System.err.println(new StaticMessageSource().getMessage(error, Locale.getDefault()));
    }/*from   ww  w.ja  va 2  s. c  om*/
}

From source file:org.cloudfoundry.identity.uaa.config.YamlBindingTests.java

@Test
public void testBindErrorTypeMismatch() {
    VanillaTarget target = new VanillaTarget();
    BindingResult result = bind(target, "foo: bar\nvalue: foo");
    assertEquals(1, result.getErrorCount());
}