Search in sources :

Example 11 with ConceptReferenceTerm

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

the class ConceptReferenceTermValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see ConceptReferenceTermValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    ConceptReferenceTerm term = new ConceptReferenceTerm();
    term.setName("name");
    term.setCode("code");
    term.setConceptSource(Context.getConceptService().getConceptSource(1));
    term.setVersion("version");
    term.setDescription("Description");
    term.setRetireReason("RetireReason");
    Errors errors = new BindException(term, "term");
    new ConceptReferenceTermValidator().validate(term, errors);
    Assert.assertEquals(false, errors.hasErrors());
}
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 12 with ConceptReferenceTerm

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

the class ConceptReferenceTermValidatorTest method validate_shouldFailIfTheNameIsAnEmptyString.

/**
 * @see ConceptReferenceTermValidator#validate(Object,Errors)
 */
@Test
@Ignore
public void validate_shouldFailIfTheNameIsAnEmptyString() {
    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 13 with ConceptReferenceTerm

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

the class ConceptReferenceTermValidatorTest method validate_shouldFailIfATermIsMappedMultipleTimesToTheSameTerm.

/**
 * @see ConceptReferenceTermValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfATermIsMappedMultipleTimesToTheSameTerm() {
    ConceptReferenceTerm term = new ConceptReferenceTerm();
    ConceptService cs = Context.getConceptService();
    term.setCode("unique code");
    term.setConceptSource(Context.getConceptService().getConceptSource(1));
    ConceptReferenceTermMap map1 = new ConceptReferenceTermMap(cs.getConceptReferenceTerm(1), cs.getConceptMapType(1));
    term.addConceptReferenceTermMap(map1);
    // test should fail if we change the term below
    ConceptReferenceTermMap map2 = new ConceptReferenceTermMap(cs.getConceptReferenceTerm(1), cs.getConceptMapType(1));
    term.addConceptReferenceTermMap(map2);
    Errors errors = new BindException(term, "term");
    new ConceptReferenceTermValidator().validate(term, errors);
    System.err.println(errors.getAllErrors());
    // the term for second mapping should be rejected
    Assert.assertEquals(true, errors.hasFieldErrors("conceptReferenceTermMaps[1].termB"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptReferenceTermMap(org.openmrs.ConceptReferenceTermMap) BindException(org.springframework.validation.BindException) ConceptService(org.openmrs.api.ConceptService) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with ConceptReferenceTerm

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

the class ConceptReferenceTermValidatorTest method validate_shouldFailIfTheNameIsNull.

/**
 * @see ConceptReferenceTermValidator#validate(Object,Errors)
 */
@Test
@Ignore
public void validate_shouldFailIfTheNameIsNull() {
    ConceptReferenceTerm term = new ConceptReferenceTerm();
    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 15 with ConceptReferenceTerm

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

the class ConceptServiceTest method saveConceptReferenceTerm_shouldAddAConceptReferenceTermToTheDatabaseAndAssignAnIdToIt.

/**
 * @see ConceptService#saveConceptReferenceTerm(ConceptReferenceTerm)
 */
@Test
public void saveConceptReferenceTerm_shouldAddAConceptReferenceTermToTheDatabaseAndAssignAnIdToIt() {
    ConceptReferenceTerm term = new ConceptReferenceTerm();
    term.setName("test term");
    term.setCode("test code");
    ConceptSource source = Context.getConceptService().getConceptSource(1);
    term.setConceptSource(source);
    ConceptReferenceTerm savedTerm = Context.getConceptService().saveConceptReferenceTerm(term);
    Assert.assertNotNull(savedTerm.getId());
    Assert.assertNotNull(Context.getConceptService().getConceptReferenceTermByName("test term", source));
}
Also used : ConceptSource(org.openmrs.ConceptSource) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

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