I’m very new to OpenMRS and still setting up my IDE to get things running, so please bear with me.
I have successfully built openmrs-core (2.3.0-SNAPSHOT) and the webapp is running on jetty. I understand that for the GUI I need to clone and build openmrs-module-legacyui.
With openmrs-module-legacyui (1.6.0-SNAPSHOT) came legacyui-omod and here I’m encountering problems:
legacui-omod doesn’t build due to test failures. These failures seem to be related to localization and it seems that where the name of a property is expected the value is returned:
Patient.saved
Patient gespeichert
With Patient.saved=Patient gespeichert in messages_de.properties.
What I don’t quite understand:
Those test cases should fail no matter what the locale is. So I’m wondering now if I’m doing everything right. Am I perhaps looking at the wrong code meaning shouldn’t I be using openmrs-module-legacyui (1.6.0-SNAPSHOT)?
The failing test cases are more than 3 years old and would have certainly be fixed by now if there really was a problem. So what instead of openmrs-module-legacyui should I be using?
Or should I just skip the tests?
This is really bizarre:
I ran one of the failing unit tests with Locale.setDefault(new Locale("en", "GB")); and it passed.
So I switched my system locale to LANG="en_EN.UTF-8" and all failing tests passed even the one with an NPE.
I’ve uploaded two JUnit exports on pastebin for you to share my surprise.
@Test
@Verifies(value = "should pass if all the form data is valid", method = "saveShortPatient(WebRequest,ShortPatientModel,BindingResult,SessionStatus)")
public void saveShortPatient_shouldPassIfAllTheFormDataIsValid() throws Exception {
I found
messages.properties of openmrs-api are used and messages_de.properties contains Patient.saved while messages_en_GB.properties does not, so when running the test in a German environment it fails
if I add Patient.saved=xxx to messages_en_GB.properties and set Locale.setDefault(new Locale("en")); or Locale.setDefault(new Locale("en", "GB")); the test fails
strangely enough messages_fr.properties contains an entry for Patient.saved but setting the default locale to fr does not make the test fail
adding a messages_fr_FR.properties containing Patient.saved the test fails when using Locale(“fr”)
So if nothing else is specified default locale seems to be en_GB.
Since there is no entry in messages_en_GB for e. g. Patient.saved the returned “value” is Patient.saved, this has been made the expected outcome.
If there is a different default locale two things can happen:
a) the corresponding messages_xx.properties is used, the entry is found and the value is returned, the test fails - e. g. for default locale “de” and “hi”
b) for some reason the corresponding messages_xx.properties is not used, the test passes - e. g. default locale “fr”.
Perhaps it would be a good idea not to rely on the messages.properties of openmrs-api for two reasons:
They are “far away” and any changes there can break test cases in legacyui-omod.
Developers using their own locale might be confused by failing tests spending a lot of time analyzing the problem.
Instead one could set the default locale in each test case to something like “test” and add a messages_test.properties to test/resources of legacyui-omod. That way one can even see that the properties are resolved properly (without making that a failure).