Search in sources :

Example 71 with ConceptName

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());
}
Also used : ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 72 with ConceptName

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());
}
Also used : Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) HasFieldErrors.hasFieldErrors(org.openmrs.test.matchers.HasFieldErrors.hasFieldErrors) HasGlobalErrors.hasGlobalErrors(org.openmrs.test.matchers.HasGlobalErrors.hasGlobalErrors) ConceptName(org.openmrs.ConceptName) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 73 with ConceptName

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);
}
Also used : Locale(java.util.Locale) ConceptName(org.openmrs.ConceptName) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 74 with ConceptName

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());
}
Also used : ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 75 with ConceptName

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);
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) HasFieldErrors.hasFieldErrors(org.openmrs.test.matchers.HasFieldErrors.hasFieldErrors) HasGlobalErrors.hasGlobalErrors(org.openmrs.test.matchers.HasGlobalErrors.hasGlobalErrors) ConceptName(org.openmrs.ConceptName) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ConceptName (org.openmrs.ConceptName)100 Test (org.junit.Test)78 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)71 Concept (org.openmrs.Concept)62 ConceptDescription (org.openmrs.ConceptDescription)42 ConceptDatatype (org.openmrs.ConceptDatatype)34 ConceptClass (org.openmrs.ConceptClass)33 Locale (java.util.Locale)32 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)22 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 Obs (org.openmrs.Obs)9 BindException (org.springframework.validation.BindException)8 ConceptMap (org.openmrs.ConceptMap)7 Errors (org.springframework.validation.Errors)7 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Patient (org.openmrs.Patient)6 Encounter (org.openmrs.Encounter)5 OrderFrequency (org.openmrs.OrderFrequency)5