use of org.openmrs.DrugReferenceMap in project openmrs-core by openmrs.
the class DrugValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see DrugValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
Drug drug = new Drug();
drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1)));
drug.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");
drug.setStrength("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");
drug.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(drug, "drug");
new DrugValidator().validate(drug, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("strength"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.openmrs.DrugReferenceMap in project openmrs-core by openmrs.
the class DrugValidatorTest method validate_shouldRejectDrugMultipleMappingsToTheSameTerm.
/**
* @see DrugValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldRejectDrugMultipleMappingsToTheSameTerm() {
Drug drug = new Drug();
DrugReferenceMap term1 = new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1));
DrugReferenceMap term2 = new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(2));
drug.addDrugReferenceMap(term1);
drug.addDrugReferenceMap(term2);
Assert.assertEquals(2, drug.getDrugReferenceMaps().size());
Errors errors = new BindException(drug, "drug");
new DrugValidator().validate(drug, errors);
Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[1].conceptReferenceTerm"));
}
use of org.openmrs.DrugReferenceMap in project openmrs-core by openmrs.
the class DrugValidatorTest method validate_shouldInvokeConceptMapTypeValidatorIfConceptMapTypeOnDrugReferenceMapIsNew.
/**
* @see DrugValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldInvokeConceptMapTypeValidatorIfConceptMapTypeOnDrugReferenceMapIsNew() {
Drug drug = new Drug();
drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), new ConceptMapType()));
Errors errors = new BindException(drug, "drug");
new DrugValidator().validate(drug, errors);
// concept map type validator should have been called which should reject a null name
Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[0].conceptMapType.name"));
}
use of org.openmrs.DrugReferenceMap in project openmrs-core by openmrs.
the class DrugValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see DrugValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
Drug drug = new Drug();
drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1)));
drug.setName("name");
drug.setStrength("strength");
drug.setRetireReason("retireReason");
Errors errors = new BindException(drug, "drug");
new DrugValidator().validate(drug, errors);
Assert.assertFalse(errors.hasFieldErrors());
}
Aggregations