use of org.openmrs.ConceptNameTag in project openmrs-core by openmrs.
the class ConceptNameTagValidatorTest method validate_shouldFailValidationIfConceptNameTagIsNull.
@Test(expected = IllegalArgumentException.class)
public void validate_shouldFailValidationIfConceptNameTagIsNull() {
Errors errors = new BindException(new ConceptNameTag(), "cnt");
new ConceptNameTagValidator().validate(null, errors);
}
use of org.openmrs.ConceptNameTag in project openmrs-core by openmrs.
the class ConceptNameTagValidatorTest method validate_shouldFailValidationIfTagIsNullOrEmptyOrWhitespace.
/**
* @see ConceptNameTagValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfTagIsNullOrEmptyOrWhitespace() {
ConceptNameTag cnt = new ConceptNameTag();
Errors errors = new BindException(cnt, "cnt");
new ConceptNameTagValidator().validate(cnt, errors);
Assert.assertTrue(errors.hasFieldErrors("tag"));
cnt.setTag("");
errors = new BindException(cnt, "cnt");
new ConceptNameTagValidator().validate(cnt, errors);
Assert.assertTrue(errors.hasFieldErrors("tag"));
cnt.setTag(" ");
errors = new BindException(cnt, "cnt");
new ConceptNameTagValidator().validate(cnt, errors);
Assert.assertTrue(errors.hasFieldErrors("tag"));
}
use of org.openmrs.ConceptNameTag in project openmrs-core by openmrs.
the class ConceptServiceTest method saveConceptNameTag_shouldNotSaveATagIfItIsInvalid.
/**
* @see ConceptService#saveConceptNameTag(Object,Errors)
*/
@Test(expected = Exception.class)
public void saveConceptNameTag_shouldNotSaveATagIfItIsInvalid() {
ConceptNameTag cnt = new ConceptNameTag();
ConceptService cs = Context.getConceptService();
cs.saveConceptNameTag(cnt);
}
use of org.openmrs.ConceptNameTag in project openmrs-core by openmrs.
the class ConceptServiceTest method saveConcept_shouldReuseConceptNameTagsThatAlreadyExistInTheDatabase.
/**
* @see ConceptService#saveConcept(Concept)
*/
@Test
public void saveConcept_shouldReuseConceptNameTagsThatAlreadyExistInTheDatabase() {
executeDataSet("org/openmrs/api/include/ConceptServiceTest-tags.xml");
ConceptService cs = Context.getConceptService();
// make sure the name tag exists already
ConceptNameTag cnt = cs.getConceptNameTagByName("preferred_en");
Assert.assertNotNull(cnt);
ConceptName cn = new ConceptName("Some name", Locale.ENGLISH);
cn.addTag(new ConceptNameTag("preferred_en", "preferred name in a language"));
Concept concept = new Concept();
concept.addName(cn);
concept.addDescription(new ConceptDescription("some description", null));
concept.setDatatype(new ConceptDatatype(1));
concept.setConceptClass(new ConceptClass(1));
cs.saveConcept(concept);
Collection<ConceptNameTag> savedConceptNameTags = concept.getName(Locale.ENGLISH, false).getTags();
ConceptNameTag savedConceptNameTag = (ConceptNameTag) savedConceptNameTags.toArray()[0];
Assert.assertEquals(cnt.getConceptNameTagId(), savedConceptNameTag.getConceptNameTagId());
}
use of org.openmrs.ConceptNameTag in project openmrs-core by openmrs.
the class ConceptServiceTest method saveConceptNameTag_shouldSaveAConceptNameTagIfATagDoesNotExist.
@Test
public void saveConceptNameTag_shouldSaveAConceptNameTagIfATagDoesNotExist() {
ConceptNameTag nameTag = new ConceptNameTag();
nameTag.setTag("a new tag");
ConceptNameTag savedNameTag = conceptService.saveConceptNameTag(nameTag);
assertNotNull(nameTag.getId());
assertEquals(savedNameTag.getId(), nameTag.getId());
}
Aggregations