use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldNotSetDefaultPreferredNameToShortOrIndexTerms.
/**
* @see ConceptServiceImpl#saveConcept(Concept)
*/
@Test
public void saveConcept_shouldNotSetDefaultPreferredNameToShortOrIndexTerms() {
Locale loc = new Locale("fr", "CA");
ConceptName shortName = new ConceptName("short name", loc);
// be explicit for test case
shortName.setConceptNameType(ConceptNameType.SHORT);
ConceptName indexTerm = new ConceptName("indexTerm", loc);
// synonyms are id'd by a null type
indexTerm.setConceptNameType(ConceptNameType.INDEX_TERM);
Concept c = new Concept();
HashSet<ConceptName> allNames = new HashSet<>(4);
allNames.add(indexTerm);
allNames.add(shortName);
c.setNames(allNames);
// ignore it so we can test the set default preferred name functionality
try {
Context.getConceptService().saveConcept(c);
} catch (org.openmrs.api.APIException e) {
// ignore it
}
assertNull("there's a preferred name", c.getPreferredName(loc));
assertFalse("name was explicitly marked preferred", shortName.isPreferred());
assertFalse("name was explicitly marked preferred", indexTerm.isPreferred());
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldForceSetFlagIfSetMembersExist.
/**
* @see ConceptServiceImpl#saveConcept(Concept)
*/
@Test
public void saveConcept_shouldForceSetFlagIfSetMembersExist() {
// Given
Concept concept = new Concept();
concept.addName(new ConceptName("Concept", new Locale("en", "US")));
concept.addDescription(new ConceptDescription("some description", null));
concept.setDatatype(new ConceptDatatype(1));
concept.setConceptClass(new ConceptClass(1));
Concept conceptSetMember = new Concept();
conceptSetMember.addName(new ConceptName("Set Member", new Locale("en", "US")));
conceptSetMember.addDescription(new ConceptDescription("some description", null));
conceptSetMember.setConceptClass(new ConceptClass(1));
conceptSetMember.setDatatype(new ConceptDatatype(1));
Context.getConceptService().saveConcept(conceptSetMember);
concept.addSetMember(conceptSetMember);
concept.setSet(false);
// When
Context.getConceptService().saveConcept(concept);
// Then
assertTrue(concept.getSet());
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ProgramWorkflowServiceTest method getSortedStates_shouldSortNamesContainingNumbersIntelligently.
/**
* THIS TEST SHOULD BE IN THE CLASS 'PROGRAMWORKFLOWTEST.JAVA' BUT IT REQUIRES ACCESS TO THE DAO
* LAYER
*
* @see ProgramWorkflow#getSortedStates()
*/
@Test
public void getSortedStates_shouldSortNamesContainingNumbersIntelligently() {
ProgramWorkflow program = new ProgramWorkflow();
ConceptName state1ConceptName = new ConceptName("Group 10", Context.getLocale());
Concept state1Concept = new Concept();
state1Concept.addName(state1ConceptName);
ProgramWorkflowState state1 = new ProgramWorkflowState();
state1.setConcept(state1Concept);
program.addState(state1);
ConceptName state2ConceptName = new ConceptName("Group 2", Context.getLocale());
Concept state2Concept = new Concept();
state2Concept.addName(state2ConceptName);
ProgramWorkflowState state2 = new ProgramWorkflowState();
state2.setConcept(state2Concept);
program.addState(state2);
Set<ProgramWorkflowState> sortedStates = program.getSortedStates();
int x = 1;
for (ProgramWorkflowState state : sortedStates) {
if (x == 1) {
Assert.assertEquals("Group 2", state.getConcept().getName(Context.getLocale()).getName());
} else if (x == 2) {
Assert.assertEquals("Group 10", state.getConcept().getName(Context.getLocale()).getName());
} else {
Assert.fail("Wha?!");
}
x++;
}
}
use of org.openmrs.ConceptName in project openmrs-core by openmrs.
the class ConceptNameSaveHandlerTest method handle_shouldNotFailIfTagsIsNull.
/**
* @see ConceptNameSaveHandler#handle(ConceptName,User,Date,String)
*/
@Test
public void handle_shouldNotFailIfTagsIsNull() {
ConceptNameSaveHandler handler = new ConceptNameSaveHandler();
ConceptName name = new ConceptName();
name.setTags(null);
handler.handle(name, null, null, null);
}
use of org.openmrs.ConceptName 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());
}
Aggregations