Search in sources :

Example 26 with GlobalProperty

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

the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsTrue.

/**
 * @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
 */
@Test
public void saveOrder_shouldFailDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsTrue() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Patient patient = Context.getPatientService().getPatient(7);
    CareSetting careSetting = Context.getOrderService().getCareSetting(2);
    OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    order.setEncounter(encounter);
    order.setConcept(Context.getConceptService().getConcept(5497));
    order.setPatient(patient);
    order.setCareSetting(careSetting);
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setDateActivated(encounter.getEncounterDatetime());
    order.setOrderType(orderType);
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setInstructions("None");
    order.setDosingInstructions("Test Instruction");
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("drug"));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 27 with GlobalProperty

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

the class LocaleUtilityTest method should_resetTheLocale.

/**
 * This test doesn't really test anything, and it should ALWAYS be the last method in this
 * class. <br>
 * <br>
 * This method just resets the current user's locale so that when things are run in batches all
 * tests still work.
 */
@Test
public void should_resetTheLocale() {
    // set user locale to nothing
    Context.setLocale(null);
    // clear out the caches
    GlobalProperty defaultLocale = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, "", "blanking out default locale");
    Context.getAdministrationService().saveGlobalProperty(defaultLocale);
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 28 with GlobalProperty

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

the class LocaleUtilityTest method getDefaultLocale_shouldNotFailWithEmptyGlobalPropertyValue.

/**
 * @see LocaleUtility#getDefaultLocale()
 */
@Test
public void getDefaultLocale_shouldNotFailWithEmptyGlobalPropertyValue() {
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, ""));
    // check for nonnullness
    Assert.assertNotNull(LocaleUtility.getDefaultLocale());
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 29 with GlobalProperty

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

the class LocaleUtilityTest method getDefaultLocale_shouldReturnLocaleObjectForGlobalProperty.

/**
 * @see LocaleUtility#getDefaultLocale()
 */
@Test
public void getDefaultLocale_shouldReturnLocaleObjectForGlobalProperty() {
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, ja"));
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, "ja"));
    Assert.assertEquals(Locale.JAPANESE, LocaleUtility.getDefaultLocale());
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 30 with GlobalProperty

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

the class LocaleUtilityTest method getDefaultLocale_shouldNotCacheLocaleWhenSessionIsNotOpen.

/**
 * @see LocaleUtility#getDefaultLocale()
 */
@Test
public void getDefaultLocale_shouldNotCacheLocaleWhenSessionIsNotOpen() {
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, ja"));
    // set GP default locale to valid locale that is not the OpenmrsConstant default locale
    GlobalProperty gp = Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, "ja"));
    // close session
    Context.closeSession();
    // This might fail if default locale is called before this test is run and so the static defaultLocale is cached
    // 
    // verify that default locale is the OpenmrsConstant default locale
    Assert.assertEquals(LocaleUtility.fromSpecification(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE_DEFAULT_VALUE), LocaleUtility.getDefaultLocale());
    // open a session
    Context.openSession();
    authenticate();
    // verify that the default locale is the GP default locale
    Assert.assertEquals(Locale.JAPANESE, LocaleUtility.getDefaultLocale());
    // clear GP default locale
    gp.setPropertyValue("");
    Context.getAdministrationService().saveGlobalProperty(gp);
}
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