Search in sources :

Example 11 with FieldType

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

the class FieldTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see FieldTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    FieldType type = new FieldType();
    type.setName("too long text too long text too long text too long text");
    Errors 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 12 with FieldType

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

the class FieldValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    Field ff = new Field();
    FieldType ft = new FieldType();
    Boolean retired = Boolean.FALSE;
    ft.setId(0xdeadcafe);
    ff.setFieldType(ft);
    ff.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    ff.setRetired(retired);
    Boolean multiple = Boolean.FALSE;
    ff.setSelectMultiple(multiple);
    ff.setTableName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    ff.setAttributeName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    ff.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(ff, "field");
    new FieldValidator().validate(ff, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    Assert.assertTrue(errors.hasFieldErrors("tableName"));
    Assert.assertTrue(errors.hasFieldErrors("attributeName"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
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 13 with FieldType

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

the class FieldValidatorTest method validate_shouldPassValidationIfAllFieldsAreCorrect.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllFieldsAreCorrect() {
    Field ff = new Field();
    FieldType ft = new FieldType();
    Boolean retired = Boolean.FALSE;
    ft.setId(0xdeadcafe);
    ff.setFieldType(ft);
    ff.setName("valid");
    ff.setRetired(retired);
    Boolean multiple = Boolean.FALSE;
    ff.setSelectMultiple(multiple);
    Errors errors = new BindException(ff, "name");
    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 14 with FieldType

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

the class FormServiceTest method saveFieldType_shouldUpdateExistingFieldType.

/**
 * @see FormService#saveFieldType(FieldType)
 */
@Test
public void saveFieldType_shouldUpdateExistingFieldType() {
    FormService formService = Context.getFormService();
    FieldType fieldType = formService.getFieldType(1);
    Assert.assertNotNull(fieldType);
    fieldType.setName("SOME OTHER NEW NAME");
    formService.saveFieldType(fieldType);
    FieldType refetchedFieldType = formService.getFieldType(1);
    assertEquals("SOME OTHER NEW NAME", refetchedFieldType.getName());
}
Also used : FieldType(org.openmrs.FieldType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with FieldType

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

the class FormServiceTest method saveFieldType_shouldCreateNewFieldType.

/**
 * @see FormService#saveFieldType(FieldType)
 */
@Test
public void saveFieldType_shouldCreateNewFieldType() {
    FieldType fieldType = new FieldType();
    fieldType.setName("testing");
    fieldType.setDescription("desc");
    fieldType.setIsSet(true);
    FormService formService = Context.getFormService();
    formService.saveFieldType(fieldType);
    Assert.assertNotNull(formService.getFieldType(fieldType.getFieldTypeId()));
}
Also used : 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