Search in sources :

Example 6 with FieldType

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

the class FieldValidatorTest method validate_shouldFailValidationIfNameIsEmpty.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfNameIsEmpty() {
    Field ff = new Field();
    ff.setName("");
    FieldType ft = new FieldType();
    Boolean retired = Boolean.FALSE;
    ft.setId(0xdeadcafe);
    ff.setFieldType(ft);
    ff.setRetired(retired);
    Boolean multiple = Boolean.FALSE;
    ff.setSelectMultiple(multiple);
    Errors errors = new BindException(ff, "name");
    new FieldValidator().validate(ff, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Field(org.openmrs.Field) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) FieldType(org.openmrs.FieldType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with FieldType

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

the class FieldValidatorTest method validate_shouldFailValidationIfNameIsNull.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfNameIsNull() {
    Field ff = new Field();
    ff.setName(null);
    FieldType ft = new FieldType();
    Boolean retired = Boolean.FALSE;
    ft.setId(0xdeadcafe);
    ff.setFieldType(ft);
    ff.setRetired(retired);
    Boolean multiple = Boolean.FALSE;
    ff.setSelectMultiple(multiple);
    Errors errors = new BindException(ff, "name");
    new FieldValidator().validate(ff, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Field(org.openmrs.Field) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) FieldType(org.openmrs.FieldType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with FieldType

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

the class FieldValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    Field ff = new Field();
    FieldType ft = new FieldType();
    Boolean retired = Boolean.FALSE;
    ft.setId(0xdeadcafe);
    ff.setFieldType(ft);
    ff.setName("name");
    ff.setRetired(retired);
    Boolean multiple = Boolean.FALSE;
    ff.setSelectMultiple(multiple);
    ff.setTableName("tableName");
    ff.setAttributeName("attributeName");
    ff.setRetireReason("retireReason");
    Errors errors = new BindException(ff, "field");
    new FieldValidator().validate(ff, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Field(org.openmrs.Field) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) FieldType(org.openmrs.FieldType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with FieldType

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

the class FieldValidatorTest method validate_shouldFailValidationIfRetiredIsNull.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfRetiredIsNull() {
    Field ff = new Field();
    ff.setName("good");
    FieldType ft = new FieldType();
    ft.setFieldTypeId(0xdeadcafe);
    ff.setFieldType(ft);
    ff.setName("valid");
    Boolean retired = null;
    ff.setRetired(retired);
    Boolean multiple = Boolean.TRUE;
    ff.setSelectMultiple(multiple);
    Errors errors = new BindException(ff, "retired");
    new FieldValidator().validate(ff, errors);
    Assert.assertTrue(errors.hasFieldErrors("retired"));
}
Also used : Field(org.openmrs.Field) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) FieldType(org.openmrs.FieldType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with FieldType

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

the class FieldTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see FieldTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    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)

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