Search in sources :

Example 16 with GlobalProperty

use of org.openmrs.GlobalProperty 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")));
}
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 17 with GlobalProperty

use of org.openmrs.GlobalProperty 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")));
}
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 18 with GlobalProperty

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

the class AdministrationServiceTest method saveGlobalProperty_shouldNotAllowDifferentPropertiesToHaveTheSameStringWithDifferentCase.

/**
 * @see AdministrationService#saveGlobalProperty(GlobalProperty)
 */
@Test
public void saveGlobalProperty_shouldNotAllowDifferentPropertiesToHaveTheSameStringWithDifferentCase() {
    executeDataSet("org/openmrs/api/include/AdministrationServiceTest-globalproperties.xml");
    // sanity check
    String orig = adminService.getGlobalProperty("another-global-property");
    Assert.assertEquals("anothervalue", orig);
    // should match current gp and update
    GlobalProperty gp = new GlobalProperty("ANOTher-global-property", "somethingelse");
    adminService.saveGlobalProperty(gp);
    String prop = adminService.getGlobalProperty("ANOTher-global-property", "boo");
    Assert.assertEquals("somethingelse", prop);
    orig = adminService.getGlobalProperty("another-global-property");
    Assert.assertEquals("somethingelse", orig);
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 19 with GlobalProperty

use of org.openmrs.GlobalProperty 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));
}
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 20 with GlobalProperty

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

the class AdministrationServiceTest method getGlobalPropertiesByPrefix_shouldReturnAllRelevantGlobalPropertiesInTheDatabase.

/**
 * @see AdministrationService#getGlobalPropertiesByPrefix(String)
 */
@Test
public void getGlobalPropertiesByPrefix_shouldReturnAllRelevantGlobalPropertiesInTheDatabase() {
    executeDataSet("org/openmrs/api/include/AdministrationServiceTest-globalproperties.xml");
    List<GlobalProperty> properties = adminService.getGlobalPropertiesByPrefix("fake.module.");
    for (GlobalProperty property : properties) {
        Assert.assertTrue(property.getProperty().startsWith("fake.module."));
        Assert.assertTrue(property.getPropertyValue().startsWith("correct-value"));
    }
}
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