use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ObsValidatorTest method validate_shouldRejectAnInvalidConceptAndDrugCombination.
/**
* @see ObsValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldRejectAnInvalidConceptAndDrugCombination() {
Obs obs = new Obs();
obs.setPerson(new Person(7));
obs.setObsDatetime(new Date());
Concept questionConcept = new Concept(100);
ConceptDatatype dt = new ConceptDatatype(1);
dt.setUuid(ConceptDatatype.CODED_UUID);
questionConcept.setDatatype(dt);
obs.setConcept(questionConcept);
obs.setValueCoded(new Concept(101));
Drug drug = new Drug();
drug.setConcept(new Concept(102));
obs.setValueDrug(drug);
Errors errors = new BindException(obs, "obs");
obsValidator.validate(obs, errors);
assertTrue(errors.hasFieldErrors("valueDrug"));
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptDatatypeValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.
/**
* @see ConceptDatatypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() {
ConceptDatatype cd = new ConceptDatatype();
cd.setName(null);
cd.setDescription("some text");
Errors errors = new BindException(cd, "cd");
new ConceptDatatypeValidator().validate(cd, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
cd.setName("");
errors = new BindException(cd, "cd");
new ConceptDatatypeValidator().validate(cd, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
cd.setName(" ");
errors = new BindException(cd, "cd");
new ConceptDatatypeValidator().validate(cd, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptDatatypeValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.
/**
* @see ConceptDatatypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
ConceptDatatype cd = new ConceptDatatype();
cd.setName("name");
cd.setDescription("some text");
Errors errors = new BindException(cd, "cd");
new ConceptDatatypeValidator().validate(cd, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptDatatypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see ConceptDatatypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
ConceptDatatype cd = new ConceptDatatype();
cd.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");
cd.setDescription("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");
cd.setHl7Abbreviation("hl7Abbreviation");
cd.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(cd, "cd");
new ConceptDatatypeValidator().validate(cd, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("description"));
Assert.assertTrue(errors.hasFieldErrors("hl7Abbreviation"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptServiceTest method getConceptDatatypeByUuid_shouldFindObjectGivenValidUuid.
/**
* @see ConceptService#getConceptDatatypeByUuid(String)
*/
@Test
public void getConceptDatatypeByUuid_shouldFindObjectGivenValidUuid() {
String uuid = "8d4a4488-c2cc-11de-8d13-0010c6dffd0f";
ConceptDatatype conceptDatatype = Context.getConceptService().getConceptDatatypeByUuid(uuid);
Assert.assertEquals(1, (int) conceptDatatype.getConceptDatatypeId());
}
Aggregations