use of org.openmrs.messagesource.MutableMessageSource in project openmrs-core by openmrs.
the class AdministrationServiceTest method getPresentationLocales_shouldReturnAllCountryLocalesIfLanguageLocaleAndNoCountryLocalesAreSpecifiedInAllowedList.
/**
* @see AdministrationService#getPresentationLocales()
*/
@Test
public void getPresentationLocales_shouldReturnAllCountryLocalesIfLanguageLocaleAndNoCountryLocalesAreSpecifiedInAllowedList() {
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, es"));
List<Locale> locales = new ArrayList<>();
locales.add(new Locale("pl", "PL"));
locales.add(new Locale("en"));
locales.add(new Locale("es"));
locales.add(new Locale("es", "CL"));
locales.add(new Locale("es", "SN"));
MutableResourceBundleMessageSource mutableResourceBundleMessageSource = Mockito.mock(MutableResourceBundleMessageSource.class);
Mockito.when(mutableResourceBundleMessageSource.getLocales()).thenReturn(locales);
MutableMessageSource mutableMessageSource = Context.getMessageSourceService().getActiveMessageSource();
Context.getMessageSourceService().setActiveMessageSource(mutableResourceBundleMessageSource);
Set<Locale> presentationLocales = Context.getAdministrationService().getPresentationLocales();
Context.getMessageSourceService().setActiveMessageSource(mutableMessageSource);
Assert.assertEquals(3, presentationLocales.size());
Assert.assertTrue("es_CL", presentationLocales.contains(new Locale("es", "CL")));
Assert.assertTrue("es_SN", presentationLocales.contains(new Locale("es", "SN")));
Assert.assertTrue("en", presentationLocales.contains(new Locale("en")));
}
use of org.openmrs.messagesource.MutableMessageSource in project openmrs-core by openmrs.
the class AdministrationServiceTest method getPresentationLocales_shouldReturnOnlyCountryLocaleIfBothCountryLocaleAndLanguageLocaleAreSpecifiedInAllowedList.
/**
* @see AdministrationService#getPresentationLocales()
*/
@Test
public void getPresentationLocales_shouldReturnOnlyCountryLocaleIfBothCountryLocaleAndLanguageLocaleAreSpecifiedInAllowedList() {
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, es, es_CL"));
List<Locale> locales = new ArrayList<>();
locales.add(new Locale("pl", "PL"));
locales.add(new Locale("en"));
locales.add(new Locale("es"));
locales.add(new Locale("es", "CL"));
MutableResourceBundleMessageSource mutableResourceBundleMessageSource = Mockito.mock(MutableResourceBundleMessageSource.class);
Mockito.when(mutableResourceBundleMessageSource.getLocales()).thenReturn(locales);
MutableMessageSource mutableMessageSource = Context.getMessageSourceService().getActiveMessageSource();
Context.getMessageSourceService().setActiveMessageSource(mutableResourceBundleMessageSource);
Set<Locale> presentationLocales = Context.getAdministrationService().getPresentationLocales();
Context.getMessageSourceService().setActiveMessageSource(mutableMessageSource);
Assert.assertEquals(2, presentationLocales.size());
Assert.assertTrue("en", presentationLocales.contains(new Locale("en")));
Assert.assertTrue("es_CL", presentationLocales.contains(new Locale("es", "CL")));
}
use of org.openmrs.messagesource.MutableMessageSource in project openmrs-core by openmrs.
the class AdministrationServiceTest method getPresentationLocales_shouldReturnLanguageLocaleIfItIsSpecifiedInAllowedListAndThereAreNoCountryLocaleMessageFilesAvailable.
/**
* @see AdministrationService#getPresentationLocales()
*/
@Test
public void getPresentationLocales_shouldReturnLanguageLocaleIfItIsSpecifiedInAllowedListAndThereAreNoCountryLocaleMessageFilesAvailable() {
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, es"));
List<Locale> locales = new ArrayList<>();
locales.add(new Locale("pl", "PL"));
locales.add(new Locale("en"));
locales.add(new Locale("es"));
MutableResourceBundleMessageSource mutableResourceBundleMessageSource = Mockito.mock(MutableResourceBundleMessageSource.class);
Mockito.when(mutableResourceBundleMessageSource.getLocales()).thenReturn(locales);
MutableMessageSource mutableMessageSource = Context.getMessageSourceService().getActiveMessageSource();
Context.getMessageSourceService().setActiveMessageSource(mutableResourceBundleMessageSource);
Set<Locale> presentationLocales = Context.getAdministrationService().getPresentationLocales();
Context.getMessageSourceService().setActiveMessageSource(mutableMessageSource);
Assert.assertEquals(2, presentationLocales.size());
Assert.assertTrue("en", presentationLocales.contains(new Locale("en")));
Assert.assertTrue("es", presentationLocales.contains(new Locale("es")));
}
use of org.openmrs.messagesource.MutableMessageSource in project openmrs-core by openmrs.
the class AdministrationServiceTest method getPresentationLocales_shouldPreserveInsertionOrderInSetReturnedByMethod.
/**
* @see AdministrationService#getPresentationLocales()
*/
@Test
public void getPresentationLocales_shouldPreserveInsertionOrderInSetReturnedByMethod() {
String globalPropertyLocaleListAllowedData = "en_GB, es, ja_JP, it_IT, pl_PL";
// The order of languages and locales is described above and should be followed bt `presentationLocales` Set
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, globalPropertyLocaleListAllowedData));
List<Locale> locales = new ArrayList<>();
// Add data in random order and verify that order is maintained in the end by checking against order in global property
locales.add(new Locale("pl", "PL"));
locales.add(new Locale("es"));
locales.add(new Locale("en"));
locales.add(new Locale("it", "IT"));
MutableResourceBundleMessageSource mutableResourceBundleMessageSource = Mockito.mock(MutableResourceBundleMessageSource.class);
Mockito.when(mutableResourceBundleMessageSource.getLocales()).thenReturn(locales);
MutableMessageSource mutableMessageSource = Context.getMessageSourceService().getActiveMessageSource();
Context.getMessageSourceService().setActiveMessageSource(mutableResourceBundleMessageSource);
List<Locale> presentationLocales = new ArrayList<>(Context.getAdministrationService().getPresentationLocales());
Context.getMessageSourceService().setActiveMessageSource(mutableMessageSource);
// Assert Locales in expected order as set by global property
Assert.assertEquals(new Locale("en"), presentationLocales.get(0));
Assert.assertEquals(new Locale("es"), presentationLocales.get(1));
Assert.assertEquals(new Locale("it", "IT"), presentationLocales.get(2));
Assert.assertEquals(new Locale("pl", "PL"), presentationLocales.get(3));
}
use of org.openmrs.messagesource.MutableMessageSource in project openmrs-core by openmrs.
the class AdministrationServiceTest method getPresentationLocales_shouldReturnLanguageLocaleIfCountryLocaleIsSpecifiedInAllowedListButCountryLocaleMessageFileIsMissing.
/**
* @see AdministrationService#getPresentationLocales()
*/
@Test
public void getPresentationLocales_shouldReturnLanguageLocaleIfCountryLocaleIsSpecifiedInAllowedListButCountryLocaleMessageFileIsMissing() {
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, es_CL"));
List<Locale> locales = new ArrayList<>();
locales.add(new Locale("pl", "PL"));
locales.add(new Locale("en"));
locales.add(new Locale("es"));
MutableResourceBundleMessageSource mutableResourceBundleMessageSource = Mockito.mock(MutableResourceBundleMessageSource.class);
Mockito.when(mutableResourceBundleMessageSource.getLocales()).thenReturn(locales);
MutableMessageSource mutableMessageSource = Context.getMessageSourceService().getActiveMessageSource();
Context.getMessageSourceService().setActiveMessageSource(mutableResourceBundleMessageSource);
Set<Locale> presentationLocales = Context.getAdministrationService().getPresentationLocales();
Context.getMessageSourceService().setActiveMessageSource(mutableMessageSource);
Assert.assertEquals(2, presentationLocales.size());
Assert.assertTrue("en", presentationLocales.contains(new Locale("en")));
Assert.assertTrue("es", presentationLocales.contains(new Locale("es")));
}
Aggregations