-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#288 - Fix Global Properties loading for OpenMRS 2.7+ #289
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...rg/openmrs/module/initializer/api/loaders/GlobalPropertiesLoaderIntegration_2_7_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.initializer.api.loaders; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openmrs.GlobalProperty; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.initializer.DomainBaseModuleContextSensitive_2_7_Test; | ||
import org.openmrs.module.initializer.api.gp.GlobalPropertiesLoader; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* This test is intended to be a copy of the GlobalPropertiesLoaderIntegrationTest from the api module, | ||
* but included within the api-2.7 module to test that global properties loading from xml works successfully | ||
* in an OpenMRS 2.7 environment | ||
*/ | ||
public class GlobalPropertiesLoaderIntegration_2_7_Test extends DomainBaseModuleContextSensitive_2_7_Test { | ||
|
||
@Autowired | ||
private GlobalPropertiesLoader loader; | ||
|
||
@Test | ||
public void loadGlobalProperties_shouldLoadGlobalProperties() { | ||
|
||
// Replay | ||
loader.load(); | ||
|
||
// Verif | ||
Assert.assertEquals("GP one one", Context.getAdministrationService().getGlobalProperty("gp.gp11")); | ||
Assert.assertEquals("GP one two", Context.getAdministrationService().getGlobalProperty("gp.gp12")); | ||
Assert.assertEquals("GP two one", Context.getAdministrationService().getGlobalProperty("gp.gp21")); | ||
Assert.assertEquals("GP three one", Context.getAdministrationService().getGlobalProperty("gp.gp31")); | ||
Assert.assertEquals("GP three two", Context.getAdministrationService().getGlobalProperty("gp.gp32")); | ||
Assert.assertEquals("GP three three", Context.getAdministrationService().getGlobalProperty("gp.gp33")); | ||
} | ||
|
||
@Test | ||
public void load_shouldOverrideGlobalProperties() { | ||
|
||
// Setup | ||
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty("gp.gp11", "foobar")); | ||
Assert.assertEquals("foobar", Context.getAdministrationService().getGlobalProperty("gp.gp11")); | ||
|
||
// Replay | ||
loader.load(); | ||
|
||
// Verif | ||
Assert.assertEquals("GP one one", Context.getAdministrationService().getGlobalProperty("gp.gp11")); | ||
} | ||
|
||
@Test | ||
public void load_shouldNotAffectOtherGlobalProperties() { | ||
|
||
// Setup | ||
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty("gp.foo", "Foo")); | ||
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty("gp.bar", "Bar")); | ||
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty("gp.baz", "Baz")); | ||
|
||
// Replay | ||
loader.load(); | ||
|
||
// Verif | ||
Assert.assertEquals("Foo", Context.getAdministrationService().getGlobalProperty("gp.foo")); | ||
Assert.assertEquals("Bar", Context.getAdministrationService().getGlobalProperty("gp.bar")); | ||
Assert.assertEquals("Baz", Context.getAdministrationService().getGlobalProperty("gp.baz")); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
api-2.7/src/test/resources/testAppDataDir/configuration/globalproperties/gp1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<config> | ||
<globalProperties> | ||
<globalProperty> | ||
<property>gp.gp11</property> | ||
<value>GP one one</value> | ||
</globalProperty> | ||
<globalProperty> | ||
<property>gp.gp12</property> | ||
<value>GP one two</value> | ||
</globalProperty> | ||
</globalProperties> | ||
</config> |
8 changes: 8 additions & 0 deletions
8
api-2.7/src/test/resources/testAppDataDir/configuration/globalproperties/gp2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<config> | ||
<globalProperties> | ||
<globalProperty> | ||
<property>gp.gp21</property> | ||
<value>GP two one</value> | ||
</globalProperty> | ||
</globalProperties> | ||
</config> |
19 changes: 19 additions & 0 deletions
19
api-2.7/src/test/resources/testAppDataDir/configuration/globalproperties/gp3.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<config> | ||
<comment> | ||
It should be ok to just add some comments like this. | ||
</comment> | ||
<globalProperties> | ||
<globalProperty> | ||
<property>gp.gp31</property> | ||
<value>GP three one</value> | ||
</globalProperty> | ||
<globalProperty> | ||
<property>gp.gp32</property> | ||
<value>GP three two</value> | ||
</globalProperty> | ||
<globalProperty> | ||
<property>gp.gp33</property> | ||
<value>GP three three</value> | ||
</globalProperty> | ||
</globalProperties> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic seems to imply that it fails on older versions of core. We might not necessarily need a separate
InitializerSerializer_2_7
, but it could be useful to have some unit test(s) enforcing the logic .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean about
this logic seems to imply that it fails on older versions of core
. I don't think it implies that. But your point about having some unit tests that actually show this failure and prove that this fixes it is totally valid. I copied the test from theapi
project (which tests using OpenMRS 2.1) into theapi-2.7
project (which tests using OpenMRS 2.7). This test fails without my fix above, which is easily testable if you comment out lines 62 and 63 above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mseaton, sorry for the confusion. I was just wondering why the error is logged instead of actually re-throwing a runtime exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see @Ruhanga . It is logged as it is assumed that any Exception thrown by this block is due to the fact that this method is not present in the Xstream library, which is an expected condition for any platform < 2.7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, makes sense to me. Thanks @mseaton.