Search in sources :

Example 16 with FieldType

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

the class FieldTypeValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.

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

Example 17 with FieldType

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

the class FieldTypeValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.

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

Example 18 with FieldType

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

the class FieldTypeValidatorTest method validate_shouldFailIfFieldTypeNameIsDuplicate.

/**
 * @see org.openmrs.validator.FieldTypeValidator#validate(Object, Errors)
 */
@Test
public void validate_shouldFailIfFieldTypeNameIsDuplicate() {
    FieldType type = new FieldType();
    type.setName("some field type");
    Errors errors = new BindException(type, "type");
    new FieldTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) FieldType(org.openmrs.FieldType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

FieldType (org.openmrs.FieldType)18 Test (org.junit.Test)17 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)17 BindException (org.springframework.validation.BindException)13 Errors (org.springframework.validation.Errors)13 Field (org.openmrs.Field)9 Concept (org.openmrs.Concept)1 FormField (org.openmrs.FormField)1