Search in sources :

Example 36 with Errors

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

the class OrderValidatorTest method validate_shouldFailValidationIfDateActivatedIsBeforeEncountersEncounterDatetime.

/**
 * @see OrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfDateActivatedIsBeforeEncountersEncounterDatetime() {
    Date encounterDate = new Date();
    Date orderDate = DateUtils.addDays(encounterDate, -1);
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    encounter.setEncounterDatetime(encounterDate);
    Order order = new Order();
    order.setDateActivated(orderDate);
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setEncounter(encounter);
    order.setOrderer(Context.getProviderService().getProvider(1));
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("dateActivated"));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 37 with Errors

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

the class OrderValidatorTest method validate_shouldFailValidationIfOrdererIsNull.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfOrdererIsNull() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasFieldErrors("discontinued"));
    Assert.assertFalse(errors.hasFieldErrors("concept"));
    Assert.assertTrue(errors.hasFieldErrors("orderer"));
    Assert.assertFalse(errors.hasFieldErrors("patient"));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) 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 38 with Errors

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

the class OrderValidatorTest method validate_shouldNotAllowAFutureDateActivated.

/**
 * @see OrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldNotAllowAFutureDateActivated() {
    Patient patient = Context.getPatientService().getPatient(7);
    TestOrder order = new TestOrder();
    order.setPatient(patient);
    order.setOrderType(orderService.getOrderTypeByName("Test order"));
    order.setEncounter(Context.getEncounterService().getEncounter(3));
    order.setConcept(Context.getConceptService().getConcept(5497));
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setCareSetting(orderService.getCareSetting(1));
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, 1);
    order.setDateActivated(cal.getTime());
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("dateActivated"));
    Assert.assertEquals("Order.error.dateActivatedInFuture", errors.getFieldError("dateActivated").getCode());
}
Also used : Errors(org.springframework.validation.Errors) TestOrder(org.openmrs.TestOrder) Calendar(java.util.Calendar) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 39 with Errors

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

the class PatientIdentifierValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    PatientIdentifier pi = new PatientIdentifier("too long text too long text too long text too long text", new PatientIdentifierType(1), null);
    PatientIdentifierType idType = pi.getIdentifierType();
    idType.setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED);
    pi.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(pi, "pi");
    new PatientIdentifierValidator().validate(pi, errors);
    Assert.assertTrue(errors.hasFieldErrors("identifier"));
    Assert.assertTrue(errors.hasFieldErrors("voidReason"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 40 with Errors

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

the class PatientValidatorTest method validate_shouldFailValidationIfGenderIsBlank.

/**
 * @see org.openmrs.validator.PatientValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfGenderIsBlank() {
    Patient pa = new Patient(1);
    Errors errors = new BindException(pa, "patient");
    validator.validate(pa, errors);
    Assert.assertTrue(errors.hasFieldErrors("gender"));
}
Also used : Errors(org.springframework.validation.Errors) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) Test(org.junit.Test)

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