@Test public void globalPropertyChanged_shouldSetAllowedLocalesIfGlobalPropertyIsAnEmptyString() { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, ""); globalLocaleList.globalPropertyChanged(gp); assertThat(globalLocaleList.getAllowedLocales(), contains(Locale.ROOT)); }
/** * @see OrderService#getDrugDosingUnits() */ @Test public void getDrugDosingUnits_shouldReturnAnEmptyListIfNothingIsConfigured() { adminService.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GP_DRUG_DOSING_UNITS_CONCEPT_UUID, "")); assertThat(orderService.getDrugDosingUnits(), is(empty())); }
/** * @see OrderService#getTestSpecimenSources() */ @Test public void getTestSpecimenSources_shouldReturnAnEmptyListIfNothingIsConfigured() { adminService.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GP_TEST_SPECIMEN_SOURCES_CONCEPT_UUID, "")); assertThat(orderService.getTestSpecimenSources(), is(empty())); }
@Test public void saveGlobalProperty_shouldFailIfDefaultLocaleNotInAllowedLocaleList() { Locale defaultLocale = new Locale("fr"); expectedException.expect(APIException.class); expectedException.expectMessage("is not in allowed locales list"); adminService.saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, defaultLocale.toString())); }
/** * Creates a new Global Property to lock person attribute types by setting its value * @param propertyValue value for person attribute types locked GP */ public void createPersonAttributeTypeLockedGPAndSetValue(String propertyValue) { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PERSON_ATRIBUTE_TYPES_LOCKED); gp.setPropertyValue(propertyValue); Context.getAdministrationService().saveGlobalProperty(gp); }
@Test public void getAllowedLocales_shouldNotFailIfNotGlobalPropertyForLocalesAllowedDefinedYet() { adminService.purgeGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST)); adminService.getAllowedLocales(); }
@Test public void saveGlobalProperty_shouldFailIfGivenAllowedLocaleListDoesNotContainDefaultLocale() { String localeList = "fr,es"; assertThat("localeList contains default locale but should not for this test case", localeList, not(containsString(LocaleUtility.getDefaultLocale().toString()))); expectedException.expect(APIException.class); expectedException.expectMessage("can not be removed from allowed locales list because it is the default locale"); adminService.saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, localeList)); }
/** * Creates a new Global Property to lock patient identifier types by setting its value * * @param propertyValue value for patient identifier types locked GP */ public void createPatientIdentifierTypeLockedGPAndSetValue(String propertyValue) { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_TYPES_LOCKED); gp.setPropertyValue(propertyValue); Context.getAdministrationService().saveGlobalProperty(gp); }
/** * Creates a new Global Property to lock forms by setting its value * @param propertyValue value for forms locked GP */ public void createFormsLockedGPAndSetValue(String propertyValue) { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_FORMS_LOCKED); gp.setPropertyValue(propertyValue); Context.getAdministrationService().saveGlobalProperty(gp); }
/** * @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()); }
/** * @see OrderService#getNonCodedDrugConcept() */ @Test public void getNonCodedDrugConcept_shouldReturnNullIfNothingIsConfigured() { adminService.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GP_DRUG_ORDER_DRUG_OTHER, "")); assertNull(orderService.getNonCodedDrugConcept()); }
@Test public void saveGlobalProperty_shouldSaveAGlobalPropertyWhoseTypedValueIsHandledByACustomDatatype() { GlobalProperty gp = new GlobalProperty(); gp.setProperty("What time is it?"); gp.setDatatypeClassname(DateDatatype.class.getName()); gp.setValue(new Date()); adminService.saveGlobalProperty(gp); assertNotNull(gp.getValueReference()); }
@Test public void saveGlobalProperties_shouldAssignUuidToAllNewProperties() { // get the current global properties List<GlobalProperty> globalProperties = adminService.getAllGlobalProperties(); // and now add a new one to it and save it globalProperties.add(new GlobalProperty("new prop", "new prop value", "desc")); adminService.saveGlobalProperties(globalProperties); assertNotNull(adminService.getGlobalPropertyObject("new prop").getUuid()); }
@Test(expected = APIException.class) public void getActiveEncounterVisitHandler_shouldThrowIfBeanWithGivenTypeAndNameNotFound() { String incorrectBeanName = OpenmrsConstants.REGISTERED_COMPONENT_NAME_PREFIX + "invalidName"; GlobalProperty visitHandlerProperty = new GlobalProperty(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER, incorrectBeanName); Context.getAdministrationService().saveGlobalProperty(visitHandlerProperty); Context.getEncounterService().getActiveEncounterVisitHandler(); }
@Test public void saveGlobalProperty_shouldCreateGlobalPropertyInDatabase() { executeDataSet(ADMIN_INITIAL_DATA_XML); adminService.saveGlobalProperty(new GlobalProperty("detectHiddenSkill", "100")); assertNotNull(adminService.getGlobalProperty("detectHiddenSkill")); }
@Test public void getActiveEncounterVisitHandler_shouldReturnBeanHaveBeenRegisteredWithGivenName() { String correctBeanName = OpenmrsConstants.REGISTERED_COMPONENT_NAME_PREFIX + "existingOrNewVisitAssignmentHandler"; GlobalProperty visitHandlerProperty = new GlobalProperty(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER, correctBeanName); Context.getAdministrationService().saveGlobalProperty(visitHandlerProperty); EncounterVisitHandler activeEncounterVisitHandler = Context.getEncounterService().getActiveEncounterVisitHandler(); Assert.assertNotNull(activeEncounterVisitHandler); }
@Before public void setUp() { validator = new PersonNameValidator(); personName = new PersonName(); errors = new BindException(personName, "personName"); Context.getAdministrationService().saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_NAME_REGEX, "^[a-zA-Z \\-]+$")); }
/** * @see LocationService#getDefaultLocation() */ @Test public void getDefaultLocation_shouldReturnDefaultLocationForTheImplementation() { //set the global property for default location to something other than Unknown Location GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCATION_NAME, "Test Parent Location", "Testing default Location"); Context.getAdministrationService().saveGlobalProperty(gp); Assert.assertEquals("Test Parent Location", Context.getLocationService().getDefaultLocation().getName()); }
/** * @see LocationService#getDefaultLocation() */ @Test public void getDefaultLocation_shouldReturnUnknownLocationIfTheGlobalPropertyIsSomethingElseThatDoesnotExist() { //set the global property to something that has no match in the location table GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCATION_NAME, "None existent Location", "Testing"); Context.getAdministrationService().saveGlobalProperty(gp); Assert.assertEquals("Unknown Location", Context.getLocationService().getDefaultLocation().getName()); }
/** * @see LocationUtility#getDefaultLocation() */ @Test public void getDefaultLocation_shouldReturnTheUpdatedDefaultLocationWhenTheValueOfTheGlobalPropertyIsChanged() { //sanity check Assert.assertEquals("Unknown Location", LocationUtility.getDefaultLocation().getName()); GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCATION_NAME, "Xanadu", "Testing"); Context.getAdministrationService().saveGlobalProperty(gp); Assert.assertEquals("Xanadu", LocationUtility.getDefaultLocation().getName()); }