Search in sources :

Example 26 with ConceptReferenceTerm

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

the class ConceptReferenceTermValidatorTest method validate_shouldFailIfTheCodeIsNull.

/**
 * @see ConceptReferenceTermValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfTheCodeIsNull() {
    ConceptReferenceTerm term = new ConceptReferenceTerm();
    term.setName("name");
    term.setConceptSource(Context.getConceptService().getConceptSource(1));
    Errors errors = new BindException(term, "term");
    new ConceptReferenceTermValidator().validate(term, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("code"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 27 with ConceptReferenceTerm

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

the class ConceptReferenceTermValidatorTest method validate_shouldFailIfATermIsMappedToItself.

/**
 * @see ConceptReferenceTermValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfATermIsMappedToItself() {
    ConceptReferenceTerm term = Context.getConceptService().getConceptReferenceTerm(1);
    Set<ConceptReferenceTermMap> maps = term.getConceptReferenceTermMaps();
    ConceptReferenceTermMap invalidMap = maps.iterator().next();
    invalidMap.setTermB(term);
    term.setConceptReferenceTermMaps(maps);
    Errors errors = new BindException(term, "term");
    new ConceptReferenceTermValidator().validate(term, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("conceptReferenceTermMaps[0].termB"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptReferenceTermMap(org.openmrs.ConceptReferenceTermMap) BindException(org.springframework.validation.BindException) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 28 with ConceptReferenceTerm

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

the class ConceptReferenceTermValidatorTest method validate_shouldFailIfTheConceptReferenceTermCodeIsADuplicateInItsConceptSource.

/**
 * @see ConceptReferenceTermValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfTheConceptReferenceTermCodeIsADuplicateInItsConceptSource() {
    ConceptReferenceTerm term = new ConceptReferenceTerm();
    term.setName("name");
    term.setCode("WGT234");
    term.setConceptSource(Context.getConceptService().getConceptSource(1));
    Errors errors = new BindException(term, "term");
    new ConceptReferenceTermValidator().validate(term, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("code"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 29 with ConceptReferenceTerm

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

the class ConceptReferenceTermValidatorTest method validate_shouldFailIfTheNameIsAWhiteSpaceCharacter.

/**
 * @see ConceptReferenceTermValidator#validate(Object,Errors)
 */
@Test
@Ignore
public // we might need these back when the constraint is put back
void validate_shouldFailIfTheNameIsAWhiteSpaceCharacter() {
    ConceptReferenceTerm term = new ConceptReferenceTerm();
    term.setName(" ");
    term.setCode("code");
    term.setConceptSource(Context.getConceptService().getConceptSource(1));
    Errors errors = new BindException(term, "term");
    new ConceptReferenceTermValidator().validate(term, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 30 with ConceptReferenceTerm

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

the class ConceptReferenceTermValidatorTest method validate_shouldFailIfTheConceptReferenceTermObjectIsNull.

/**
 * @see ConceptReferenceTermValidator#validate(Object,Errors)
 */
@Test(expected = IllegalArgumentException.class)
public void validate_shouldFailIfTheConceptReferenceTermObjectIsNull() {
    Errors errors = new BindException(new ConceptReferenceTerm(), "term");
    new ConceptReferenceTermValidator().validate(null, errors);
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)37 Test (org.junit.Test)33 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)31 BindException (org.springframework.validation.BindException)19 Errors (org.springframework.validation.Errors)19 ConceptSource (org.openmrs.ConceptSource)7 ConceptReferenceTermMap (org.openmrs.ConceptReferenceTermMap)5 ArrayList (java.util.ArrayList)3 Ignore (org.junit.Ignore)3 Drug (org.openmrs.Drug)3 APIException (org.openmrs.api.APIException)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Criteria (org.hibernate.Criteria)2 ConceptMap (org.openmrs.ConceptMap)2 ConceptMapType (org.openmrs.ConceptMapType)2 ConceptName (org.openmrs.ConceptName)2 DrugReferenceMap (org.openmrs.DrugReferenceMap)2 OpenmrsObject (org.openmrs.OpenmrsObject)2 ConceptService (org.openmrs.api.ConceptService)2