/** * @see LocaleUtility#getLocalesInOrder() */ @Test public void getLocalesInOrder_shouldAlwaysHaveEnglishIncludedInTheReturnedCollection() { Set<Locale> localesInOrder = LocaleUtility.getLocalesInOrder(); Assert.assertEquals(true, localesInOrder.contains(Locale.ENGLISH)); }
for (Locale currentLocale : LocaleUtility.getLocalesInOrder()) { ConceptName preferredName = getPreferredName(currentLocale); if (preferredName != null) {
/** * @see LocaleUtility#getLocalesInOrder() */ @Test public void getLocalesInOrder_shouldHaveDefaultLocaleAsTheFirstElementIfUserHasNoPreferredLocale() { // make sure the user doesn't have a locale Context.setLocale(null); Set<Locale> localesInOrder = LocaleUtility.getLocalesInOrder(); Assert.assertEquals(LocaleUtility.getDefaultLocale(), localesInOrder.iterator().next()); }
/** * @see LocaleUtility#getLocalesInOrder() */ @Test public void getLocalesInOrder_shouldAlwaysHaveDefaultLocaleDefaultValueIncludedInTheReturnedCollection() { Set<Locale> localesInOrder = LocaleUtility.getLocalesInOrder(); Assert.assertEquals(true, localesInOrder.contains(LocaleUtility .fromSpecification(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE_DEFAULT_VALUE))); }
/** * @see LocaleUtility#getLocalesInOrder() */ @Test public void getLocalesInOrder_shouldHaveDefaultLocaleAsTheSecondElementIfUserHasAPreferredLocale() { Locale lu_UG = new Locale("lu", "UG"); Context.setLocale(lu_UG); Set<Locale> localesInOrder = LocaleUtility.getLocalesInOrder(); Iterator<Locale> it = localesInOrder.iterator(); Assert.assertEquals(lu_UG, it.next()); Assert.assertEquals(LocaleUtility.getDefaultLocale(), it.next()); }
/** * @see LocaleUtility#getLocalesInOrder() */ @Test public void getLocalesInOrder_shouldReturnASetOfLocalesWithAPredictableOrder() { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "lu, sw_KE, en_US, en_GB", "Test Allowed list of locales"); Context.getAdministrationService().saveGlobalProperty(gp); Locale lu_UG = new Locale("lu", "UG"); Context.setLocale(lu_UG); Set<Locale> localesInOrder = LocaleUtility.getLocalesInOrder(); Iterator<Locale> it = localesInOrder.iterator(); Assert.assertEquals(new Locale("lu", "UG"), it.next()); Assert.assertEquals(LocaleUtility.getDefaultLocale(), it.next()); Assert.assertEquals(new Locale("lu"), it.next()); Assert.assertEquals(new Locale("sw", "KE"), it.next()); Assert.assertEquals(new Locale("en", "US"), it.next()); Assert.assertEquals(new Locale("en"), it.next()); }
/** * This test fetches all concepts in the xml test dataset and ensures that every locale for a * concept name is among those listed in the global property 'locale.allowed.list' and default * locale. NOTE that it doesn't test a particular API method directly. */ @Test public void saveConcept_shouldNotAcceptALocaleThatIsNeitherAmongTheLocaleAllowedListNorADefaultLocale() { List<Concept> concepts = Context.getConceptService().getAllConcepts(); Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder(); for (Concept concept : concepts) { if (!CollectionUtils.isEmpty(concept.getNames())) { for (ConceptName cn : concept.getNames()) { Assert.assertTrue("The locale '" + cn.getLocale() + "' of conceptName with id: " + cn.getConceptNameId() + " is not among those listed in the global property 'locale.allowed.list'", allowedLocales .contains(cn.getLocale())); } } } }
/** * This test is run against the xml test dataset for all concepts to ensure that in every locale * with one or more names, there isn't more than one name explicitly marked as locale preferred. * NOTE that it doesn't test a particular API method directly */ @Test public void saveConcept_shouldEnsureThatEveryConcepNameLocaleHasExactlyOnePreferredName() { List<Concept> concepts = Context.getConceptService().getAllConcepts(); Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder(); for (Concept concept : concepts) { for (Locale locale : allowedLocales) { Collection<ConceptName> namesInLocale = concept.getNames(locale); if (!CollectionUtils.isEmpty(namesInLocale)) { int preferredNamesFound = 0; for (ConceptName conceptName : namesInLocale) { if (conceptName.getLocalePreferred()) { preferredNamesFound++; Assert.assertTrue("Found multiple preferred names for conceptId: " + concept.getConceptId() + " in the locale '" + locale + "'", preferredNamesFound < 2); } } } } } }
/** * @see LocaleUtility#getLocalesInOrder() */ @Test public void getLocalesInOrder_shouldReturnASetOfLocalesWithNoDuplicates() { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "lu_UG, lu, sw_KE, en_US, en, en, en_GB, sw_KE", "Test Allowed list of locales"); Context.getAdministrationService().saveGlobalProperty(gp); GlobalProperty defaultLocale = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, "lu", "Test Allowed list of locales"); Context.getAdministrationService().saveGlobalProperty(defaultLocale); Locale lu_UG = new Locale("lu", "UG"); Context.setLocale(lu_UG); //note that unique list of locales should be lu_UG, lu, sw_KE, en_US, en Assert.assertEquals(6, LocaleUtility.getLocalesInOrder().size()); Context.getAdministrationService().saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, "")); }
/** * This test fetches all concepts in the xml test dataset and ensures that every locale that has * atleast one conceptName has a name marked as preferred. NOTE that it doesn't test a * particular API method directly. */ @Test public void saveConcept_shouldAlwaysReturnAPreferredNameForEveryLocaleThatHasAtleastOneUnvoidedName() { List<Concept> concepts = Context.getConceptService().getAllConcepts(); Set<Locale> allowedLocales = LocaleUtility.getLocalesInOrder(); for (Concept concept : concepts) { for (Locale locale : allowedLocales) { if (!CollectionUtils.isEmpty(concept.getNames(locale))) { Assert.assertNotNull("Concept with Id: " + concept.getConceptId() + " has no preferred name in locale:" + locale, concept.getPreferredName(locale)); Assert.assertEquals(true, concept.getPreferredName(locale).getLocalePreferred()); } } } }
List<Locale> locales = new ArrayList<Locale>(LocaleUtility.getLocalesInOrder());
List<Locale> locales = new ArrayList<Locale>(LocaleUtility.getLocalesInOrder()); List<ConceptClass> classes = null; ConceptClass responseConceptClass = conceptService.getConceptClassByUuid(conceptClass);