Search in sources :

Example 51 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class PrivilegeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see PrivilegeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    Privilege priv = new Privilege();
    priv.setPrivilege("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    priv.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(priv, "priv");
    new PrivilegeValidator().validate(priv, errors);
    Assert.assertTrue(errors.hasFieldErrors("privilege"));
    Assert.assertTrue(errors.hasFieldErrors("description"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Privilege(org.openmrs.Privilege) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 52 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class ConceptNameTagValidatorTest method validate_shouldFailValidationIfConceptNameTagIsNull.

@Test(expected = IllegalArgumentException.class)
public void validate_shouldFailValidationIfConceptNameTagIsNull() {
    Errors errors = new BindException(new ConceptNameTag(), "cnt");
    new ConceptNameTagValidator().validate(null, errors);
}
Also used : Errors(org.springframework.validation.Errors) ConceptNameTag(org.openmrs.ConceptNameTag) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 53 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class ConceptNameTagValidatorTest method validate_shouldFailValidationIfTagIsNullOrEmptyOrWhitespace.

/**
 * @see ConceptNameTagValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfTagIsNullOrEmptyOrWhitespace() {
    ConceptNameTag cnt = new ConceptNameTag();
    Errors errors = new BindException(cnt, "cnt");
    new ConceptNameTagValidator().validate(cnt, errors);
    Assert.assertTrue(errors.hasFieldErrors("tag"));
    cnt.setTag("");
    errors = new BindException(cnt, "cnt");
    new ConceptNameTagValidator().validate(cnt, errors);
    Assert.assertTrue(errors.hasFieldErrors("tag"));
    cnt.setTag(" ");
    errors = new BindException(cnt, "cnt");
    new ConceptNameTagValidator().validate(cnt, errors);
    Assert.assertTrue(errors.hasFieldErrors("tag"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptNameTag(org.openmrs.ConceptNameTag) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 54 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class ConceptSourceValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    ConceptSource conceptSource = new ConceptSource();
    conceptSource.setName("New name");
    conceptSource.setDescription("Some description");
    conceptSource.setHl7Code("Hl7Code");
    conceptSource.setRetireReason("RetireReason");
    Errors errors = new BindException(conceptSource, "conceptSource");
    new ConceptSourceValidator().validate(conceptSource, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptSource(org.openmrs.ConceptSource) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 55 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class ConceptSourceValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.

@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
    ConceptSource conceptSource = new ConceptSource();
    conceptSource.setName("New name");
    conceptSource.setDescription("Some description");
    Errors errors = new BindException(conceptSource, "conceptSource");
    new ConceptSourceValidator().validate(conceptSource, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptSource(org.openmrs.ConceptSource) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

BindException (org.springframework.validation.BindException)458 Test (org.junit.Test)402 Errors (org.springframework.validation.Errors)387 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)384 Date (java.util.Date)61 OrderUtilTest (org.openmrs.order.OrderUtilTest)58 DrugOrder (org.openmrs.DrugOrder)56 Patient (org.openmrs.Patient)40 Calendar (java.util.Calendar)30 Concept (org.openmrs.Concept)26 Encounter (org.openmrs.Encounter)25 TestOrder (org.openmrs.TestOrder)23 OrderType (org.openmrs.OrderType)22 Obs (org.openmrs.Obs)20 Order (org.openmrs.Order)20 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)19 Visit (org.openmrs.Visit)19 PatientProgram (org.openmrs.PatientProgram)18 PatientIdentifierType (org.openmrs.PatientIdentifierType)17 Drug (org.openmrs.Drug)15