Search in sources :

Example 96 with Errors

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

the class VisitValidatorTest method validate_shouldAcceptAVisitIfStartDateTimeIsEqualToStartDateTimeOfAnotherVoidedVisitOfTheSamePatient.

/**
 * @see VisitValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldAcceptAVisitIfStartDateTimeIsEqualToStartDateTimeOfAnotherVoidedVisitOfTheSamePatient() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(DATE_TIME_2014_02_05_00_00_00_0);
    Visit visit = makeVisit(42);
    visit.setStartDatetime(calendar.getTime());
    assertTrue(patientHasVoidedVisit(visit.getPatient(), DATE_TIME_2014_02_05_00_00_00_0, DATE_TIME_2014_02_11_00_00_00_0));
    Errors errors = new BindException(visit, "visit");
    new VisitValidator().validate(visit, errors);
    assertFalse(errors.hasFieldErrors("startDatetime"));
}
Also used : Errors(org.springframework.validation.Errors) Visit(org.openmrs.Visit) Calendar(java.util.Calendar) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 97 with Errors

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

the class VisitValidatorTest method validate_shouldFailIfStartDatetimeIsNotSet.

/**
 * @see VisitValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfStartDatetimeIsNotSet() {
    VisitService vs = Context.getVisitService();
    Visit visit = new Visit();
    visit.setVisitType(vs.getVisitType(1));
    visit.setPatient(Context.getPatientService().getPatient(2));
    Errors errors = new BindException(visit, "visit");
    new VisitValidator().validate(visit, errors);
    assertTrue(errors.hasFieldErrors("startDatetime"));
}
Also used : Errors(org.springframework.validation.Errors) VisitService(org.openmrs.api.VisitService) Visit(org.openmrs.Visit) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 98 with Errors

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

the class VisitValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see VisitValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    Visit visit = makeVisit(42);
    visit.setVoidReason("voidReason");
    Errors errors = new BindException(visit, "visit");
    new VisitValidator().validate(visit, errors);
    assertEquals(false, errors.hasFieldErrors("voidReason"));
}
Also used : Errors(org.springframework.validation.Errors) Visit(org.openmrs.Visit) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 99 with Errors

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

the class VisitValidatorTest method validate_shouldFailIfAnAttributeIsBad.

/**
 * @see VisitValidator#validate(Object,Errors)
 */
@Test
// Once we figure it out, this test can be un-Ignored
@Ignore
public void validate_shouldFailIfAnAttributeIsBad() {
    Visit visit = visitService.getVisit(1);
    visit.addAttribute(makeAttribute(new Date()));
    visit.addAttribute(makeAttribute("not a date"));
    visit.getActiveAttributes();
    Errors errors = new BindException(visit, "visit");
    new VisitValidator().validate(visit, errors);
    assertEquals(true, errors.hasFieldErrors("attributes"));
}
Also used : Errors(org.springframework.validation.Errors) Visit(org.openmrs.Visit) BindException(org.springframework.validation.BindException) Date(java.util.Date) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 100 with Errors

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

the class OrderTypeValidatorTest method validate_shouldPassIfAllFieldsAreCorrectForANewOrderType.

/**
 * @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassIfAllFieldsAreCorrectForANewOrderType() {
    OrderType orderType = new OrderType();
    orderType.setName("unique name");
    orderType.setJavaClassName("org.openmrs.TestDrugOrder");
    Collection<ConceptClass> col = new HashSet<>();
    col.add(Context.getConceptService().getConceptClass(2));
    orderType.setConceptClasses(col);
    Errors errors = new BindException(orderType, "orderType");
    new OrderTypeValidator().validate(orderType, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) ConceptClass(org.openmrs.ConceptClass) OrderType(org.openmrs.OrderType) BindException(org.springframework.validation.BindException) HashSet(java.util.HashSet) 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