use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class AdministrationServiceTest method getSearchLocales_shouldIncludeUsersProficientLocales.
/**
* @see AdministrationService#getSearchLocales(User)
*/
@Test
public void getSearchLocales_shouldIncludeUsersProficientLocales() {
// given
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, en_US, pl"));
User user = Context.getAuthenticatedUser();
user.setUserProperty(OpenmrsConstants.USER_PROPERTY_PROFICIENT_LOCALES, "en_GB, en_US");
Context.getUserService().saveUser(user);
// when
List<Locale> searchLocales = Context.getAdministrationService().getSearchLocales();
// then
Assert.assertTrue("en_GB", searchLocales.contains(new Locale("en", "GB")));
Assert.assertTrue("en_US", searchLocales.contains(new Locale("en", "US")));
Assert.assertFalse("pl", searchLocales.contains(new Locale("pl")));
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class AdministrationServiceTest method getSearchLocales_shouldExcludeNotAllowedLocales.
/**
* @see AdministrationService#getSearchLocales(User)
*/
@Test
public void getSearchLocales_shouldExcludeNotAllowedLocales() {
// given
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_US, en_GB, pl, es"));
User user = Context.getAuthenticatedUser();
user.setUserProperty(OpenmrsConstants.USER_PROPERTY_PROFICIENT_LOCALES, "es_CL, en_US, pl");
Context.getUserService().saveUser(user);
// when
List<Locale> searchLocales = Context.getAdministrationService().getSearchLocales();
// then
Assert.assertTrue("en_US", searchLocales.contains(new Locale("en", "US")));
Assert.assertTrue("pl", searchLocales.contains(new Locale("pl")));
Assert.assertTrue("es", searchLocales.contains(new Locale("es")));
Assert.assertFalse("es_CL", searchLocales.contains(new Locale("es", "CL")));
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class AdministrationServiceTest method updateGlobalProperty_shouldUpdateAGlobalPropertyWhoseTypedvalueIsHandledByACustomDatatype.
/**
* @see AdministrationService#updateGlobalProperty(String,String)
*/
@Test
public void updateGlobalProperty_shouldUpdateAGlobalPropertyWhoseTypedvalueIsHandledByACustomDatatype() {
GlobalProperty gp = new GlobalProperty();
gp.setProperty("Flag");
gp.setDatatypeClassname(BooleanDatatype.class.getName());
gp.setValue(Boolean.FALSE);
adminService.saveGlobalProperty(gp);
Assert.assertEquals(adminService.getGlobalProperty("Flag"), "false");
adminService.updateGlobalProperty("Flag", Boolean.TRUE.toString());
Assert.assertEquals(adminService.getGlobalProperty("Flag"), "true");
}
use of org.openmrs.GlobalProperty 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")));
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class AdministrationServiceTest method setImplementationId_shouldSetUuidOnImplementationIdGlobalProperty.
/**
* @see AdministrationService#setImplementationId(ImplementationId)
*/
@Test
@Ignore
public void setImplementationId_shouldSetUuidOnImplementationIdGlobalProperty() {
ImplementationId validId = new ImplementationId();
validId.setImplementationId("JUNIT-TEST");
validId.setName("JUNIT-TEST implementation id");
validId.setPassphrase("This is the junit test passphrase");
validId.setDescription("This is the junit impl id used for testing of the openmrs API only.");
adminService.setImplementationId(validId);
GlobalProperty gp = adminService.getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_IMPLEMENTATION_ID);
Assert.assertNotNull(gp.getUuid());
}
Aggregations