use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptDatatypeValidatorTest method validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace.
/**
* @see ConceptDatatypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace() {
ConceptDatatype cd = new ConceptDatatype();
cd.setName("name");
cd.setDescription(null);
Errors errors = new BindException(cd, "cd");
new ConceptDatatypeValidator().validate(cd, errors);
Assert.assertFalse(errors.hasFieldErrors("description"));
cd.setDescription("");
errors = new BindException(cd, "cd");
new ConceptDatatypeValidator().validate(cd, errors);
Assert.assertFalse(errors.hasFieldErrors("description"));
cd.setDescription(" ");
errors = new BindException(cd, "cd");
new ConceptDatatypeValidator().validate(cd, errors);
Assert.assertFalse(errors.hasFieldErrors("description"));
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldSetDefaultPreferredNameToFullySpecifiedFirst.
/**
* @see ConceptServiceImpl#saveConcept(Concept)
* Concept.getPreferredName(locale) returns null, saveConcept chooses one. The default
* first choice is the fully specified name in the locale. The default second choice
* is a synonym in the locale.
*/
@Test
public void saveConcept_shouldSetDefaultPreferredNameToFullySpecifiedFirst() {
Locale loc = new Locale("fr", "CA");
ConceptName fullySpecifiedName = new ConceptName("fully specified", loc);
// be explicit for test case
fullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
ConceptName shortName = new ConceptName("short name", loc);
// be explicit for test case
shortName.setConceptNameType(ConceptNameType.SHORT);
ConceptName synonym = new ConceptName("synonym", loc);
// synonyms are id'd by a null type
synonym.setConceptNameType(null);
ConceptName indexTerm = new ConceptName("indexTerm", loc);
// synonyms are id'd by a null type
indexTerm.setConceptNameType(ConceptNameType.INDEX_TERM);
Concept c = new Concept();
c.addName(fullySpecifiedName);
c.addName(synonym);
c.addName(indexTerm);
c.addName(shortName);
c.addDescription(new ConceptDescription("some description", null));
c.setDatatype(new ConceptDatatype(1));
c.setConceptClass(new ConceptClass(1));
assertFalse("check test assumption - the API didn't automatically set preferred vlag", c.getFullySpecifiedName(loc).isPreferred());
assertNotNull("Concept is legit, save succeeds", Context.getConceptService().saveConcept(c));
Context.getConceptService().saveConcept(c);
assertNotNull("there's a preferred name", c.getPreferredName(loc));
assertTrue("name was explicitly marked preferred", c.getPreferredName(loc).isPreferred());
assertEquals("name matches", c.getPreferredName(loc).getName(), fullySpecifiedName.getName());
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldTrimWhitespacesInConceptName.
@Test
public void saveConcept_shouldTrimWhitespacesInConceptName() {
// Given
Concept concept = new Concept();
String nameWithSpaces = " jwm ";
concept.addName(new ConceptName(nameWithSpaces, new Locale("en", "US")));
concept.addDescription(new ConceptDescription("some description", null));
concept.setDatatype(new ConceptDatatype(1));
concept.setConceptClass(new ConceptClass(1));
// When
Context.getConceptService().saveConcept(concept);
// Then
assertNotEquals(concept.getName().getName(), nameWithSpaces);
assertEquals(concept.getName().getName(), "jwm");
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptServiceImplTest method saveConcept_shouldReturnTheConceptWithNewConceptIDIfCreatingNewConcept.
/**
* @see ConceptServiceImpl#saveConcept(Concept)
*/
@Test
public void saveConcept_shouldReturnTheConceptWithNewConceptIDIfCreatingNewConcept() {
Concept c = new Concept();
ConceptName fullySpecifiedName = new ConceptName("requires one name min", new Locale("fr", "CA"));
c.addName(fullySpecifiedName);
c.addDescription(new ConceptDescription("some description", null));
c.setDatatype(new ConceptDatatype(1));
c.setConceptClass(new ConceptClass(1));
Concept savedC = Context.getConceptService().saveConcept(c);
assertNotNull(savedC);
assertTrue(savedC.getConceptId() > 0);
}
use of org.openmrs.ConceptDatatype in project openmrs-core by openmrs.
the class ConceptServiceTest method getConceptsByName_shouldReturnConceptsForAllCountriesAndGlobalLanguageGivenLanguageOnlyLocale.
/**
* @see ConceptService#getConceptsByName(String,Locale)
*/
@Test
public void getConceptsByName_shouldReturnConceptsForAllCountriesAndGlobalLanguageGivenLanguageOnlyLocale() {
// given
String name = "Concept";
Concept concept1 = new Concept();
concept1.addName(new ConceptName(name, new Locale("en", "US")));
concept1.addDescription(new ConceptDescription("some description", null));
concept1.setDatatype(new ConceptDatatype(1));
concept1.setConceptClass(new ConceptClass(1));
Context.getConceptService().saveConcept(concept1);
Concept concept2 = new Concept();
concept2.addName(new ConceptName(name, new Locale("en", "GB")));
concept2.addDescription(new ConceptDescription("some description", null));
concept2.setDatatype(new ConceptDatatype(1));
concept2.setConceptClass(new ConceptClass(1));
Context.getConceptService().saveConcept(concept2);
Concept concept3 = new Concept();
concept3.addName(new ConceptName(name, new Locale("en")));
concept3.addDescription(new ConceptDescription("some description", null));
concept3.setDatatype(new ConceptDatatype(1));
concept3.setConceptClass(new ConceptClass(1));
Context.getConceptService().saveConcept(concept3);
updateSearchIndex();
// when
List<Concept> concepts = Context.getConceptService().getConceptsByName(name, new Locale("en"), false);
// then
Assert.assertEquals(3, concepts.size());
Assert.assertTrue(concepts.containsAll(Arrays.asList(concept1, concept2, concept3)));
}
Aggregations