-
Notifications
You must be signed in to change notification settings - Fork 80
#292 - Error loading locations on OpenMRS 2.7 #293
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d519d1d
#292 - Unit test demonstrating error
mseaton 02e0976
Merge branch 'main' into ISSUE-292
mseaton 73cc520
#292 - Simplify test case
mseaton 4f740a6
#292 - Fix to BaseAttributeLineProcessor
mseaton 60662a8
#292 - Cleanup
mseaton f9aec7e
#292 - Cleanup
mseaton 18ad8b6
#292 - Cleanup
mseaton ceae231
Merge branch 'main' into ISSUE-292
mseaton 0e22fd2
#292 - Add release note
mseaton eeb634e
#292 - Fix following code review
mseaton 0aef781
#292 - Formatting
mseaton 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 hidden or 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
200 changes: 200 additions & 0 deletions
200
.../java/org/openmrs/module/initializer/api/loaders/LocationsLoader_2_7_IntegrationTest.java
This file contains hidden or 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,200 @@ | ||
/** | ||
* 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.Before; | ||
import org.junit.Test; | ||
import org.openmrs.Location; | ||
import org.openmrs.LocationAttribute; | ||
import org.openmrs.LocationTag; | ||
import org.openmrs.api.LocationService; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.customdatatype.datatype.DateDatatype; | ||
import org.openmrs.module.initializer.DomainBaseModuleContextSensitive_2_7_Test; | ||
import org.openmrs.module.initializer.api.loc.LocationsLoader; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
|
||
import java.util.Collection; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
|
||
/** | ||
* This is a copy of the LocationsLoaderIntegration test in order to test the same test against | ||
* OpenMRS 2.7 | ||
*/ | ||
public class LocationsLoader_2_7_IntegrationTest extends DomainBaseModuleContextSensitive_2_7_Test { | ||
|
||
@Autowired | ||
@Qualifier("locationService") | ||
private LocationService ls; | ||
|
||
@Autowired | ||
private LocationsLoader loader; | ||
|
||
@Autowired | ||
private DateDatatype dateDatatype; | ||
|
||
private Locale localeEn = Locale.ENGLISH; | ||
|
||
private Locale localeKm = new Locale("km", "KH"); | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
executeDataSet("testdata/test-metadata.xml"); | ||
} | ||
|
||
@Test | ||
public void load_shouldLoadAccordingToCsvFiles() { | ||
// Pre-load verif | ||
{ | ||
Location loc = ls.getLocation(4089); | ||
Assert.assertEquals("a03e395c-b881-49b7-b6fc-983f6bddc7fc", loc.getUuid()); | ||
Assert.assertEquals("Acme Clinic", loc.getName()); | ||
Assert.assertThat(loc.getDescription(), nullValue()); | ||
Assert.assertThat(loc.getParentLocation(), nullValue()); | ||
Assert.assertThat(loc.getTags().size(), is(0)); | ||
|
||
Collection<LocationAttribute> attributes = loc.getActiveAttributes(); | ||
Assert.assertThat(attributes.size(), is(1)); | ||
Assert.assertEquals("2016-04-14", | ||
dateDatatype.serialize((Date) ((LocationAttribute) attributes.toArray()[0]).getValue())); | ||
} | ||
{ | ||
Location loc = ls.getLocation(4090); | ||
Assert.assertEquals("cbaaaab4-d960-4ae9-9b6a-8983fbd947b6", loc.getUuid()); | ||
Assert.assertEquals("Legacy Location", loc.getName()); | ||
Assert.assertEquals("Legacy location that must be retired", loc.getDescription()); | ||
Assert.assertThat(loc.getRetired(), is(false)); | ||
} | ||
|
||
// Replay | ||
loader.load(); | ||
|
||
// Verify fetch by name | ||
{ | ||
Location loc = ls.getLocation("LOCATION_NO_UUID"); | ||
Assert.assertEquals("Main Street", loc.getAddress1()); | ||
Assert.assertEquals("fdddc31a-3930-11ea-9712-a73c3c19744f", loc.getUuid()); | ||
} | ||
// Verify creation with dynamic tag creation | ||
{ | ||
Location loc = ls.getLocation("The Lake Clinic-Cambodia"); | ||
Assert.assertEquals("Paradise Street", loc.getAddress1()); | ||
Assert.assertEquals("Siem Reap", loc.getCountyDistrict()); | ||
Assert.assertEquals("Siem Reap", loc.getStateProvince()); | ||
Assert.assertEquals("Cambodia", loc.getCountry()); | ||
|
||
Set<LocationTag> tags = loc.getTags(); | ||
Assert.assertThat(tags, notNullValue()); | ||
Assert.assertThat(tags.size(), is(2)); | ||
Assert.assertThat(tags.contains(ls.getLocationTagByName("Login Location")), is(true)); | ||
Assert.assertThat(tags.contains(ls.getLocationTagByName("Another Location Tag")), is(true)); | ||
|
||
Collection<LocationAttribute> attributes = loc.getActiveAttributes(); | ||
Assert.assertThat(attributes.size(), is(2)); | ||
Assert.assertEquals("CODE-TLC-123", ((LocationAttribute) attributes.toArray()[0]).getValue()); | ||
Assert.assertEquals("2017-05-15", | ||
dateDatatype.serialize((Date) ((LocationAttribute) attributes.toArray()[1]).getValue())); | ||
} | ||
// Verify creation with Tag| headers | ||
{ | ||
Location loc = ls.getLocation("OPD Room"); | ||
Assert.assertEquals(ls.getLocation("The Lake Clinic-Cambodia"), loc.getParentLocation()); | ||
|
||
Set<LocationTag> tags = loc.getTags(); | ||
Assert.assertThat(tags, notNullValue()); | ||
Assert.assertThat(tags.size(), is(1)); | ||
Assert.assertThat(tags.contains(ls.getLocationTagByName("Facility Location")), is(true)); | ||
} | ||
// Verify that the provided UUID is correctly assigned | ||
{ | ||
Location loc = ls.getLocationByUuid("1cb58794-3c49-11ea-b3eb-f7801304f314"); | ||
Assert.assertNotNull(loc); | ||
Assert.assertEquals("New Location", loc.getName()); | ||
} | ||
// Verify edit | ||
{ | ||
Location loc = ls.getLocationByUuid("a03e395c-b881-49b7-b6fc-983f6bddc7fc"); | ||
Assert.assertEquals("Acme Clinic", loc.getName()); | ||
Assert.assertEquals("This now becomes a child of TLC", loc.getDescription()); | ||
Assert.assertEquals(ls.getLocation("The Lake Clinic-Cambodia"), loc.getParentLocation()); | ||
|
||
Set<LocationTag> tags = loc.getTags(); | ||
Assert.assertThat(tags, notNullValue()); | ||
Assert.assertThat(tags.size(), is(1)); | ||
Assert.assertThat(tags.contains(ls.getLocationTagByName("Login Location")), is(true)); | ||
|
||
Collection<LocationAttribute> attributes = loc.getActiveAttributes(); | ||
Assert.assertThat(attributes.size(), is(1)); | ||
Assert.assertEquals("2019-03-13", | ||
dateDatatype.serialize((Date) ((LocationAttribute) attributes.toArray()[0]).getValue())); | ||
|
||
} | ||
// Verify retire | ||
{ | ||
Location loc = ls.getLocationByUuid("cbaaaab4-d960-4ae9-9b6a-8983fbd947b6"); | ||
Assert.assertThat(loc.getRetired(), is(true)); | ||
} | ||
// Verify that location with an invalid parent isn't created | ||
{ | ||
Location loc = ls.getLocationByUuid("2b9824a3-92f0-4966-8f34-1b105624b267"); | ||
Assert.assertNull(loc); | ||
} | ||
|
||
// verify Locations domain i18n on entries with display:xy fields | ||
{ | ||
Assert.assertEquals("Acme Clinic (translated)", Context.getMessageSourceService() | ||
.getMessage("ui.i18n.Location.name.a03e395c-b881-49b7-b6fc-983f6bddc7fc", null, localeEn)); | ||
Assert.assertEquals("គ្លីនិកអាមី", Context.getMessageSourceService() | ||
.getMessage("ui.i18n.Location.name.a03e395c-b881-49b7-b6fc-983f6bddc7fc", null, localeKm)); | ||
Assert.assertEquals("Acme Clinic (translated)", Context.getMessageSourceService() | ||
.getMessage("org.openmrs.Location.a03e395c-b881-49b7-b6fc-983f6bddc7fc", null, localeEn)); | ||
Assert.assertEquals("គ្លីនិកអាមី", Context.getMessageSourceService() | ||
.getMessage("org.openmrs.Location.a03e395c-b881-49b7-b6fc-983f6bddc7fc", null, localeKm)); | ||
} | ||
// verify no Locations domain i18n on entries without display:xy fields and entries without pre-filled uuids | ||
{ | ||
Assert.assertNotNull(ls.getLocationByUuid("1cb58794-3c49-11ea-b3eb-f7801304f314")); | ||
Assert.assertEquals("ui.i18n.Location.name.1cb58794-3c49-11ea-b3eb-f7801304f314", | ||
Context.getMessageSourceService().getMessage("ui.i18n.Location.name.1cb58794-3c49-11ea-b3eb-f7801304f314", | ||
null, localeEn)); | ||
Assert.assertEquals("ui.i18n.Location.name.1cb58794-3c49-11ea-b3eb-f7801304f314", | ||
Context.getMessageSourceService().getMessage("ui.i18n.Location.name.1cb58794-3c49-11ea-b3eb-f7801304f314", | ||
null, localeKm)); | ||
|
||
Assert.assertEquals("org.openmrs.Location.1cb58794-3c49-11ea-b3eb-f7801304f314", | ||
Context.getMessageSourceService().getMessage("org.openmrs.Location.1cb58794-3c49-11ea-b3eb-f7801304f314", | ||
null, localeEn)); | ||
Assert.assertEquals("org.openmrs.Location.1cb58794-3c49-11ea-b3eb-f7801304f314", | ||
Context.getMessageSourceService().getMessage("org.openmrs.Location.1cb58794-3c49-11ea-b3eb-f7801304f314", | ||
null, localeKm)); | ||
|
||
Location loc = ls.getLocation("The Lake Clinic-Cambodia"); | ||
Assert.assertNotNull(loc); | ||
|
||
String uuid = loc.getUuid(); | ||
Assert.assertEquals("ui.i18n.Location.name." + uuid, | ||
Context.getMessageSourceService().getMessage("ui.i18n.Location.name." + uuid, null, localeEn)); | ||
Assert.assertEquals("ui.i18n.Location.name." + uuid, | ||
Context.getMessageSourceService().getMessage("ui.i18n.Location.name." + uuid, null, localeKm)); | ||
Assert.assertEquals("org.openmrs.Location." + uuid, | ||
Context.getMessageSourceService().getMessage("org.openmrs.Location." + uuid, null, localeEn)); | ||
Assert.assertEquals("org.openmrs.Location." + uuid, | ||
Context.getMessageSourceService().getMessage("org.openmrs.Location." + uuid, null, localeKm)); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
api-2.7/src/test/resources/testAppDataDir/configuration/locations/locations.csv
This file contains hidden or 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 @@ | ||
Uuid,Void/Retire,Name,Description,Parent,Tags,Tag|Facility Location,Attribute|9eca4f4e-707f-4bb8-8289-2f9b6e93803c,Attribute|Last Audit Date,Address 1,Address 2,Address 3,Address 4,Address 5,Address 6,City/Village,County/District,State/Province,Postal Code,Country,display:en,display:km_KH,_order:1000 | ||
,,The Lake Clinic-Cambodia,,,Login Location; Another Location Tag,,CODE-TLC-123,2017-05-15,Paradise Street,,,,,,,Siem Reap,Siem Reap,,Cambodia,The Lake Clinic-Cambodia (translated),គ្លីនីកគ្លីនិក - ប្រទេសកម្ពុជា, | ||
,,OPD Room,,The Lake Clinic-Cambodia,,TRUE,,,,,,,,,,,,,,,, | ||
a03e395c-b881-49b7-b6fc-983f6bddc7fc,,Acme Clinic,This now becomes a child of TLC,The Lake Clinic-Cambodia,Login Location,,,2019-03-13,,,,,,,,,,,,Acme Clinic (translated),គ្លីនិកអាមី, | ||
cbaaaab4-d960-4ae9-9b6a-8983fbd947b6,TRUE,Legacy Location,Legacy location that must be retired,,,,,,,,,,,,,,,,,,, | ||
,,LOCATION_NO_UUID,,,,,,,Main Street,,,,,,,Siem Reap,Siem Reap,,Cambodia,,, | ||
1cb58794-3c49-11ea-b3eb-f7801304f314,,New Location,,,,,,,,,,,,,,,,,,,, | ||
2b9824a3-92f0-4966-8f34-1b105624b267,,Invalid parent location,This location shouldn not be loaded as it has an invalid parent,Invalid parent,,,,,,,,,,,,,,,,,, |
5 changes: 5 additions & 0 deletions
5
api-2.7/src/test/resources/testAppDataDir/configuration/locationtags/locationtags.csv
This file contains hidden or 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,5 @@ | ||
Uuid,Void/Retire,Name,Description | ||
,,Sparse, | ||
b03e395c-b881-49b7-b6fc-983f6befc7fc,,Filled in,A tag with all its fields | ||
a2327745-2970-4752-ac8a-dd0ba131f40e,TRUE,Facility Location, | ||
a1417745-1170-5752-fc8a-dd0ba131f40e,,Supply Room,Don't call it a shed |
This file contains hidden or 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
This file contains hidden or 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.
I guess this was meant to point to
attributeTypeIdentifier
? Would be nice having a unit test covering this - maybe not strictly necessary?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.
Good catch @Ruhanga . I've updated that. This isn't new functionality, my main goal was to ensure all existing unit and integration tests pass, as well as any that I copied into the api-2.7 project, so my assumption is that the existing unit test coverage is sufficiently robust to handle a refactor.