Search in sources :

Example 46 with BindException

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

the class PersonAttributeTypeValidatorTest method validate_shouldFailValidationIfNameAlreadyInUse.

/**
 * @see PersonAttributeTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfNameAlreadyInUse() {
    PersonAttributeType type = new PersonAttributeType();
    type.setName("Birthplace");
    Errors errors = new BindException(type, "patObj");
    new PersonAttributeTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) PersonAttributeType(org.openmrs.PersonAttributeType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 47 with BindException

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

the class PersonAttributeTypeValidatorTest method validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace.

/**
 * @see PersonAttributeTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace() {
    PersonAttributeType type = new PersonAttributeType();
    type.setName("name");
    type.setDescription(null);
    Errors errors = new BindException(type, "type");
    new PersonAttributeTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasFieldErrors("description"));
    type.setDescription("");
    errors = new BindException(type, "type");
    new PersonAttributeTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasFieldErrors("description"));
    type.setDescription(" ");
    errors = new BindException(type, "type");
    new PersonAttributeTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasFieldErrors("description"));
}
Also used : Errors(org.springframework.validation.Errors) PersonAttributeType(org.openmrs.PersonAttributeType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 48 with BindException

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

the class PersonAttributeTypeValidatorTest method validate_shouldFailValidationIfFormatIsEmpty.

/**
 * @see PersonAttributeTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFormatIsEmpty() {
    PersonAttributeType type = new PersonAttributeType();
    type.setName("Zodiac");
    type.setDescription("Zodiac Description");
    type.setFormat("");
    Errors errors = new BindException(type, "patObj");
    new PersonAttributeTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("format"));
}
Also used : Errors(org.springframework.validation.Errors) PersonAttributeType(org.openmrs.PersonAttributeType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 49 with BindException

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

the class PersonAttributeTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see PersonAttributeTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    PersonAttributeType type = new PersonAttributeType();
    type.setName("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");
    type.setFormat("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");
    type.setRetireReason("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(type, "patObj");
    new PersonAttributeTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    Assert.assertTrue(errors.hasFieldErrors("format"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Also used : Errors(org.springframework.validation.Errors) PersonAttributeType(org.openmrs.PersonAttributeType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 50 with BindException

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

the class PrivilegeValidatorTest method validate_shouldFailValidationIfPrivilegeIsNullOrEmptyOrWhitespace.

/**
 * @see PrivilegeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfPrivilegeIsNullOrEmptyOrWhitespace() {
    Privilege priv = new Privilege();
    priv.setPrivilege(null);
    priv.setDescription("some text");
    Errors errors = new BindException(priv, "priv");
    new PrivilegeValidator().validate(priv, errors);
    Assert.assertTrue(errors.hasFieldErrors("privilege"));
    priv.setPrivilege("");
    errors = new BindException(priv, "priv");
    new PrivilegeValidator().validate(priv, errors);
    Assert.assertTrue(errors.hasFieldErrors("privilege"));
    priv.setPrivilege(" ");
    errors = new BindException(priv, "priv");
    new PrivilegeValidator().validate(priv, errors);
    Assert.assertTrue(errors.hasFieldErrors("privilege"));
}
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)

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