Search in sources :

Example 91 with GlobalProperty

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"))));
}
Also used : Locale(java.util.Locale) User(org.openmrs.User) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 92 with GlobalProperty

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"));
}
Also used : Errors(org.springframework.validation.Errors) User(org.openmrs.User) AdministrationService(org.openmrs.api.AdministrationService) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 93 with GlobalProperty

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"));
}
Also used : Errors(org.springframework.validation.Errors) User(org.openmrs.User) AdministrationService(org.openmrs.api.AdministrationService) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 94 with GlobalProperty

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));
}
Also used : GlobalProperty(org.openmrs.GlobalProperty)

Example 95 with GlobalProperty

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, ""));
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

GlobalProperty (org.openmrs.GlobalProperty)110 Test (org.junit.Test)80 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)77 Locale (java.util.Locale)14 OrderUtilTest (org.openmrs.order.OrderUtilTest)14 Encounter (org.openmrs.Encounter)12 ArrayList (java.util.ArrayList)11 User (org.openmrs.User)11 Patient (org.openmrs.Patient)10 AdministrationService (org.openmrs.api.AdministrationService)10 BindException (org.springframework.validation.BindException)10 DrugOrder (org.openmrs.DrugOrder)9 Errors (org.springframework.validation.Errors)9 CareSetting (org.openmrs.CareSetting)7 OrderType (org.openmrs.OrderType)7 Date (java.util.Date)6 EncounterType (org.openmrs.EncounterType)5 APIException (org.openmrs.api.APIException)5 MutableMessageSource (org.openmrs.messagesource.MutableMessageSource)4 MutableResourceBundleMessageSource (org.openmrs.messagesource.impl.MutableResourceBundleMessageSource)4