Search in sources :

Example 6 with DrugReferenceMap

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"));
}
Also used : Drug(org.openmrs.Drug) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) DrugReferenceMap(org.openmrs.DrugReferenceMap) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with DrugReferenceMap

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"));
}
Also used : Drug(org.openmrs.Drug) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) DrugReferenceMap(org.openmrs.DrugReferenceMap) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with DrugReferenceMap

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"));
}
Also used : Drug(org.openmrs.Drug) Errors(org.springframework.validation.Errors) ConceptMapType(org.openmrs.ConceptMapType) BindException(org.springframework.validation.BindException) DrugReferenceMap(org.openmrs.DrugReferenceMap) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with DrugReferenceMap

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());
}
Also used : Drug(org.openmrs.Drug) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) DrugReferenceMap(org.openmrs.DrugReferenceMap) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Drug (org.openmrs.Drug)9 DrugReferenceMap (org.openmrs.DrugReferenceMap)9 Test (org.junit.Test)8 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)8 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 ConceptMapType (org.openmrs.ConceptMapType)2 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)2 HashSet (java.util.HashSet)1