Search in sources :

Example 41 with BindException

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

the class PatientValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see PatientValidator#validate(Object,Errors)
 */
@Override
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0);
    Patient patient = new Patient();
    PersonName pName = new PersonName();
    pName.setGivenName("Tom");
    pName.setMiddleName("E.");
    pName.setFamilyName("Patient");
    patient.addName(pName);
    patient.setGender("male");
    PersonAddress pAddress = new PersonAddress();
    pAddress.setAddress1("123 My street");
    pAddress.setAddress2("Apt 402");
    pAddress.setCityVillage("Anywhere city");
    pAddress.setCountry("Some Country");
    Set<PersonAddress> pAddressList = patient.getAddresses();
    pAddressList.add(pAddress);
    patient.setAddresses(pAddressList);
    patient.addAddress(pAddress);
    PatientIdentifier patientIdentifier1 = new PatientIdentifier();
    patientIdentifier1.setLocation(new Location(1));
    patientIdentifier1.setIdentifier("012345678");
    patientIdentifier1.setDateCreated(new Date());
    patientIdentifier1.setIdentifierType(patientIdentifierType);
    patient.addIdentifier(patientIdentifier1);
    patient.setVoidReason("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(patient, "patient");
    validator.validate(patient, errors);
    Assert.assertTrue(errors.hasFieldErrors("voidReason"));
}
Also used : Errors(org.springframework.validation.Errors) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Date(java.util.Date) Location(org.openmrs.Location) Test(org.junit.Test)

Example 42 with BindException

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

the class PatientValidatorTest method validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred.

@Test
public void validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred() {
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0);
    Patient patient = new Patient();
    PersonName pName = new PersonName();
    pName.setGivenName("Tom");
    pName.setMiddleName("E.");
    pName.setFamilyName("Patient");
    patient.addName(pName);
    patient.setGender("male");
    PersonAddress pAddress = new PersonAddress();
    pAddress.setAddress1("123 My street");
    pAddress.setAddress2("Apt 402");
    pAddress.setCityVillage("Anywhere city");
    pAddress.setCountry("Some Country");
    Set<PersonAddress> pAddressList = patient.getAddresses();
    pAddressList.add(pAddress);
    patient.setAddresses(pAddressList);
    patient.addAddress(pAddress);
    PatientIdentifier patientIdentifier1 = new PatientIdentifier();
    patientIdentifier1.setLocation(new Location(1));
    patientIdentifier1.setIdentifier("012345678");
    patientIdentifier1.setDateCreated(new Date());
    patientIdentifier1.setIdentifierType(patientIdentifierType);
    patient.addIdentifier(patientIdentifier1);
    Errors errors = new BindException(patient, "patient");
    validator.validate(patient, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Date(java.util.Date) Location(org.openmrs.Location) Test(org.junit.Test)

Example 43 with BindException

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

the class PatientValidatorTest method validate_shouldFailValidationIfAPreferredPatientIdentifierIsNotChosenForVoidedPatients.

/**
 * @see PatientValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfAPreferredPatientIdentifierIsNotChosenForVoidedPatients() {
    Patient pa = Context.getPatientService().getPatient(432);
    // sanity check
    Assert.assertTrue(pa.getVoided());
    Assert.assertNotNull(pa.getPatientIdentifier());
    for (PatientIdentifier id : pa.getIdentifiers()) id.setPreferred(false);
    Errors errors = new BindException(pa, "patient");
    validator.validate(pa, errors);
    Assert.assertTrue(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test)

Example 44 with BindException

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

the class PersonAttributeTypeValidatorTest method validate_shouldPassValidationIfAllFieldsAreCorreect.

/**
 * @see PersonAttributeTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllFieldsAreCorreect() {
    PersonAttributeType type = new PersonAttributeType();
    type.setName("Zodiac");
    type.setFormat("java.lang.String");
    type.setDescription("Zodiac Description");
    Errors errors = new BindException(type, "patObj");
    new PersonAttributeTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasErrors());
}
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 45 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)

Aggregations

BindException (org.springframework.validation.BindException)461 Test (org.junit.Test)401 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