Search in sources :

Example 11 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.

the class AdministrationServiceTest method saveGlobalProperties_shouldAssignUuidToAllNewProperties.

/**
 * @see AdministrationService#saveGlobalProperties(List)
 */
@Test
public void saveGlobalProperties_shouldAssignUuidToAllNewProperties() {
    // get the current global properties
    List<GlobalProperty> globalProperties = Context.getAdministrationService().getAllGlobalProperties();
    // and now add a new one to it and save it
    globalProperties.add(new GlobalProperty("new prop", "new prop value", "desc"));
    Context.getAdministrationService().saveGlobalProperties(globalProperties);
    Assert.assertNotNull(Context.getAdministrationService().getGlobalPropertyObject("new prop").getUuid());
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 12 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.

the class AdministrationServiceTest method getSearchLocales_shouldIncludeCurrentlySelectedFullLocaleAndLangugage.

/**
 * @see AdministrationService#getSearchLocales(User)
 */
@Test
public void getSearchLocales_shouldIncludeCurrentlySelectedFullLocaleAndLangugage() {
    // given
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB"));
    User user = Context.getAuthenticatedUser();
    user.setUserProperty(OpenmrsConstants.USER_PROPERTY_PROFICIENT_LOCALES, "");
    Context.getUserService().saveUser(user);
    Context.setLocale(new Locale("en", "GB"));
    // when
    List<Locale> searchLocales = Context.getAdministrationService().getSearchLocales();
    // then
    Assert.assertEquals(Context.getLocale(), searchLocales.get(0));
    Assert.assertEquals(new Locale(Context.getLocale().getLanguage()), searchLocales.get(1));
}
Also used : Locale(java.util.Locale) User(org.openmrs.User) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 13 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.

the class AdministrationServiceTest method saveGlobalProperty_shouldCreateGlobalPropertyInDatabase.

/**
 * @see AdministrationService#saveGlobalProperty(GlobalProperty)
 */
@Test
public void saveGlobalProperty_shouldCreateGlobalPropertyInDatabase() {
    executeDataSet(ADMIN_INITIAL_DATA_XML);
    AdministrationService as = Context.getAdministrationService();
    as.saveGlobalProperty(new GlobalProperty("detectHiddenSkill", "100"));
    Assert.assertNotNull(as.getGlobalProperty("detectHiddenSkill"));
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with GlobalProperty

use of org.openmrs.GlobalProperty 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")));
}
Also used : Locale(java.util.Locale) MutableResourceBundleMessageSource(org.openmrs.messagesource.impl.MutableResourceBundleMessageSource) ArrayList(java.util.ArrayList) MutableMessageSource(org.openmrs.messagesource.MutableMessageSource) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.

the class AdministrationServiceTest method getAllowedLocales_shouldNotFailIfNotGlobalPropertyForLocalesAllowedDefinedYet.

/**
 * @see AdministrationService#getAllowedLocales()
 */
@Test
public void getAllowedLocales_shouldNotFailIfNotGlobalPropertyForLocalesAllowedDefinedYet() {
    Context.getAdministrationService().purgeGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST));
    Context.getAdministrationService().getAllowedLocales();
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

GlobalProperty (org.openmrs.GlobalProperty)107 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 BindException (org.springframework.validation.BindException)10 DrugOrder (org.openmrs.DrugOrder)9 Errors (org.springframework.validation.Errors)9 AdministrationService (org.openmrs.api.AdministrationService)8 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)4 MutableMessageSource (org.openmrs.messagesource.MutableMessageSource)4 MutableResourceBundleMessageSource (org.openmrs.messagesource.impl.MutableResourceBundleMessageSource)4