Search in sources :

Example 6 with ConceptNameTag

use of org.openmrs.ConceptNameTag in project openmrs-core by openmrs.

the class ConceptServiceTest method purgeConceptNameTag_shouldDeleteTheSpecifiedConceptNameTagFromTheDatabase.

/**
 * @see ConceptService#purgeConceptNameTag(ConceptNameTag)
 */
@Test
public void purgeConceptNameTag_shouldDeleteTheSpecifiedConceptNameTagFromTheDatabase() {
    executeDataSet("org/openmrs/api/include/ConceptServiceTest-tags.xml");
    // sanity check
    ConceptNameTag nameTag = Context.getConceptService().getConceptNameTagByName("preferred_en");
    Assert.assertNotNull(nameTag);
    Context.getConceptService().purgeConceptNameTag(nameTag);
    Assert.assertNull(Context.getConceptService().getConceptNameTagByName("preferred_en"));
}
Also used : ConceptNameTag(org.openmrs.ConceptNameTag) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 7 with ConceptNameTag

use of org.openmrs.ConceptNameTag in project openmrs-core by openmrs.

the class ConceptServiceTest method saveConceptNameTag_shouldNotSaveAConceptNameTagIfTagExists.

@Test(expected = Exception.class)
public void saveConceptNameTag_shouldNotSaveAConceptNameTagIfTagExists() {
    String tag = "a new tag";
    ConceptNameTag nameTag = new ConceptNameTag();
    nameTag.setTag(tag);
    conceptService.saveConceptNameTag(nameTag);
    ConceptNameTag secondNameTag = new ConceptNameTag();
    secondNameTag.setTag(tag);
    ConceptNameTag existingConceptNameTag = conceptService.saveConceptNameTag(secondNameTag);
    assertNull(secondNameTag.getId());
    assertEquals(existingConceptNameTag.getId(), nameTag.getId());
}
Also used : ConceptNameTag(org.openmrs.ConceptNameTag) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 8 with ConceptNameTag

use of org.openmrs.ConceptNameTag in project openmrs-core by openmrs.

the class ConceptNameSaveHandlerTest method handle_shouldNotReplaceTagsThatHaveIds.

/**
 * @see ConceptNameSaveHandler#handle(ConceptName,User,Date,String)
 */
@Test
public void handle_shouldNotReplaceTagsThatHaveIds() {
    ConceptNameSaveHandler handler = new ConceptNameSaveHandler();
    ConceptName name = new ConceptName();
    ConceptNameTag tag = new ConceptNameTag("some randome tag name with an id", "");
    // this tag has an id
    tag.setConceptNameTagId(34);
    name.addTag(tag);
    handler.handle(name, null, null, null);
    ConceptNameTag newTag = name.getTags().iterator().next();
    Assert.assertEquals(34, newTag.getConceptNameTagId().intValue());
}
Also used : ConceptNameTag(org.openmrs.ConceptNameTag) ConceptName(org.openmrs.ConceptName) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with ConceptNameTag

use of org.openmrs.ConceptNameTag in project openmrs-core by openmrs.

the class ConceptNameSaveHandlerTest method handle_shouldReplaceTagsWithoutIdsWithDatabaseFetchedTag.

/**
 * @see ConceptNameSaveHandler#handle(ConceptName,User,Date,String)
 */
@Test
public void handle_shouldReplaceTagsWithoutIdsWithDatabaseFetchedTag() {
    ConceptNameSaveHandler handler = new ConceptNameSaveHandler();
    ConceptName name = new ConceptName();
    // this tag has a null id
    name.addTag("preferred");
    // this tag has a null id
    name.addTag("short");
    handler.handle(name, null, null, null);
    for (ConceptNameTag tag : name.getTags()) {
        if (tag.getTag().equals("preferred")) {
            Assert.assertEquals(4, tag.getConceptNameTagId().intValue());
        } else if (tag.getTag().equals("short")) {
            Assert.assertEquals(2, tag.getConceptNameTagId().intValue());
        }
    }
}
Also used : ConceptNameTag(org.openmrs.ConceptNameTag) ConceptName(org.openmrs.ConceptName) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with ConceptNameTag

use of org.openmrs.ConceptNameTag in project openmrs-core by openmrs.

the class ConceptNameSaveHandlerTest method handle_shouldNotReplaceTagsWithoutIdsThatAreNotInTheDatabase.

/**
 * @see ConceptNameSaveHandler#handle(ConceptName,User,Date,String)
 */
@Test
public void handle_shouldNotReplaceTagsWithoutIdsThatAreNotInTheDatabase() {
    ConceptNameSaveHandler handler = new ConceptNameSaveHandler();
    ConceptName name = new ConceptName();
    // this tag has a null id
    name.addTag(new ConceptNameTag("Some randome tag name", ""));
    handler.handle(name, null, null, null);
    ConceptNameTag newTag = name.getTags().iterator().next();
    Assert.assertNull(newTag.getConceptNameTagId());
}
Also used : ConceptNameTag(org.openmrs.ConceptNameTag) ConceptName(org.openmrs.ConceptName) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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