Example usage for org.springframework.validation Errors getErrorCount

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

Introduction

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

Prototype

int getErrorCount();

Source Link

Document

Return the total number of errors.

Usage

From source file:org.mifos.core.AbstractDtoValidationTest.java

protected void verifyFieldError(Object dto, String fieldName, String errorMessage) {
    Errors errors = getErrors(dto);
    Assert.assertTrue(errors.getErrorCount() > 0, "Expected errors but got none.");
    FieldError fieldError = errors.getFieldError(fieldName);
    Assert.assertNotNull(fieldError, "Expected error on field " + fieldName + ", but got none");
    Assert.assertEquals(fieldError.getDefaultMessage(), errorMessage, "Incorrect validation error message.");
}

From source file:nl.surfnet.coin.teams.service.impl.InvitationValidatorTest.java

@Test
public void testValidate() throws Exception {
    Invitation invitation = new Invitation("valid@example.com", null);
    Errors errors = new BeanPropertyBindingResult(invitation, "invitation");
    validator.validate(invitation, errors);
    assertEquals(0, errors.getErrorCount());
}

From source file:nl.surfnet.coin.teams.service.impl.InvitationValidatorTest.java

@Test
public void testFailOnNoEmail() throws Exception {
    Invitation invitation = new Invitation("", null);
    Errors errors = new BeanPropertyBindingResult(invitation, "invitation");
    validator.validate(invitation, errors);
    assertEquals(1, errors.getErrorCount());
}

From source file:nl.surfnet.coin.teams.service.impl.InvitationValidatorTest.java

@Test
public void testFailOnInvalidEmail() throws Exception {
    Invitation invitation = new Invitation("invalid.email.example.com", null);
    Errors errors = new BeanPropertyBindingResult(invitation, "invitation");
    validator.validate(invitation, errors);
    assertEquals(1, errors.getErrorCount());
}

From source file:nl.surfnet.coin.teams.service.impl.InvitationFormValidatorTest.java

@Test
public void testValidationFails() throws Exception {
    InvitationForm form = new InvitationForm();
    form.setEmails("must.be,valid@example.com");
    Errors errors = new BeanPropertyBindingResult(form, "invitationForm");
    validator.validate(form, errors);// www .  jav a2 s  .  c  o  m
    assertEquals(1, errors.getErrorCount());
}

From source file:nl.surfnet.coin.teams.service.impl.InvitationFormValidatorTest.java

@Test
public void testValidateForCSVInput() throws Exception {
    InvitationForm form = new InvitationForm();
    String mails = "test@example.com,test@example.net,john.doe@example.org";
    MultipartFile mockFile = new MockMultipartFile("mockFile", "test.csv", "text/csv", mails.getBytes("utf-8"));
    form.setCsvFile(mockFile);/*from   ww w.j  a va2  s.  co  m*/
    Errors errors = new BeanPropertyBindingResult(form, "invitationForm");
    validator.validate(form, errors);
    assertEquals(0, errors.getErrorCount());
}

From source file:nl.surfnet.coin.teams.service.impl.InvitationFormValidatorTest.java

@Test
public void testValidateForEmailsInput() throws Exception {
    InvitationForm form = new InvitationForm();
    form.setEmails("test@example.com");
    Errors errors = new BeanPropertyBindingResult(form, "invitationForm");
    validator.validate(form, errors);//from   w w w.j  ava 2 s . c  om
    assertEquals(0, errors.getErrorCount());
    form.setEmails("test@example.com,   test@example.net");
    validator.validate(form, errors);
    assertEquals(0, errors.getErrorCount());
}

From source file:org.mifos.loan.service.LoanProductDtoValidationTest.java

public void testMinInterestRate() {
    loanProductDto.setMinInterestRate(5.0);
    Errors errors = getErrors(loanProductDto);
    logger.info(errors);//from www  .  j av  a2  s  .c  o m
    Assert.assertTrue(errors.getErrorCount() > 0, "Expected errors but got none.");
}

From source file:net.maritimecloud.identityregistry.validators.VesselValidatorTests.java

@Test
public void validateValidVesselNoAttributes() {
    Vessel validVessel = new Vessel();
    validVessel.setMrn("urn:mrn:mcl:vessel:test-org:valid-vessel");
    validVessel.setName("Test Vessel");
    Errors errors = new BeanPropertyBindingResult(validVessel, "validVessel");
    this.vesselValidator.validate(validVessel, errors);
    assertEquals(0, errors.getErrorCount());
}

From source file:net.maritimecloud.endorsement.validators.EndorsementValidatorTest.java

@Test
public void validateValidEndorsement() {
    Endorsement validEndorsement = new Endorsement();
    validEndorsement.setOrgMrn("urn:mrn:mcl:org:dma");
    validEndorsement.setOrgName("DMA");
    validEndorsement.setServiceMrn("urn:mrn:mcl:service-instance:dma:nw-nv");
    validEndorsement.setServiceVersion("0.1.2");
    validEndorsement.setServiceLevel("instance");
    validEndorsement.setUserMrn("urn:mrn:mcl:user:dma:tgc");
    validEndorsement.setParentMrn("urn:mrn:mcl:service-design:dma:nw-nv");
    validEndorsement.setParentVersion("0.3.2");

    Errors errors = new BeanPropertyBindingResult(validEndorsement, "validEndorsement");
    endorsementValidator.validate(validEndorsement, errors);
    System.out.println(errors.getErrorCount());
    assertEquals(0, errors.getErrorCount());

}