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"));
}
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"));
}
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());
}
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());
}
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()));
}
Aggregations