Search in sources :

Example 31 with Errors

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

the class OrderValidatorTest method validate_shouldFailValidationIfDateActivatedAfterAutoExpireDate.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfDateActivatedAfterAutoExpireDate() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setOrderer(Context.getProviderService().getProvider(1));
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1);
    order.setDateActivated(new Date());
    order.setAutoExpireDate(cal.getTime());
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("dateActivated"));
    Assert.assertTrue(errors.hasFieldErrors("autoExpireDate"));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) Calendar(java.util.Calendar) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 32 with Errors

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

the class OrderValidatorTest method validate_shouldFailValidationIfScheduledDateIsSetAndUrgencyIsNotSetAsON_SCHEDULED_DATE.

/**
 * @see OrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfScheduledDateIsSetAndUrgencyIsNotSetAsON_SCHEDULED_DATE() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setScheduledDate(new Date());
    order.setUrgency(Order.Urgency.ROUTINE);
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("urgency"));
    order.setScheduledDate(new Date());
    order.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
    errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasFieldErrors("urgency"));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 33 with Errors

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

the class OrderValidatorTest method validate_shouldFailValidationIfEncounterIsNull.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfEncounterIsNull() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setEncounter(null);
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("encounter"));
}
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 34 with Errors

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

the class OrderValidatorTest method validate_shouldFailValidationIfUrgencyIsNull.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfUrgencyIsNull() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setUrgency(null);
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("urgency"));
}
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 35 with Errors

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

the class OrderValidatorTest method validate_shouldFailValidationIfActionIsNull.

/**
 * @see OrderValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfActionIsNull() {
    Order order = new Order();
    order.setConcept(Context.getConceptService().getConcept(88));
    order.setPatient(Context.getPatientService().getPatient(2));
    order.setAction(null);
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("action"));
}
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)

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