Search in sources :

Example 86 with GlobalProperty

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

Example 87 with GlobalProperty

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

Example 88 with GlobalProperty

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

Example 89 with GlobalProperty

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")));
}
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 90 with GlobalProperty

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