use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
concept.addName(new ConceptName("CD4", Context.getLocale()));
concept.addDescription(new ConceptDescription("some description", null));
concept.setVersion("version");
concept.setRetireReason("retireReason");
concept.setConceptClass(new ConceptClass());
concept.setDatatype(new ConceptDatatype());
validator.validate(concept, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptValidatorTest method validate_shouldPassIfTheDuplicateNameInTheLocaleForTheConceptBeingValidatedIsVoided.
@Test
public void validate_shouldPassIfTheDuplicateNameInTheLocaleForTheConceptBeingValidatedIsVoided() {
ConceptName otherName = conceptService.getConceptName(1439);
// sanity check since names should only be unique amongst preferred and fully specified names
Assert.assertTrue(otherName.isFullySpecifiedName() || otherName.isPreferred());
Assert.assertFalse(otherName.getVoided());
Assert.assertFalse(otherName.getConcept().getRetired());
// change to a duplicate name in the same locale
ConceptName duplicateName = conceptService.getConceptName(2477);
duplicateName.setName(otherName.getName());
Concept concept = duplicateName.getConcept();
concept.setPreferredName(duplicateName);
// ensure that the name has been marked as preferred in its locale
Assert.assertEquals(duplicateName, concept.getPreferredName(duplicateName.getLocale()));
Assert.assertTrue(duplicateName.isPreferred());
duplicateName.setVoided(true);
Errors errors = new BindException(concept, "concept");
validator.validate(concept, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptValidatorTest method validate_shouldFailIfThereIsADuplicateUnretiredConceptNameInTheLocale.
@Test
public void validate_shouldFailIfThereIsADuplicateUnretiredConceptNameInTheLocale() {
Context.setLocale(new Locale("en", "GB"));
concept = cd4Count;
String duplicateName = concept.getFullySpecifiedName(Context.getLocale()).getName();
ConceptName newName = new ConceptName(duplicateName, Context.getLocale());
newName.setDateCreated(Calendar.getInstance().getTime());
newName.setCreator(Context.getAuthenticatedUser());
concept.addName(newName);
errors = new BindException(concept, "concept");
expectedException.expect(DuplicateConceptNameException.class);
expectedException.expectMessage("'" + duplicateName + "' is a duplicate name in locale '" + Context.getLocale() + "'");
validator.validate(concept, errors);
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptValidatorTest method validate_shouldPassIfTheConceptHasAtleastOneFullySpecifiedNameAddedToIt.
@Test
public void validate_shouldPassIfTheConceptHasAtleastOneFullySpecifiedNameAddedToIt() {
concept.addName(new ConceptName("one name", Context.getLocale()));
concept.addDescription(new ConceptDescription("some description", null));
concept.setConceptClass(new ConceptClass());
concept.setDatatype(new ConceptDatatype());
validator.validate(concept, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptValidatorTest method validate_shouldFailIfThereIsADuplicateUnretiredPreferredNameInTheSameLocale.
@Test
public void validate_shouldFailIfThereIsADuplicateUnretiredPreferredNameInTheSameLocale() {
Context.setLocale(new Locale("en", "GB"));
Concept concept = cd4Count;
ConceptName preferredName = new ConceptName("preferred name", Context.getLocale());
concept.setPreferredName(preferredName);
conceptService.saveConcept(concept);
Assert.assertEquals("preferred name", concept.getPreferredName(Context.getLocale()).getName());
Concept anotherConcept = weight;
anotherConcept.getFullySpecifiedName(Context.getLocale()).setName("preferred name");
Errors errors = new BindException(anotherConcept, "concept");
expectedException.expect(DuplicateConceptNameException.class);
expectedException.expectMessage("'" + preferredName + "' is a duplicate name in locale '" + Context.getLocale() + "'");
validator.validate(anotherConcept, errors);
}
Aggregations