Search in sources :

Example 1 with ConceptNameTag

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

Example 2 with ConceptNameTag

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"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptNameTag(org.openmrs.ConceptNameTag) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with ConceptNameTag

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

Example 4 with ConceptNameTag

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

Example 5 with ConceptNameTag

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

Aggregations

ConceptNameTag (org.openmrs.ConceptNameTag)20 Test (org.junit.Test)18 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)18 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 ConceptName (org.openmrs.ConceptName)4 ArrayList (java.util.ArrayList)1 Concept (org.openmrs.Concept)1 ConceptClass (org.openmrs.ConceptClass)1 ConceptDatatype (org.openmrs.ConceptDatatype)1 ConceptDescription (org.openmrs.ConceptDescription)1 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)1