use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class AdministrationServiceTest method getSearchLocales_shouldCacheResultsForAnUser.
/**
* @see AdministrationService#getSearchLocales()
*/
@Test
public void getSearchLocales_shouldCacheResultsForAnUser() {
// 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
Context.getAdministrationService().getSearchLocales();
List<Locale> cachedSearchLocales = getCachedSearchLocalesForCurrentUser();
// then
assertThat(cachedSearchLocales, hasItem(Locale.ENGLISH));
assertThat(cachedSearchLocales, hasItem(new Locale("en", "US")));
assertThat(cachedSearchLocales, not(hasItem(new Locale("pl"))));
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class UserValidatorTest method validate_shouldFailValidationIfEmailAsUsernameDisabledAndEmailProvided.
/**
* @see UserValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfEmailAsUsernameDisabledAndEmailProvided() {
User user = new User();
user.setUsername("test@example.com");
AdministrationService as = Context.getAdministrationService();
as.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_USER_REQUIRE_EMAIL_AS_USERNAME, "false"));
Errors errors = new BindException(user, "user");
validator.validate(user, errors);
Assert.assertTrue(errors.hasFieldErrors("username"));
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class UserValidatorTest method validate_shouldFailValidationIfEmailAsUsernameEnabledAndEmailInvalid.
/**
* @see UserValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfEmailAsUsernameEnabledAndEmailInvalid() {
User user = new User();
user.setUsername("test@example.com");
AdministrationService as = Context.getAdministrationService();
as.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_USER_REQUIRE_EMAIL_AS_USERNAME, "true"));
Errors errors = new BindException(user, "user");
validator.validate(user, errors);
Assert.assertFalse(errors.hasFieldErrors("username"));
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class GlobalPropertiesTestHelper method purgeGlobalProperty.
public void purgeGlobalProperty(String propertyName) {
GlobalProperty globalProperty = administrationService.getGlobalPropertyObject(propertyName);
if (globalProperty != null) {
administrationService.purgeGlobalProperty(globalProperty);
}
Assert.assertNull(administrationService.getGlobalProperty(propertyName));
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class LocaleUtilityTest method getDefaultLocale_shouldNotFailWithBogusGlobalPropertyValue.
/**
* @see LocaleUtility#getDefaultLocale()
*/
@Test
public void getDefaultLocale_shouldNotFailWithBogusGlobalPropertyValue() {
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, asdfasdf"));
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, "asdfasdf"));
// check for nonnullness
Assert.assertNotNull(LocaleUtility.getDefaultLocale());
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, ""));
}
Aggregations