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"));
}
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);
}
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());
}
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());
}
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);
}
Aggregations