org.openmrs.GlobalProperty - java examples

Here are the examples of the java api org.openmrs.GlobalProperty taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

62 Examples 7

19 View Complete Implementation : ModuleUtilTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.module.ModuleUtil#getMandatoryModules()
 */
@Test
public void getMandatoryModules_shouldReturnMandatoryModuleIds() {
    // given
    GlobalProperty gp1 = new GlobalProperty("firstmodule.mandatory", "true");
    GlobalProperty gp2 = new GlobalProperty("secondmodule.mandatory", "false");
    Context.getAdministrationService().saveGlobalProperty(gp1);
    Context.getAdministrationService().saveGlobalProperty(gp2);
    // when
    // then
    replacedertThat(ModuleUtil.getMandatoryModules(), contains("firstmodule"));
}

19 View Complete Implementation : LocaleUtility.java
Copyright Apache License 2.0
Author : isstac
@Override
public void globalPropertyChanged(GlobalProperty newValue) {
    // reset the value
    setDefaultLocaleCache(null);
    setLocalesAllowedListCache(null);
}

19 View Complete Implementation : ModuleUtilTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.module.ModuleUtil#checkMandatoryModulesStarted()
 */
@Test(expected = MandatoryModuleException.clreplaced)
public void checkMandatoryModulesStarted_shouldThrowModuleExceptionIfAMandatoryModuleIsNotStarted() {
    // given
    replacedertThat(ModuleFactory.getStartedModules(), empty());
    GlobalProperty gp1 = new GlobalProperty("module1.mandatory", "true");
    Context.getAdministrationService().saveGlobalProperty(gp1);
    // when
    ModuleUtil.checkMandatoryModulesStarted();
// then exception
}

19 View Complete Implementation : TestUtil.java
Copyright Apache License 2.0
Author : isstac
/**
 * Utility method that allows tests to easily configure and save a global property
 * @param string the name of the property to save
 * @param value the value of the property to save
 */
public static void saveGlobalProperty(String name, String value) {
    GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(name);
    if (gp == null) {
        gp = new GlobalProperty(name);
    }
    gp.setPropertyValue(value);
    Context.getAdministrationService().saveGlobalProperty(gp);
}

19 View Complete Implementation : PersonNameGlobalPropertyListener.java
Copyright Apache License 2.0
Author : isstac
@Override
public void globalPropertyChanged(GlobalProperty newValue) {
    PersonName.setFormat(newValue.getPropertyValue());
}

19 View Complete Implementation : LocationUtility.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.GlobalPropertyListener#globalPropertyChanged(org.openmrs.GlobalProperty)
 */
@Override
public void globalPropertyChanged(GlobalProperty newValue) {
    // reset the value
    setDefaultLocation(null);
}

19 View Complete Implementation : OpenmrsUtilTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * Tests the methods in {@link OpenmrsUtil} TODO: finish adding tests for all methods
 */
public clreplaced OpenmrsUtilTest extends BaseContextSensitiveTest {

    private static GlobalProperty luhnGP = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_PATIENT_IDENTIFIER_VALIDATOR, OpenmrsConstants.LUHN_IDENTIFIER_VALIDATOR);

    /**
     * @throws Exception
     * @see org.springframework.test.AbstractTransactionalSpringContextTests#onSetUpInTransaction()
     */
    @Before
    public void runBeforeEachTest() throws Exception {
        initializeInMemoryDatabase();
        authenticate();
        Context.getAdministrationService().saveGlobalProperty(luhnGP);
    }

    /**
     * test the collection contains method
     *
     * @see OpenmrsUtil#collectionContains(Collection,Object)
     */
    @Test
    public void collectionContains_shouldUseEqualsMethodForComparisonInsteadOfCompareToGivenListCollection() {
        ArrayList<PatientIdentifier> identifiers = new ArrayList<>();
        PatientIdentifier pi = new PatientIdentifier();
        pi.setIdentifier("123");
        pi.setIdentifierType(new PatientIdentifierType(1));
        pi.setDateCreated(new Date());
        pi.setCreator(new User(1));
        identifiers.add(pi);
        // sanity check
        identifiers.add(pi);
        replacedertFalse("Lists should accept more than one object", identifiers.size() == 1);
        pi.setDateCreated(null);
        pi.setCreator(null);
        replacedertTrue("Just because the date is null, doesn't make it not in the list anymore", OpenmrsUtil.collectionContains(identifiers, pi));
    }

    /**
     * test the collection contains method
     *
     * @see OpenmrsUtil#collectionContains(Collection,Object)
     */
    @Test
    public void collectionContains_shouldUseEqualsMethodForComparisonInsteadOfCompareToGivenSortedSetCollection() {
        SortedSet<PatientIdentifier> identifiers = new TreeSet<>();
        PatientIdentifier pi = new PatientIdentifier();
        pi.setIdentifier("123");
        pi.setIdentifierType(new PatientIdentifierType(1));
        pi.setDateCreated(new Date());
        pi.setCreator(new User(1));
        identifiers.add(pi);
        // sanity check
        identifiers.add(pi);
        replacedertTrue("There should still be only 1 identifier in the patient object now", identifiers.size() == 1);
        pi.setDateCreated(null);
        pi.setCreator(null);
        replacedertTrue("Just because the date is null, doesn't make it not in the list anymore", OpenmrsUtil.collectionContains(identifiers, pi));
    }

    /**
     * When given a null parameter, the {@link OpenmrsUtil#url2file(java.net.URL)} method should
     * quietly fail by returning null
     *
     * @see OpenmrsUtil#url2file(URL)
     */
    @Test
    public void url2file_shouldReturnNullGivenNullParameter() {
        replacedertNull(OpenmrsUtil.url2file(null));
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = InvalidCharactersPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithDigitOnlyPreplacedwordByDefault() {
        OpenmrsUtil.validatePreplacedword("admin", "12345678", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = InvalidCharactersPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithDigitOnlyPreplacedwordIfNotAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_REQUIRES_NON_DIGIT, "true");
        OpenmrsUtil.validatePreplacedword("admin", "12345678", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test
    public void validatePreplacedword_shouldPreplacedWithDigitOnlyPreplacedwordIfAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_REQUIRES_NON_DIGIT, "false");
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_REQUIRES_UPPER_AND_LOWER_CASE, "false");
        OpenmrsUtil.validatePreplacedword("admin", "12345678", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = InvalidCharactersPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithCharOnlyPreplacedwordByDefault() {
        OpenmrsUtil.validatePreplacedword("admin", "testonly", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = InvalidCharactersPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithCharOnlyPreplacedwordIfNotAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_REQUIRES_DIGIT, "true");
        OpenmrsUtil.validatePreplacedword("admin", "testonly", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test
    public void validatePreplacedword_shouldPreplacedWithCharOnlyPreplacedwordIfAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_REQUIRES_DIGIT, "false");
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_REQUIRES_UPPER_AND_LOWER_CASE, "false");
        OpenmrsUtil.validatePreplacedword("admin", "testonly", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = InvalidCharactersPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithoutUpperAndLowerCasePreplacedwordByDefault() {
        OpenmrsUtil.validatePreplacedword("admin", "test0nl1", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = InvalidCharactersPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithoutUpperAndLowerCasePreplacedwordIfNotAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_REQUIRES_UPPER_AND_LOWER_CASE, "true");
        OpenmrsUtil.validatePreplacedword("admin", "test0nl1", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test
    public void validatePreplacedword_shouldPreplacedWithoutUpperAndLowerCasePreplacedwordIfAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_REQUIRES_UPPER_AND_LOWER_CASE, "false");
        OpenmrsUtil.validatePreplacedword("admin", "test0nl1", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = WeakPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithPreplacedwordEqualsToUserNameByDefault() {
        OpenmrsUtil.validatePreplacedword("Admin1234", "Admin1234", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = WeakPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithPreplacedwordEqualsToUserNameIfNotAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_CANNOT_MATCH_USERNAME_OR_SYSTEMID, "true");
        OpenmrsUtil.validatePreplacedword("Admin1234", "Admin1234", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test
    public void validatePreplacedword_shouldPreplacedWithPreplacedwordEqualsToUserNameIfAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_CANNOT_MATCH_USERNAME_OR_SYSTEMID, "false");
        OpenmrsUtil.validatePreplacedword("Admin1234", "Admin1234", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = WeakPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithPreplacedwordEqualsToSystemIdByDefault() {
        OpenmrsUtil.validatePreplacedword("admin", "Admin1234", "Admin1234");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = WeakPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithPreplacedwordEqualsToSystemIdIfNotAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_CANNOT_MATCH_USERNAME_OR_SYSTEMID, "true");
        OpenmrsUtil.validatePreplacedword("admin", "Admin1234", "Admin1234");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test
    public void validatePreplacedword_shouldPreplacedWithPreplacedwordEqualsToSystemIdIfAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_CANNOT_MATCH_USERNAME_OR_SYSTEMID, "false");
        OpenmrsUtil.validatePreplacedword("admin", "Admin1234", "Admin1234");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = ShortPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithShortPreplacedwordByDefault() {
        OpenmrsUtil.validatePreplacedword("admin", "1234567", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = ShortPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithShortPreplacedwordIfNotAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_MINIMUM_LENGTH, "6");
        OpenmrsUtil.validatePreplacedword("admin", "12345", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test
    public void validatePreplacedword_shouldPreplacedWithShortPreplacedwordIfAllowed() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_MINIMUM_LENGTH, "0");
        OpenmrsUtil.validatePreplacedword("admin", "H4t", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test(expected = InvalidCharactersPreplacedwordException.clreplaced)
    public void validatePreplacedword_shouldFailWithPreplacedwordNotMatchingConfiguredRegex() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_CUSTOM_REGEX, "[A-Z][a-z][0-9][0-9][a-z][A-Z][a-z][a-z][a-z][a-z]");
        OpenmrsUtil.validatePreplacedword("admin", "he11oWorld", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test
    public void validatePreplacedword_shouldPreplacedWithPreplacedwordMatchingConfiguredRegex() {
        TestUtil.saveGlobalProperty(OpenmrsConstants.GP_PreplacedWORD_CUSTOM_REGEX, "[A-Z][a-z][0-9][0-9][a-z][A-Z][a-z][a-z][a-z][a-z]");
        OpenmrsUtil.validatePreplacedword("admin", "He11oWorld", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test
    public void validatePreplacedword_shouldAllowPreplacedwordToContainNonAlphanumericCharacters() {
        OpenmrsUtil.validatePreplacedword("admin", "Test1234?", "1-8");
    }

    /**
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test
    public void validatePreplacedword_shouldAllowPreplacedwordToContainWhiteSpaces() {
        OpenmrsUtil.validatePreplacedword("admin", "Test *&^ 1234? ", "1-8");
    }

    /**
     * @see OpenmrsUtil#getDateFormat(Locale)
     */
    @Test
    public void getDateFormat_shouldReturnAPatternWithFourYCharactersInIt() {
        replacedert.replacedertEquals("MM/dd/yyyy", OpenmrsUtil.getDateFormat(Locale.US).toLocalizedPattern());
        replacedert.replacedertEquals("dd/MM/yyyy", OpenmrsUtil.getDateFormat(Locale.UK).toLocalizedPattern());
        replacedert.replacedertEquals("tt.MM.uuuu", OpenmrsUtil.getDateFormat(Locale.GERMAN).toLocalizedPattern());
        replacedert.replacedertEquals("dd-MM-yyyy", OpenmrsUtil.getDateFormat(new Locale("pt", "pt")).toLocalizedPattern());
    }

    /**
     * @see OpenmrsUtil#containsUpperAndLowerCase(String)
     */
    @Test
    public void containsUpperAndLowerCase_shouldReturnTrueIfStringContainsUpperAndLowerCase() {
        replacedert.replacedertTrue(OpenmrsUtil.containsUpperAndLowerCase("Hello"));
        replacedert.replacedertTrue(OpenmrsUtil.containsUpperAndLowerCase("methodName"));
        replacedert.replacedertTrue(OpenmrsUtil.containsUpperAndLowerCase("the letter K"));
        replacedert.replacedertTrue(OpenmrsUtil.containsUpperAndLowerCase("The number 10"));
    }

    /**
     * @see OpenmrsUtil#containsUpperAndLowerCase(String)
     */
    @Test
    public void containsUpperAndLowerCase_shouldReturnFalseIfStringDoesNotContainLowerCaseCharacters() {
        replacedert.replacedertFalse(OpenmrsUtil.containsUpperAndLowerCase("HELLO"));
        replacedert.replacedertFalse(OpenmrsUtil.containsUpperAndLowerCase("THE NUMBER 10?"));
        replacedert.replacedertFalse(OpenmrsUtil.containsUpperAndLowerCase(""));
        replacedert.replacedertFalse(OpenmrsUtil.containsUpperAndLowerCase(null));
    }

    /**
     * @see OpenmrsUtil#containsUpperAndLowerCase(String)
     */
    @Test
    public void containsUpperAndLowerCase_shouldReturnFalseIfStringDoesNotContainUpperCaseCharacters() {
        replacedert.replacedertFalse(OpenmrsUtil.containsUpperAndLowerCase("hello"));
        replacedert.replacedertFalse(OpenmrsUtil.containsUpperAndLowerCase("the number 10?"));
        replacedert.replacedertFalse(OpenmrsUtil.containsUpperAndLowerCase(""));
        replacedert.replacedertFalse(OpenmrsUtil.containsUpperAndLowerCase(null));
    }

    /**
     * @see OpenmrsUtil#containsOnlyDigits(String)
     */
    @Test
    public void containsOnlyDigits_shouldReturnTrueIfStringContainsOnlyDigits() {
        replacedert.replacedertTrue(OpenmrsUtil.containsOnlyDigits("1234567890"));
    }

    /**
     * @see OpenmrsUtil#containsOnlyDigits(String)
     */
    @Test
    public void containsOnlyDigits_shouldReturnFalseIfStringContainsAnyNonDigits() {
        replacedert.replacedertFalse(OpenmrsUtil.containsOnlyDigits("1.23"));
        replacedert.replacedertFalse(OpenmrsUtil.containsOnlyDigits("123A"));
        replacedert.replacedertFalse(OpenmrsUtil.containsOnlyDigits("12 3"));
        replacedert.replacedertFalse(OpenmrsUtil.containsOnlyDigits(""));
        replacedert.replacedertFalse(OpenmrsUtil.containsOnlyDigits(null));
    }

    /**
     * @see OpenmrsUtil#containsDigit(String)
     */
    @Test
    public void containsDigit_shouldReturnTrueIfStringContainsAnyDigits() {
        replacedert.replacedertTrue(OpenmrsUtil.containsDigit("There is 1 digit here."));
    }

    /**
     * @see OpenmrsUtil#containsDigit(String)
     */
    @Test
    public void containsDigit_shouldReturnFalseIfStringContainsNoDigits() {
        replacedert.replacedertFalse(OpenmrsUtil.containsDigit("ABC .$!@#$%^&*()-+=/?><.,~`|[]"));
        replacedert.replacedertFalse(OpenmrsUtil.containsDigit(""));
        replacedert.replacedertFalse(OpenmrsUtil.containsDigit(null));
    }

    /**
     * The validate preplacedword method should be in a separate jvm here so that the Context and
     * services are not available to the validatePreplacedword (similar to how its used in the
     * initialization wizard), but that is not possible to set up on a test-by-test basis, so we
     * settle by making the user context not available.
     *
     * @see OpenmrsUtil#validatePreplacedword(String,String,String)
     */
    @Test
    public void validatePreplacedword_shouldStillWorkWithoutAnOpenSession() {
        Context.closeSession();
        OpenmrsUtil.validatePreplacedword("admin", "1234Preplacedword", "systemId");
    }

    /**
     * @see OpenmrsUtil#getDateFormat(Locale)
     */
    @Test
    public void getDateFormat_shouldNotAllowTheReturnedSimpleDateFormatToBeModified() {
        // start with a locale that is not currently cached by getDateFormat()
        Locale locale = new Locale("hk");
        replacedert.replacedertTrue("default locale is potentially already cached", !Context.getLocale().equals(locale));
        // get the initially built dateformat from getDateFormat()
        SimpleDateFormat sdf = OpenmrsUtil.getDateFormat(locale);
        replacedert.replacedertNotSame("initial dateFormatCache entry is modifiable", OpenmrsUtil.getDateFormat(locale), sdf);
        // verify changing the pattern on our variable does not affect the cache
        sdf.applyPattern("yyyymmdd");
        replacedert.replacedertTrue("initial dateFormatCache pattern is modifiable", !OpenmrsUtil.getDateFormat(locale).toPattern().equals(sdf.toPattern()));
        // the dateformat cache now contains the format for this locale; checking
        // a second time will guarantee we are looking at cached data and not the
        // initially built dateformat
        sdf = OpenmrsUtil.getDateFormat(locale);
        replacedert.replacedertNotSame("cached dateFormatCache entry is modifiable", OpenmrsUtil.getDateFormat(locale), sdf);
        // verify changing the pattern on our variable does not affect the cache
        sdf.applyPattern("yyyymmdd");
        replacedert.replacedertTrue("cached dateFormatCache pattern is modifiable", !OpenmrsUtil.getDateFormat(locale).toPattern().equals(sdf.toPattern()));
    }

    @Test
    public void openmrsDateFormat_shouldParseValidDate() throws ParseException {
        SimpleDateFormat sdf = OpenmrsUtil.getDateFormat(new Locale("en", "GB"));
        sdf.parse("20/12/2001");
        sdf = OpenmrsUtil.getDateFormat(new Locale("en", "US"));
        sdf.parse("12/20/2001");
    }

    @Test
    public void openmrsDateFormat_shouldNotAllowDatesWithInvalidDaysOrMonths() {
        try {
            SimpleDateFormat sdf = OpenmrsUtil.getDateFormat(new Locale("en", "GB"));
            sdf.parse("1/13/2001");
            replacedert.fail("Date with invalid month should throw exception.");
        } catch (ParseException e) {
        }
        try {
            SimpleDateFormat sdf = OpenmrsUtil.getDateFormat(new Locale("en", "GB"));
            sdf.parse("32/1/2001");
            replacedert.fail("Date with invalid day should throw exception.");
        } catch (ParseException e) {
        }
        try {
            SimpleDateFormat sdf = OpenmrsUtil.getDateFormat(new Locale("en", "US"));
            sdf.parse("13/1/2001");
            replacedert.fail("Date with invalid month should throw exception.");
        } catch (ParseException e) {
        }
        try {
            SimpleDateFormat sdf = OpenmrsUtil.getDateFormat(new Locale("en", "US"));
            sdf.parse("1/32/2001");
            replacedert.fail("Date with invalid day should throw exception.");
        } catch (ParseException e) {
        }
    }

    @Test
    public void openmrsDateFormat_shouldAllowSingleDigitDatesAndMonths() throws ParseException {
        SimpleDateFormat sdf = OpenmrsUtil.getDateFormat(new Locale("en"));
        sdf.parse("1/1/2001");
    }

    @Test
    public void openmrsDateFormat_shouldNotAllowTwoDigitYears() {
        try {
            SimpleDateFormat sdf = OpenmrsUtil.getDateFormat(new Locale("en"));
            sdf.parse("01/01/01");
            replacedert.fail("Date with two-digit year should throw exception.");
        } catch (ParseException e) {
        }
    }

    /**
     * @see OpenmrsUtil#shortenedStackTrace(String)
     */
    @Test
    public void shortenedStackTrace_shouldRemoveSpringframeworkAndReflectionRelatedLines() {
        String test = "ca.uhn.hl7v2.HL7Exception: Error while processing HL7 message: ORU_R01\n" + "\tat org.openmrs.hl7.impl.HL7ServiceImpl.processHL7Message(HL7ServiceImpl.java:752)\n" + "\tat sun.reflect.GeneratedMethodAccessor262.invoke(Unknown Source)\n" + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n" + "\tat java.lang.reflect.Method.invoke(Method.java:597)\n" + "\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)\n" + "\tat org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)\n" + "\tat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)\n" + "\tat $Proxy106.processHL7Message(Unknown Source)\n" + "\tat sun.reflect.GeneratedMethodAccessor262.invoke(Unknown Source)\n" + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n" + "\tat java.lang.reflect.Method.invoke(Method.java:597)\n" + "\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)\n" + "\tat org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)\n" + "\tat org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:107)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)\n" + "\tat org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)\n" + "\tat org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)\n" + "\tat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)\n" + "\tat $Proxy107.processHL7Message(Unknown Source)\n" + "\tat sun.reflect.GeneratedMethodAccessor262.invoke(Unknown Source)\n" + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n" + "\tat java.lang.reflect.Method.invoke(Method.java:597)\n" + "\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)\n" + "\tat org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)\n" + "\tat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)\n" + "\tat $Proxy107.processHL7Message(Unknown Source)\n" + "\tat sun.reflect.GeneratedMethodAccessor262.invoke(Unknown Source)\n" + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n" + "\tat java.lang.reflect.Method.invoke(Method.java:597)\n" + "\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)\n" + "\tat org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)\n" + "\tat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)\n" + "\tat $Proxy138.processHL7Message(Unknown Source)\n" + "\tat org.openmrs.hl7.impl.HL7ServiceImpl.processHL7InQueue(HL7ServiceImpl.java:657)\n" + "\tat sun.reflect.GeneratedMethodAccessor260.invoke(Unknown Source)\n" + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n" + "\tat java.lang.reflect.Method.invoke(Method.java:597)\n" + "\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)\n" + "\tat org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)\n" + "\tat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)\n" + "\tat $Proxy106.processHL7InQueue(Unknown Source)\n" + "\tat sun.reflect.GeneratedMethodAccessor260.invoke(Unknown Source)\n" + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n" + "\tat java.lang.reflect.Method.invoke(Method.java:597)\n" + "\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)\n" + "\tat org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)\n" + "\tat org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:107)\n" + "\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)\n" + "\tat org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)\n" + "\tat $Proxy138.processHL7InQueue(Unknown Source)\n" + "\tat org.openmrs.hl7.HL7InQueueProcessor.processHL7InQueue(HL7InQueueProcessor.java:61)\n" + "\tat org.openmrs.hl7.HL7InQueueProcessor.processNextHL7InQueue(HL7InQueueProcessor.java:91)\n" + "\tat org.openmrs.hl7.HL7InQueueProcessor.processHL7InQueue(HL7InQueueProcessor.java:110)\n" + "\tat org.openmrs.scheduler.tasks.ProcessHL7InQueueTask.execute(ProcessHL7InQueueTask.java:57)\n" + "\tat org.openmrs.scheduler.tasks.TaskThreadedInitializationWrapper.execute(TaskThreadedInitializationWrapper.java:72)\n" + "\tat org.openmrs.scheduler.timer.TimerSchedulerTask.run(TimerSchedulerTask.java:48)\n" + "\tat java.util.TimerThread.mainLoop(Timer.java:512)\n" + "\tat java.util.TimerThread.run(Timer.java:462) " + "Caused by: ca.uhn.hl7v2.app.ApplicationException: ca.uhn.hl7v2.HL7Exception: Could not resolve patient by identifier\n" + "\tat org.openmrs.hl7.handler.ORUR01Handler.processMessage(ORUR01Handler.java:132)\n" + "\tat ca.uhn.hl7v2.app.MessageTypeRouter.processMessage(MessageTypeRouter.java:52)\n" + "\tat org.openmrs.hl7.impl.HL7ServiceImpl.processHL7Message(HL7ServiceImpl.java:749) ... 101 more " + "Caused by: ca.uhn.hl7v2.HL7Exception: Could not resolve patient by identifier\n" + "\tat org.openmrs.hl7.handler.ORUR01Handler.getPatientByIdentifier(ORUR01Handler.java:998)\n" + "\tat org.openmrs.hl7.handler.ORUR01Handler.processORU_R01(ORUR01Handler.java:184)\n" + "\tat org.openmrs.hl7.handler.ORUR01Handler.processMessage(ORUR01Handler.java:124) ... 103 more";
        String expected = "ca.uhn.hl7v2.HL7Exception: Error while processing HL7 message: ORU_R01\n" + "\tat org.openmrs.hl7.impl.HL7ServiceImpl.processHL7Message(HL7ServiceImpl.java:752)\n" + "\tat [ignored] ...\n" + "\tat $Proxy106.processHL7Message(Unknown Source)\n" + "\tat [ignored] ...\n" + "\tat org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:107)\n" + "\tat [ignored] ...\n" + "\tat $Proxy107.processHL7Message(Unknown Source)\n" + "\tat [ignored] ...\n" + "\tat $Proxy107.processHL7Message(Unknown Source)\n" + "\tat [ignored] ...\n" + "\tat $Proxy138.processHL7Message(Unknown Source)\n" + "\tat org.openmrs.hl7.impl.HL7ServiceImpl.processHL7InQueue(HL7ServiceImpl.java:657)\n" + "\tat [ignored] ...\n" + "\tat $Proxy106.processHL7InQueue(Unknown Source)\n" + "\tat [ignored] ...\n" + "\tat org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:107)\n" + "\tat [ignored] ...\n" + "\tat $Proxy138.processHL7InQueue(Unknown Source)\n" + "\tat org.openmrs.hl7.HL7InQueueProcessor.processHL7InQueue(HL7InQueueProcessor.java:61)\n" + "\tat org.openmrs.hl7.HL7InQueueProcessor.processNextHL7InQueue(HL7InQueueProcessor.java:91)\n" + "\tat org.openmrs.hl7.HL7InQueueProcessor.processHL7InQueue(HL7InQueueProcessor.java:110)\n" + "\tat org.openmrs.scheduler.tasks.ProcessHL7InQueueTask.execute(ProcessHL7InQueueTask.java:57)\n" + "\tat org.openmrs.scheduler.tasks.TaskThreadedInitializationWrapper.execute(TaskThreadedInitializationWrapper.java:72)\n" + "\tat org.openmrs.scheduler.timer.TimerSchedulerTask.run(TimerSchedulerTask.java:48)\n" + "\tat java.util.TimerThread.mainLoop(Timer.java:512)\n" + "\tat java.util.TimerThread.run(Timer.java:462) " + "Caused by: ca.uhn.hl7v2.app.ApplicationException: ca.uhn.hl7v2.HL7Exception: Could not resolve patient by identifier\n" + "\tat org.openmrs.hl7.handler.ORUR01Handler.processMessage(ORUR01Handler.java:132)\n" + "\tat ca.uhn.hl7v2.app.MessageTypeRouter.processMessage(MessageTypeRouter.java:52)\n" + "\tat org.openmrs.hl7.impl.HL7ServiceImpl.processHL7Message(HL7ServiceImpl.java:749) ... 101 more " + "Caused by: ca.uhn.hl7v2.HL7Exception: Could not resolve patient by identifier\n" + "\tat org.openmrs.hl7.handler.ORUR01Handler.getPatientByIdentifier(ORUR01Handler.java:998)\n" + "\tat org.openmrs.hl7.handler.ORUR01Handler.processORU_R01(ORUR01Handler.java:184)\n" + "\tat org.openmrs.hl7.handler.ORUR01Handler.processMessage(ORUR01Handler.java:124) ... 103 more";
        replacedert.replacedertEquals("stack trace was not shortened properly", expected, OpenmrsUtil.shortenedStackTrace(test));
    }

    /**
     * @see OpenmrsUtil#shortenedStackTrace(String)
     */
    @Test
    public void shortenedStackTrace_shouldReturnNullIfStackTraceIsNull() {
        replacedert.replacedertNull("null value was not returned with null parameter", OpenmrsUtil.shortenedStackTrace(null));
    }

    /**
     * @see OpenmrsUtil#nullSafeEqualsIgnoreCase(String,String)
     */
    @Test
    public void nullSafeEqualsIgnoreCase_shouldBeCaseInsensitive() {
        replacedert.replacedertTrue(OpenmrsUtil.nullSafeEqualsIgnoreCase("equal", "Equal"));
    }

    /**
     * @see OpenmrsUtil#nullSafeEqualsIgnoreCase(String,String)
     */
    @Test
    public void nullSafeEqualsIgnoreCase_shouldReturnFalseIfOnlyOneOfTheStringsIsNull() {
        replacedert.replacedertFalse(OpenmrsUtil.nullSafeEqualsIgnoreCase(null, ""));
    }

    @Test
    public void storeProperties_shouldEscapeSlashes() throws IOException {
        Charset utf8 = StandardCharsets.UTF_8;
        String expectedProperty = "blacklistRegex";
        String expectedValue = "[^\\p{InBasicLatin}\\p{InLatin1Supplement}]";
        Properties properties = new Properties();
        properties.setProperty(expectedProperty, expectedValue);
        ByteArrayOutputStream actual = new ByteArrayOutputStream();
        ByteArrayOutputStream expected = new ByteArrayOutputStream();
        OpenmrsUtil.storeProperties(properties, actual, null);
        // Java's underlying implementation correctly writes:
        // blacklistRegex=[^\\p{InBasicLatin}\\p{InLatin1Supplement}]
        // This method didn't exist in Java 5, which is why we wrote a utility method in the first place, so we should
        // just get rid of our own implementation, and use the underlying java one.
        properties.store(new OutputStreamWriter(expected, utf8), null);
        replacedertThat(actual.toByteArray(), is(expected.toByteArray()));
    }

    /**
     * @throws IOException
     * @see OpenmrsUtil#copyFile(InputStream, OutputStream)
     */
    @Test
    public void copyFile_shouldNotCopyTheOutputstreamWhenOutputstreamIsNull() throws IOException {
        String exampleInputStreamString = "ExampleInputStream";
        ByteArrayInputStream input = new ByteArrayInputStream(exampleInputStreamString.getBytes());
        OutputStream output = null;
        OpenmrsUtil.copyFile(input, output);
        replacedertNull(output);
        replacedertNotNull(input);
    }

    /**
     * @throws IOException
     * @see OpenmrsUtil#copyFile(InputStream, OutputStream)
     */
    @Test
    public void copyFile_shouldNotCopyTheOutputstreamIfInputstreamIsNull() throws IOException {
        InputStream input = null;
        ByteArrayOutputStream output = spy(new ByteArrayOutputStream());
        OpenmrsUtil.copyFile(input, output);
        replacedertNull(input);
        replacedertNotNull(output);
        verify(output, times(1)).close();
    }

    /**
     * @throws IOException
     * @see OpenmrsUtil#copyFile(InputStream, OutputStream)
     */
    @Test
    public void copyFile_shouldCopyInputstreamToOutputstreamAndCloseTheOutputstream() throws IOException {
        String exampleInputStreamString = "ExampleInputStream";
        ByteArrayInputStream expectedByteArrayInputStream = new ByteArrayInputStream(exampleInputStreamString.getBytes());
        ByteArrayOutputStream output = spy(new ByteArrayOutputStream());
        OpenmrsUtil.copyFile(expectedByteArrayInputStream, output);
        expectedByteArrayInputStream.reset();
        ByteArrayInputStream byteArrayInputStreamFromOutputStream = new ByteArrayInputStream(output.toByteArray());
        replacedertTrue(IOUtils.contentEquals(expectedByteArrayInputStream, byteArrayInputStreamFromOutputStream));
        verify(output, times(1)).close();
    }
}

19 View Complete Implementation : AddressSupport.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.GlobalPropertyListener#globalPropertyChanged(org.openmrs.GlobalProperty)
 */
@Override
public void globalPropertyChanged(GlobalProperty newValue) {
    if (!OpenmrsConstants.GLOBAL_PROPERTY_ADDRESS_TEMPLATE.equals(newValue.getProperty())) {
        return;
    }
    try {
        setAddressTemplate(newValue.getPropertyValue());
    } catch (Exception ex) {
        log.error("Error in new xml global property value", ex);
        setAddressTemplate(new ArrayList<>());
    }
}

19 View Complete Implementation : ModuleFileParser.java
Copyright Apache License 2.0
Author : isstac
private GlobalProperty createGlobalPropertyWithDatatype(String property, String defaultValue, String description, String datatypeClreplacedname, String datatypeConfig) {
    GlobalProperty globalProperty = null;
    try {
        Clreplaced<CustomDatatype<?>> datatypeClazz = (Clreplaced<CustomDatatype<?>>) Clreplaced.forName(datatypeClreplacedname).replacedubclreplaced(CustomDatatype.clreplaced);
        globalProperty = new GlobalProperty(property, defaultValue, description, datatypeClazz, datatypeConfig);
    } catch (ClreplacedCastException ex) {
        log.error("The clreplaced specified by 'datatypeClreplacedname' (" + datatypeClreplacedname + ") must be a subtype of 'org.openmrs.customdatatype.CustomDatatype<?>'.", ex);
    } catch (ClreplacedNotFoundException ex) {
        log.error("The clreplaced specified by 'datatypeClreplacedname' (" + datatypeClreplacedname + ") could not be found.", ex);
    }
    return globalProperty;
}

19 View Complete Implementation : ModuleFileParser.java
Copyright Apache License 2.0
Author : isstac
private GlobalProperty createGlobalProperty(String property, String defaultValue, String description, String datatypeClreplacedname, String datatypeConfig) {
    GlobalProperty globalProperty = null;
    if (property.isEmpty()) {
        log.warn("'property' is required for global properties. Given '{}'", property);
        return globalProperty;
    }
    if (!datatypeClreplacedname.isEmpty()) {
        globalProperty = createGlobalPropertyWithDatatype(property, defaultValue, description, datatypeClreplacedname, datatypeConfig);
    } else {
        globalProperty = new GlobalProperty(property, defaultValue, description);
    }
    return globalProperty;
}

18 View Complete Implementation : FormServiceTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * 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);
}

18 View Complete Implementation : AdministrationServiceTest.java
Copyright Apache License 2.0
Author : isstac
@Test
public void saveGlobalProperty_shouldNotAllowDifferentPropertiesToHaveTheSameStringWithDifferentCase() {
    executeDataSet("org/openmrs/api/include/AdministrationServiceTest-globalproperties.xml");
    // sanity check
    String orig = adminService.getGlobalProperty("another-global-property");
    replacedertEquals("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");
    replacedertEquals("somethingelse", prop);
    orig = adminService.getGlobalProperty("another-global-property");
    replacedertEquals("somethingelse", orig);
}

18 View Complete Implementation : GlobalLocaleListTest.java
Copyright Apache License 2.0
Author : isstac
@Test
public void globalPropertyChanged_shouldSetAllowedLocalesIfGlobalPropertyIsAnEmptyString() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "");
    globalLocaleList.globalPropertyChanged(gp);
    replacedertThat(globalLocaleList.getAllowedLocales(), contains(Locale.ROOT));
}

18 View Complete Implementation : GlobalLocaleListTest.java
Copyright Apache License 2.0
Author : isstac
@Test
public void globalPropertyChanged_shouldSetAllowedLocalesIfGlobalPropertyContainsTwoLocales() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_CA,fr");
    globalLocaleList.globalPropertyChanged(gp);
    replacedertThat(globalLocaleList.getAllowedLocales(), contains(Locale.CANADA, Locale.FRENCH));
}

18 View Complete Implementation : HibernateAdministrationDAO.java
Copyright Apache License 2.0
Author : isstac
@Override
public boolean isDatabaseStringComparisonCaseSensitive() {
    GlobalProperty gp = (GlobalProperty) sessionFactory.getCurrentSession().get(GlobalProperty.clreplaced, OpenmrsConstants.GP_CASE_SENSITIVE_DATABASE_STRING_COMPARISON);
    if (gp != null) {
        return Boolean.valueOf(gp.getPropertyValue());
    } else {
        return true;
    }
}

18 View Complete Implementation : HibernateAdministrationDAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.db.AdministrationDAO#getGlobalProperty(java.lang.String)
 */
@Override
public String getGlobalProperty(String propertyName) throws DAOException {
    GlobalProperty gp = getGlobalPropertyObject(propertyName);
    // if no gp exists, return a null value
    if (gp == null) {
        return null;
    }
    return gp.getPropertyValue();
}

18 View Complete Implementation : ExistingOrNewVisitAssignmentHandler.java
Copyright Apache License 2.0
Author : isstac
@Override
public void globalPropertyChanged(GlobalProperty newValue) {
    setEncounterVisitMapping(new HashMap<>());
}

18 View Complete Implementation : AdministrationServiceImpl.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.AdministrationService#purgeGlobalProperties(java.util.List)
 */
@Override
public void purgeGlobalProperties(List<GlobalProperty> globalProperties) throws APIException {
    for (GlobalProperty globalProperty : globalProperties) {
        Context.getAdministrationService().purgeGlobalProperty(globalProperty);
    }
}

18 View Complete Implementation : OrderServiceImpl.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see GlobalPropertyListener#globalPropertyChanged(org.openmrs.GlobalProperty)
 */
@Override
public void globalPropertyChanged(GlobalProperty newValue) {
    setOrderNumberGenerator(null);
}

17 View Complete Implementation : HibernateAdministrationDAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.db.AdministrationDAO#deleteGlobalProperty(GlobalProperty)
 */
@Override
public void deleteGlobalProperty(GlobalProperty property) throws DAOException {
    sessionFactory.getCurrentSession().delete(property);
}

17 View Complete Implementation : AdministrationServiceImpl.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.AdministrationService#updateGlobalProperty(java.lang.String,
 *      java.lang.String)
 */
@Override
public void updateGlobalProperty(String propertyName, String propertyValue) throws IllegalStateException {
    GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(propertyName);
    if (gp == null) {
        throw new IllegalStateException("Global property with the given propertyName does not exist" + propertyName);
    }
    gp.setPropertyValue(propertyValue);
    dao.saveGlobalProperty(gp);
}

17 View Complete Implementation : GlobalLocaleList.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.GlobalPropertyListener#globalPropertyChanged(org.openmrs.GlobalProperty)
 */
@Override
public void globalPropertyChanged(GlobalProperty newValue) {
    allowedLocales = new LinkedHashSet<>();
    for (String allowedLocaleString : newValue.getPropertyValue().split(",")) {
        Locale allowedLocale = LocaleUtility.fromSpecification(allowedLocaleString.trim());
        if (allowedLocale != null) {
            allowedLocales.add(allowedLocale);
        }
    }
}

17 View Complete Implementation : AdministrationServiceTest.java
Copyright Apache License 2.0
Author : isstac
@Test
public void saveGlobalProperty_shouldOverwriteGlobalPropertyIfExists() {
    executeDataSet(ADMIN_INITIAL_DATA_XML);
    GlobalProperty gp = adminService.getGlobalPropertyObject("a_valid_gp_key");
    replacedertEquals("correct-value", gp.getPropertyValue());
    gp.setPropertyValue("new-even-more-correct-value");
    adminService.saveGlobalProperty(gp);
    replacedertEquals("new-even-more-correct-value", adminService.getGlobalProperty("a_valid_gp_key"));
}

17 View Complete Implementation : AdministrationServiceTest.java
Copyright Apache License 2.0
Author : isstac
@Test
public void getGlobalPropertyByUuid_shouldFindObjectGivenValidUuid() {
    String uuid = "4f55827e-26fe-102b-80cb-0017a47871b3";
    GlobalProperty prop = adminService.getGlobalPropertyByUuid(uuid);
    replacedertEquals("locale.allowed.list", prop.getProperty());
}

17 View Complete Implementation : LocationServiceTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * @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);
    replacedert.replacedertEquals("Unknown Location", Context.getLocationService().getDefaultLocation().getName());
}

17 View Complete Implementation : LocationServiceTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * @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);
    replacedert.replacedertEquals("Test Parent Location", Context.getLocationService().getDefaultLocation().getName());
}

17 View Complete Implementation : LocaleUtilityTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * This test doesn't really test anything, and it should ALWAYS be the last method in this
 * clreplaced. <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);
}

17 View Complete Implementation : LocationUtilityTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see LocationUtility#getDefaultLocation()
 */
@Test
public void getDefaultLocation_shouldReturnTheUpdatedDefaultLocationWhenTheValueOfTheGlobalPropertyIsChanged() {
    // sanity check
    replacedert.replacedertEquals("Unknown Location", LocationUtility.getDefaultLocation().getName());
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCATION_NAME, "Xanadu", "Testing");
    Context.getAdministrationService().saveGlobalProperty(gp);
    replacedert.replacedertEquals("Xanadu", LocationUtility.getDefaultLocation().getName());
}

16 View Complete Implementation : AdministrationServiceImpl.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.AdministrationService#purgeGlobalProperty(org.openmrs.GlobalProperty)
 */
@Override
public void purgeGlobalProperty(GlobalProperty globalProperty) throws APIException {
    notifyGlobalPropertyDelete(globalProperty.getProperty());
    dao.deleteGlobalProperty(globalProperty);
}

16 View Complete Implementation : AdministrationServiceImpl.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.GlobalPropertyListener#globalPropertyChanged(org.openmrs.GlobalProperty)
 */
@Override
public void globalPropertyChanged(GlobalProperty newValue) {
    if (newValue.getProperty().equals(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST)) {
        // reset the calculated locale values
        presentationLocales = null;
    }
}

16 View Complete Implementation : AdministrationServiceImpl.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.AdministrationService#saveGlobalProperties(java.util.List)
 */
@Override
@CacheEvict(value = "userSearchLocales", allEntries = true)
public List<GlobalProperty> saveGlobalProperties(List<GlobalProperty> props) throws APIException {
    log.debug("saving a list of global properties");
    // add all of the new properties
    for (GlobalProperty prop : props) {
        if (prop.getProperty() != null && prop.getProperty().length() > 0) {
            Context.getAdministrationService().saveGlobalProperty(prop);
        }
    }
    return props;
}

16 View Complete Implementation : AdministrationServiceImpl.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.AdministrationService#getAllowedLocales()
 */
@Override
@Transactional(readOnly = true)
public List<Locale> getAllowedLocales() {
    // lazy-load the global locale list and initialize with current global property value
    if (globalLocaleList == null) {
        globalLocaleList = new GlobalLocaleList();
        Context.getAdministrationService().addGlobalPropertyListener(globalLocaleList);
    }
    Set<Locale> allowedLocales = globalLocaleList.getAllowedLocales();
    // update the GlobalLocaleList.allowedLocales by faking a global property change
    if (allowedLocales == null) {
        // use a default language of "english" if they have cleared this GP for some reason
        String currentPropertyValue = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, LocaleUtility.getDefaultLocale().toString());
        GlobalProperty allowedLocalesProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, currentPropertyValue);
        globalLocaleList.globalPropertyChanged(allowedLocalesProperty);
        allowedLocales = globalLocaleList.getAllowedLocales();
    }
    // allowedLocales is guaranteed to not be null at this point
    return new ArrayList<>(allowedLocales);
}

16 View Complete Implementation : ModuleUtil.java
Copyright Apache License 2.0
Author : isstac
/**
 * Returns all modules that are marked as mandatory. Currently this means there is a
 * <moduleid>.mandatory=true global property.
 *
 * @return list of modules ids for mandatory modules
 * @should return mandatory module ids
 */
public static List<String> getMandatoryModules() {
    List<String> mandatoryModuleIds = new ArrayList<>();
    try {
        List<GlobalProperty> props = Context.getAdministrationService().getGlobalPropertiesBySuffix(".mandatory");
        for (GlobalProperty prop : props) {
            if ("true".equalsIgnoreCase(prop.getPropertyValue())) {
                mandatoryModuleIds.add(prop.getProperty().replace(".mandatory", ""));
            }
        }
    } catch (Exception e) {
        log.warn("Unable to get the mandatory module list", e);
    }
    return mandatoryModuleIds;
}

16 View Complete Implementation : AdministrationServiceTest.java
Copyright Apache License 2.0
Author : isstac
@Test
public void getGlobalPropertiesByPrefix_shouldReturnAllRelevantGlobalPropertiesInTheDatabase() {
    executeDataSet("org/openmrs/api/include/AdministrationServiceTest-globalproperties.xml");
    List<GlobalProperty> properties = adminService.getGlobalPropertiesByPrefix("fake.module.");
    for (GlobalProperty property : properties) {
        replacedertTrue(property.getProperty().startsWith("fake.module."));
        replacedertTrue(property.getPropertyValue().startsWith("correct-value"));
    }
}

16 View Complete Implementation : ProviderServiceTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see ProviderService#getUnknownProvider()
 */
@Test
public void getUnknownProvider_shouldGetTheUnknownProviderAccount() {
    Provider provider = new Provider();
    provider.setPerson(newPerson("Unknown Provider"));
    provider.setIdentifier("Test Unknown Provider");
    provider = service.saveProvider(provider);
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GP_UNKNOWN_PROVIDER_UUID, provider.getUuid(), null);
    Context.getAdministrationService().saveGlobalProperty(gp);
    replacedertEquals(provider, service.getUnknownProvider());
}

16 View Complete Implementation : HibernateAdministrationDAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.db.AdministrationDAO#saveGlobalProperty(org.openmrs.GlobalProperty)
 */
@Override
public GlobalProperty saveGlobalProperty(GlobalProperty gp) throws DAOException {
    GlobalProperty gpObject = getGlobalPropertyObject(gp.getProperty());
    if (gpObject != null) {
        gpObject.setPropertyValue(gp.getPropertyValue());
        gpObject.setDescription(gp.getDescription());
        sessionFactory.getCurrentSession().update(gpObject);
        return gpObject;
    } else {
        sessionFactory.getCurrentSession().save(gp);
        return gp;
    }
}

16 View Complete Implementation : HibernateOrderDAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.db.OrderDAO#getNextOrderNumberSeedSequenceValue()
 */
@Override
public Long getNextOrderNumberSeedSequenceValue() {
    GlobalProperty globalProperty = (GlobalProperty) sessionFactory.getCurrentSession().get(GlobalProperty.clreplaced, OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED, LockOptions.UPGRADE);
    if (globalProperty == null) {
        throw new APIException("GlobalProperty.missing", new Object[] { OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED });
    }
    String gpTextValue = globalProperty.getPropertyValue();
    if (StringUtils.isBlank(gpTextValue)) {
        throw new APIException("GlobalProperty.invalid.value", new Object[] { OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED });
    }
    Long gpNumericValue;
    try {
        gpNumericValue = Long.parseLong(gpTextValue);
    } catch (NumberFormatException ex) {
        throw new APIException("GlobalProperty.invalid.value", new Object[] { OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED });
    }
    globalProperty.setPropertyValue(String.valueOf(gpNumericValue + 1));
    sessionFactory.getCurrentSession().save(globalProperty);
    return gpNumericValue;
}

16 View Complete Implementation : AdministrationServiceImpl.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.AdministrationService#setGlobalProperty(java.lang.String,
 *      java.lang.String)
 */
@Override
public void setGlobalProperty(String propertyName, String propertyValue) throws APIException {
    GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(propertyName);
    if (gp == null) {
        gp = new GlobalProperty();
        gp.setProperty(propertyName);
    }
    gp.setPropertyValue(propertyValue);
    Context.getAdministrationService().saveGlobalProperty(gp);
}

15 View Complete Implementation : AdministrationServiceImpl.java
Copyright Apache License 2.0
Author : isstac
/**
 * Calls global property listeners registered for this create/change
 *
 * @param gp
 */
private void notifyGlobalPropertyChange(GlobalProperty gp) {
    for (GlobalPropertyListener listener : eventListeners.getGlobalPropertyListeners()) {
        if (listener.supportsPropertyName(gp.getProperty())) {
            listener.globalPropertyChanged(gp);
        }
    }
}

15 View Complete Implementation : ModuleFileParser.java
Copyright Apache License 2.0
Author : isstac
private List<GlobalProperty> extractGlobalProperties(Element configRoot) {
    List<GlobalProperty> result = new ArrayList<>();
    NodeList propNodes = configRoot.getElementsByTagName("globalProperty");
    if (propNodes.getLength() == 0) {
        return result;
    }
    log.debug("# global properties: {}", propNodes.getLength());
    int i = 0;
    while (i < propNodes.getLength()) {
        Element gpElement = (Element) propNodes.item(i);
        GlobalProperty globalProperty = extractGlobalProperty(gpElement);
        if (globalProperty != null) {
            result.add(globalProperty);
        }
        i++;
    }
    return result;
}

15 View Complete Implementation : AdministrationServiceTest.java
Copyright Apache License 2.0
Author : isstac
@Test
public void saveGlobalProperty_shouldSaveAGlobalPropertyWhoseTypedValueIsHandledByACustomDatatype() {
    GlobalProperty gp = new GlobalProperty();
    gp.setProperty("What time is it?");
    gp.setDatatypeClreplacedname(DateDatatype.clreplaced.getName());
    gp.setValue(new Date());
    adminService.saveGlobalProperty(gp);
    replacedertNotNull(gp.getValueReference());
}

15 View Complete Implementation : GlobalPropertiesTestHelper.java
Copyright Apache License 2.0
Author : isstac
public void purgeGlobalProperty(String propertyName) {
    GlobalProperty globalProperty = administrationService.getGlobalPropertyObject(propertyName);
    if (globalProperty != null) {
        administrationService.purgeGlobalProperty(globalProperty);
    }
    replacedert.replacedertNull(administrationService.getGlobalProperty(propertyName));
}

15 View Complete Implementation : LocaleUtilityTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see LocaleUtility#getLocalesInOrder()
 */
@Test
public void getLocalesInOrder_shouldReturnASetOfLocalesWithNoDuplicates() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "lu_UG, lu, sw_KE, en_US, en, en, en_GB, sw_KE", "Test Allowed list of locales");
    Context.getAdministrationService().saveGlobalProperty(gp);
    GlobalProperty defaultLocale = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, "lu", "Test Allowed list of locales");
    Context.getAdministrationService().saveGlobalProperty(defaultLocale);
    Locale lu_UG = new Locale("lu", "UG");
    Context.setLocale(lu_UG);
    // note that unique list of locales should be lu_UG, lu, sw_KE, en_US, en
    replacedert.replacedertEquals(6, LocaleUtility.getLocalesInOrder().size());
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE, ""));
}

14 View Complete Implementation : HibernateContextDAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see ContextDAO#updateSearchIndex()
 */
@Override
public void updateSearchIndex() {
    try {
        log.info("Updating the search index... It may take a few minutes.");
        Search.getFullTextSession(sessionFactory.getCurrentSession()).createIndexer().startAndWait();
        GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GP_SEARCH_INDEX_VERSION);
        if (gp == null) {
            gp = new GlobalProperty(OpenmrsConstants.GP_SEARCH_INDEX_VERSION);
        }
        gp.setPropertyValue(OpenmrsConstants.SEARCH_INDEX_VERSION.toString());
        Context.getAdministrationService().saveGlobalProperty(gp);
        log.info("Finished updating the search index");
    } catch (Exception e) {
        throw new RuntimeException("Failed to update the search index", e);
    }
}

14 View Complete Implementation : AdministrationServiceTest.java
Copyright Apache License 2.0
Author : isstac
@Test
public void updateGlobalProperty_shouldUpdateAGlobalPropertyWhoseTypedvalueIsHandledByACustomDatatype() {
    GlobalProperty gp = new GlobalProperty();
    gp.setProperty("Flag");
    gp.setDatatypeClreplacedname(BooleanDatatype.clreplaced.getName());
    gp.setValue(Boolean.FALSE);
    adminService.saveGlobalProperty(gp);
    replacedertEquals(adminService.getGlobalProperty("Flag"), "false");
    adminService.updateGlobalProperty("Flag", Boolean.TRUE.toString());
    replacedertEquals(adminService.getGlobalProperty("Flag"), "true");
}

14 View Complete Implementation : AdministrationServiceTest.java
Copyright Apache License 2.0
Author : isstac
@Test
@Ignore
public void setImplementationId_shouldSetUuidOnImplementationIdGlobalProperty() {
    ImplementationId validId = new ImplementationId();
    validId.setImplementationId("JUNIT-TEST");
    validId.setName("JUNIT-TEST implementation id");
    validId.setPreplacedphrase("This is the junit test preplacedphrase");
    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);
    replacedertNotNull(gp.getUuid());
}

13 View Complete Implementation : LocaleUtilityTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * @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
    replacedert.replacedertEquals(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
    replacedert.replacedertEquals(Locale.replacedANESE, LocaleUtility.getDefaultLocale());
    // clear GP default locale
    gp.setPropertyValue("");
    Context.getAdministrationService().saveGlobalProperty(gp);
}

13 View Complete Implementation : LocaleUtilityTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see LocaleUtility#getLocalesInOrder()
 */
@Test
public void getLocalesInOrder_shouldReturnASetOfLocalesWithAPredictableOrder() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "lu, sw_KE, en_US, en_GB", "Test Allowed list of locales");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Locale lu_UG = new Locale("lu", "UG");
    Context.setLocale(lu_UG);
    Set<Locale> localesInOrder = LocaleUtility.getLocalesInOrder();
    Iterator<Locale> it = localesInOrder.iterator();
    replacedert.replacedertEquals(new Locale("lu", "UG"), it.next());
    replacedert.replacedertEquals(LocaleUtility.getDefaultLocale(), it.next());
    replacedert.replacedertEquals(new Locale("lu"), it.next());
    replacedert.replacedertEquals(new Locale("sw", "KE"), it.next());
    replacedert.replacedertEquals(new Locale("en", "US"), it.next());
    replacedert.replacedertEquals(new Locale("en"), it.next());
}

13 View Complete Implementation : BasicFormBuilder.java
Copyright Apache License 2.0
Author : projectbuendia
private static Concept getObsSectionConcept() {
    Concept concept = Context.getConceptService().getConceptByName(CONCEPT_NAME_MEDICAL_RECORD_OBSERVATIONS);
    if (concept != null) {
        return concept;
    }
    String conceptId = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS);
    if (conceptId != null && StringUtils.isNumeric(conceptId)) {
        concept = Context.getConceptService().getConcept(Integer.parseInt(conceptId));
        if (concept != null) {
            return concept;
        }
    }
    concept = new Concept();
    concept.addName(new ConceptName(CONCEPT_NAME_MEDICAL_RECORD_OBSERVATIONS, Context.getLocale()));
    concept.addDescription(new ConceptDescription("General description for clinical observations entered into the system.", Context.getLocale()));
    concept.setConceptClreplaced(new ConceptClreplaced(CONCEPT_CLreplaced_MISC));
    concept.setDatatype(new ConceptDatatype(CONCEPT_DATATYPE_NA));
    concept = Context.getConceptService().saveConcept(concept);
    GlobalProperty globalProperty = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS);
    if (globalProperty == null) {
        globalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS, concept.getConceptId().toString(), "The concept id of the MEDICAL_RECORD_OBSERVATIONS concept.  " + "This concept_id is presumed to be the generic grouping (obr) concept in hl7 messages.  " + "An obs_group row is not created for this concept.");
    } else {
        globalProperty.setPropertyValue(concept.getConceptId().toString());
    }
    Context.getAdministrationService().saveGlobalProperty(globalProperty);
    return concept;
}

11 View Complete Implementation : ExistingOrNewVisitAssignmentHandlerTest.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see ExistingVisitreplacedignmentHandler#beforeCreateEncounter(Encounter)
 */
@Test
public void beforeCreateEncounter_shouldreplacedignMappingGlobalPropertyVisitType() {
    Encounter encounter = Context.getEncounterService().getEncounter(1);
    replacedert.replacedertNull(encounter.getVisit());
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(encounter.getEncounterDatetime());
    calendar.set(Calendar.YEAR, 1900);
    encounter.setEncounterDatetime(calendar.getTime());
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GP_ENCOUNTER_TYPE_TO_VISIT_TYPE_MAPPING, "3:4, 5:2, 1:2, 2:2");
    Context.getAdministrationService().saveGlobalProperty(gp);
    new ExistingOrNewVisitreplacedignmentHandler().beforeCreateEncounter(encounter);
    replacedert.replacedertNotNull(encounter.getVisit());
    // should be set according to: 1:2 encounterTypeId:visitTypeId
    replacedert.replacedertEquals(1, encounter.getEncounterType().getEncounterTypeId().intValue());
    replacedert.replacedertEquals(Context.getVisitService().getVisitType(2), encounter.getVisit().getVisitType());
}