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());
}
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"));
}
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"));
}
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"));
}
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));
}
Aggregations