Search in sources :

Example 76 with BindException

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

the class CohortValidatorTest method validate_shouldPassIfMembershipStartDateIsAfterEndDate.

@Test
public void validate_shouldPassIfMembershipStartDateIsAfterEndDate() throws Exception {
    Cohort cohort = new Cohort(2);
    CohortMembership membership = new CohortMembership(patient.getPatientId());
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date startDate = dateFormat.parse("2016-11-01 00:00:00");
    Date endDate = dateFormat.parse("2015-01-01 00:00:00");
    membership.setStartDate(startDate);
    membership.setEndDate(endDate);
    Errors errors = new BindException(cohort, "cohort");
    new CohortValidator().validate(cohort, errors);
    Assert.assertFalse(errors.hasFieldErrors("memberships"));
}
Also used : Errors(org.springframework.validation.Errors) Cohort(org.openmrs.Cohort) BindException(org.springframework.validation.BindException) SimpleDateFormat(java.text.SimpleDateFormat) CohortMembership(org.openmrs.CohortMembership) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 77 with BindException

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

the class ConceptClassValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see ConceptClassValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    ConceptClass cc = new ConceptClass();
    cc.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");
    cc.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");
    cc.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(cc, "cc");
    new ConceptClassValidator().validate(cc, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    Assert.assertTrue(errors.hasFieldErrors("description"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 78 with BindException

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

the class ConceptClassValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.

/**
 * @see ConceptClassValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
    ConceptClass cc = new ConceptClass();
    cc.setName("name");
    cc.setDescription("some text");
    Errors errors = new BindException(cc, "cc");
    new ConceptClassValidator().validate(cc, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 79 with BindException

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

the class ConceptClassValidatorTest method validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace.

@Test
public void validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace() {
    ConceptClass cc = new ConceptClass();
    cc.setName("name");
    cc.setDescription(null);
    Errors errors = new BindException(cc, "cc");
    new ConceptClassValidator().validate(cc, errors);
    Assert.assertFalse(errors.hasFieldErrors("description"));
    cc.setDescription("");
    errors = new BindException(cc, "cc");
    new ConceptClassValidator().validate(cc, errors);
    Assert.assertFalse(errors.hasFieldErrors("description"));
    cc.setDescription(" ");
    errors = new BindException(cc, "cc");
    new ConceptClassValidator().validate(cc, errors);
    Assert.assertFalse(errors.hasFieldErrors("description"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 80 with BindException

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

the class ConceptClassValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see ConceptClassValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    ConceptClass cc = new ConceptClass();
    cc.setName("name");
    cc.setDescription("some text");
    cc.setRetireReason("some text");
    Errors errors = new BindException(cc, "cc");
    new ConceptClassValidator().validate(cc, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) BindException(org.springframework.validation.BindException) 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