Search in sources :

Example 91 with Errors

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

the class LocationAttributeTypeValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.

/**
 * @see LocationAttributeTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() {
    LocationAttributeType type = new LocationAttributeType();
    type.setName(null);
    type.setDescription("description");
    Errors errors = new BindException(type, "type");
    new LocationAttributeTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    type.setName("");
    errors = new BindException(type, "type");
    new LocationAttributeTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    type.setName(" ");
    errors = new BindException(type, "type");
    new LocationAttributeTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) LocationAttributeType(org.openmrs.LocationAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 92 with Errors

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

the class LocationAttributeTypeValidatorTest method validate_shouldPassEditingLocationAttributeTypeName.

/**
 * @see LocationAttributeTypeValidator#validate(Object, Errors)
 */
@Test
public void validate_shouldPassEditingLocationAttributeTypeName() {
    LocationAttributeType et = Context.getLocationService().getLocationAttributeTypeByName("Audit Date");
    Assert.assertNotNull(et);
    Errors errors = new BindException(et, "locationAttributeType");
    new LocationAttributeTypeValidator().validate(et, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) LocationAttributeType(org.openmrs.LocationAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 93 with Errors

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

the class LocationAttributeTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see LocationAttributeTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    LocationAttributeType type = new LocationAttributeType();
    type.setName("name");
    type.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype");
    type.setDescription("description");
    type.setRetireReason("retireReason");
    Errors errors = new BindException(type, "type");
    new LocationAttributeTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) LocationAttributeType(org.openmrs.LocationAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 94 with Errors

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

the class VisitValidatorTest method validate_shouldFailIfPatientIsNotSet.

/**
 * @see VisitValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfPatientIsNotSet() {
    VisitService vs = Context.getVisitService();
    Visit visit = new Visit();
    visit.setVisitType(vs.getVisitType(1));
    visit.setStartDatetime(new Date());
    Errors errors = new BindException(visit, "visit");
    new VisitValidator().validate(visit, errors);
    assertTrue(errors.hasFieldErrors("patient"));
}
Also used : Errors(org.springframework.validation.Errors) VisitService(org.openmrs.api.VisitService) Visit(org.openmrs.Visit) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 95 with Errors

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

the class VisitValidatorTest method validate_shouldAcceptAVisitIfStopDateTimeFallsIntoAnotherVoidedVisitOfTheSamePatient.

/**
 * @see VisitValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldAcceptAVisitIfStopDateTimeFallsIntoAnotherVoidedVisitOfTheSamePatient() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(2014, Calendar.FEBRUARY, 2);
    Visit visit = makeVisit(42);
    visit.setStartDatetime(calendar.getTime());
    calendar.set(2014, Calendar.FEBRUARY, 8);
    visit.setStopDatetime(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("stopDatetime"));
}
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)

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