Search in sources :

Example 76 with Errors

use of org.springframework.validation.Errors 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 77 with Errors

use of org.springframework.validation.Errors 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 78 with Errors

use of org.springframework.validation.Errors 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)

Example 79 with Errors

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

the class DrugOrderValidatorTest method validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType.

/**
 * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType() {
    DrugOrder order = new DrugOrder();
    order.setDosingType(SimpleDosingInstructions.class);
    order.setDose(null);
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("dose"));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 80 with Errors

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

the class EncounterRoleValidatorTest method validate_shouldFailIfTheNameOfTheEncounterRoleIsNullEmptyOrWhitespace.

/**
 * @see org.openmrs.validator.EncounterRoleValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailIfTheNameOfTheEncounterRoleIsNullEmptyOrWhitespace() {
    EncounterRole encounterRoleNo1 = new EncounterRole();
    encounterRoleNo1.setName(null);
    Errors errorsNo1 = new BindException(encounterRoleNo1, "encounterRole");
    new EncounterRoleValidator().validate(encounterRoleNo1, errorsNo1);
    Assert.assertTrue(errorsNo1.hasFieldErrors("name"));
    EncounterRole encounterRoleNo2 = new EncounterRole();
    encounterRoleNo2.setName("");
    Errors errorsNo2 = new BindException(encounterRoleNo2, "encounterRole");
    new EncounterRoleValidator().validate(encounterRoleNo2, errorsNo2);
    Assert.assertTrue(errorsNo2.hasFieldErrors("name"));
    EncounterRole encounterRoleNo3 = new EncounterRole();
    encounterRoleNo3.setName("  ");
    Errors errorsNo3 = new BindException(encounterRoleNo3, "encounterRole");
    new EncounterRoleValidator().validate(encounterRoleNo3, errorsNo3);
    Assert.assertTrue(errorsNo3.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) EncounterRole(org.openmrs.EncounterRole) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Errors (org.springframework.validation.Errors)468 BindException (org.springframework.validation.BindException)387 Test (org.junit.Test)376 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)356 OrderUtilTest (org.openmrs.order.OrderUtilTest)58 DrugOrder (org.openmrs.DrugOrder)56 Date (java.util.Date)53 Test (org.junit.jupiter.api.Test)36 Patient (org.openmrs.Patient)36 TestBean (org.springframework.beans.testfixture.beans.TestBean)33 Calendar (java.util.Calendar)28 Concept (org.openmrs.Concept)25 TestOrder (org.openmrs.TestOrder)23 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)23 OrderType (org.openmrs.OrderType)22 Encounter (org.openmrs.Encounter)21 Obs (org.openmrs.Obs)20 Order (org.openmrs.Order)20 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)19 PageContext (jakarta.servlet.jsp.PageContext)17