Search in sources :

Example 56 with EncounterType

use of org.openmrs.EncounterType in project openmrs-core by openmrs.

the class EncounterTypeValidatorTest method validate_shouldFailIfEncounterTypeNameIsDuplicate.

/**
 * @see EncounterTypeValidator#validate(Object, Errors)
 */
@Test
public void validate_shouldFailIfEncounterTypeNameIsDuplicate() {
    Assert.assertNotNull(Context.getEncounterService().getEncounterType("Scheduled"));
    EncounterType newEncounterType = new EncounterType();
    newEncounterType.setName("Scheduled");
    Errors errors = new BindException(newEncounterType, "encounterType");
    new EncounterTypeValidator().validate(newEncounterType, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) EncounterType(org.openmrs.EncounterType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 57 with EncounterType

use of org.openmrs.EncounterType in project openmrs-core by openmrs.

the class EncounterTypeValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.

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

Example 58 with EncounterType

use of org.openmrs.EncounterType in project openmrs-core by openmrs.

the class EncounterTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see EncounterTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    EncounterType type = new EncounterType();
    type.setName(StringUtils.repeat("longer than 50 chars", 6));
    type.setDescription(StringUtils.repeat("longer than 1024 chars", 120));
    type.setRetireReason(StringUtils.repeat("longer than 255 chars", 27));
    Errors errors = new BindException(type, "type");
    new EncounterTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    Assert.assertTrue(errors.hasFieldErrors("description"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) EncounterType(org.openmrs.EncounterType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 59 with EncounterType

use of org.openmrs.EncounterType in project openmrs-core by openmrs.

the class EncounterTypeValidatorTest method validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace.

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

Example 60 with EncounterType

use of org.openmrs.EncounterType in project openmrs-core by openmrs.

the class EncounterTypeValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.

/**
 * @see EncounterTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
    EncounterType type = new EncounterType();
    type.setName("CLOSE");
    type.setDescription("Aaaaah");
    Errors errors = new BindException(type, "type");
    new EncounterTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) EncounterType(org.openmrs.EncounterType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

EncounterType (org.openmrs.EncounterType)60 Test (org.junit.Test)44 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)42 Encounter (org.openmrs.Encounter)19 Date (java.util.Date)17 Location (org.openmrs.Location)12 Patient (org.openmrs.Patient)10 User (org.openmrs.User)10 EncounterRole (org.openmrs.EncounterRole)9 Provider (org.openmrs.Provider)8 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 ArrayList (java.util.ArrayList)5 GlobalProperty (org.openmrs.GlobalProperty)5 List (java.util.List)4 Privilege (org.openmrs.Privilege)4 Concept (org.openmrs.Concept)3 Visit (org.openmrs.Visit)3 HashMap (java.util.HashMap)2 SQLQuery (org.hibernate.SQLQuery)2