From 5a2afe46ef1bce4f97ae887109b8d6cdfa212a23 Mon Sep 17 00:00:00 2001 From: Ruhanga <41738040+Ruhanga@users.noreply.github.com> Date: Wed, 2 Jul 2025 16:34:24 +0000 Subject: [PATCH 1/5] ADDR-140: Migrate from XStream to Jackson --- .../config/AddressConfigurationLoader.java | 31 +++-------- .../AddressConfigurationLoaderTest.java | 23 +++++---- .../include/addressConfiguration.json | 51 +++++++++++++++++++ pom.xml | 2 +- 4 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.json diff --git a/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoader.java b/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoader.java index 9c454ba5..8cb8e5cf 100644 --- a/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoader.java +++ b/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoader.java @@ -1,7 +1,5 @@ package org.openmrs.module.addresshierarchy.config; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.xml.DomDriver; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; @@ -13,6 +11,7 @@ import org.openmrs.module.addresshierarchy.AddressHierarchyLevel; import org.openmrs.module.addresshierarchy.service.AddressHierarchyService; import org.openmrs.module.addresshierarchy.util.AddressHierarchyImportUtil; +import org.openmrs.serialization.JacksonSerializer; import org.openmrs.util.OpenmrsConstants; import org.openmrs.util.OpenmrsUtil; @@ -20,7 +19,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Method; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; @@ -151,8 +149,8 @@ public static void wipeAddressHierarchy() { public static void installAddressTemplate(Object addressTemplate) { try { log.info("Installing address template"); - String xml = Context.getSerializationService().getDefaultSerializer().serialize(addressTemplate); - setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ADDRESS_TEMPLATE, xml); + String json = getSerializer().serialize(addressTemplate); + setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ADDRESS_TEMPLATE, json); } catch (Exception e) { throw new IllegalArgumentException("Unable to serialize and save address template", e); @@ -245,7 +243,7 @@ public static AddressConfiguration readFromFile(File file) { */ public static AddressConfiguration readFromString(String configuration) { try { - return (AddressConfiguration) getSerializer().fromXML(configuration); + return (AddressConfiguration) getSerializer().deserialize(configuration, AddressConfiguration.class); } catch (Exception e) { throw new IllegalArgumentException("Unable to load address configuration from configuration file. Please check the format of this file", e); @@ -256,28 +254,15 @@ public static AddressConfiguration readFromString(String configuration) { * Writes a serialized String representing the address configuration from an AddressConfiguration object */ public static String writeToString(AddressConfiguration configuration) { - return getSerializer().toXML(configuration); + return getSerializer().serialize(configuration); } /** * @return the serializer instance used to load configuration from file */ - public static XStream getSerializer() { - XStream xs = new XStream(new DomDriver()); - try { - Method allowTypeHierarchy = XStream.class.getMethod("allowTypeHierarchy", Class.class); - allowTypeHierarchy.invoke(xs, AddressConfiguration.class); - allowTypeHierarchy.invoke(xs, AddressComponent.class); - allowTypeHierarchy.invoke(xs, AddressHierarchyFile.class); - log.debug("Successfully configured address configuration serializer with allowed types"); - } - catch (Exception e) { - log.debug("Error configuring address configuration serializer with allowed types", e); - } - xs.alias("addressConfiguration", AddressConfiguration.class); - xs.alias("addressComponent", AddressComponent.class); - xs.alias("addressHierarchyFile", AddressHierarchyFile.class); - return xs; + public static JacksonSerializer getSerializer() { + JacksonSerializer serializer = Context.getRegisteredComponent("jacksonSerializer", JacksonSerializer.class); + return serializer; } /** diff --git a/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java b/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java index 30271d9e..6537eb56 100644 --- a/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java +++ b/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java @@ -1,5 +1,6 @@ package org.openmrs.module.addresshierarchy.config; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.nio.file.Files; @@ -7,29 +8,29 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.openmrs.module.addresshierarchy.AddressField; +import org.openmrs.test.jupiter.BaseContextSensitiveTest; import org.openmrs.util.OpenmrsClassLoader; -public class AddressConfigurationLoaderTest { +public class AddressConfigurationLoaderTest extends BaseContextSensitiveTest { protected final Log log = LogFactory.getLog(getClass()); - public static final String CONFIG_RESOURCE = "org/openmrs/module/addresshierarchy/include/addressConfiguration.xml"; + public static final String CONFIG_RESOURCE = "org/openmrs/module/addresshierarchy/include/addressConfiguration.json"; - @Before - public void setup() throws IOException { + @BeforeAll + public static void setup() throws IOException { System.setProperty("user.home", Files.createTempDirectory(null).toString()); // see OpenmrsUtil.getApplicationDataDirectory() } @Test public void should_writeToString() throws Exception { AddressConfiguration config = getAddressConfiguration(); - String actualXml = IOUtils.toString(OpenmrsClassLoader.getInstance().getResourceAsStream(CONFIG_RESOURCE), "UTF-8"); - String expectedXml = AddressConfigurationLoader.writeToString(config); - Assert.assertEquals(StringUtils.deleteWhitespace(expectedXml), StringUtils.deleteWhitespace(actualXml)); + String actualJson = IOUtils.toString(OpenmrsClassLoader.getInstance().getResourceAsStream(CONFIG_RESOURCE), "UTF-8"); + String expectedJson = AddressConfigurationLoader.writeToString(config); + assertEquals(StringUtils.deleteWhitespace(expectedJson), StringUtils.deleteWhitespace(actualJson)); } @Test @@ -38,7 +39,7 @@ public void should_readFromString() throws Exception { String serialized = IOUtils.toString(OpenmrsClassLoader.getInstance().getResourceAsStream(CONFIG_RESOURCE), "UTF-8"); AddressConfiguration actualConfig = AddressConfigurationLoader.readFromString(serialized); - Assert.assertEquals(expectedConfig, actualConfig); + assertEquals(expectedConfig, actualConfig); } protected AddressConfiguration getAddressConfiguration() { diff --git a/api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.json b/api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.json new file mode 100644 index 00000000..2f7af908 --- /dev/null +++ b/api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.json @@ -0,0 +1,51 @@ +{ + "wipe":false, + "addressComponents":[ + { + "field":"COUNTRY", + "nameMapping":"Country", + "sizeMapping":40, + "elementDefault":"Sierra Leone", + "requiredInHierarchy":true + }, + { + "field":"STATE_PROVINCE", + "nameMapping":"Province/Area", + "sizeMapping":40, + "elementDefault":null, + "requiredInHierarchy":true + }, + { + "field":"COUNTY_DISTRICT", + "nameMapping":"District", + "sizeMapping":40, + "elementDefault":null, + "requiredInHierarchy":false + }, + { + "field":"CITY_VILLAGE", + "nameMapping":"Chiefdom", + "sizeMapping":40, + "elementDefault":null, + "requiredInHierarchy":false + }, + { + "field":"ADDRESS_1", + "nameMapping":"Address", + "sizeMapping":80, + "elementDefault":null, + "requiredInHierarchy":false + } + ], + "lineByLineFormat":[ + "address1", + "cityVillage", + "countyDistrict, stateProvince", + "country" + ], + "addressHierarchyFile":{ + "filename":"address-hierarchy-entries.csv", + "entryDelimiter":"|", + "identifierDelimiter":"^" + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 70cf4c6f..39a0cb5d 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,7 @@ - 2.7.0 + 2.8.0-SNAPSHOT UTF-8 1.1.0-SNAPSHOT 1.22.0 From d273ce5f6fed51692439b198d02109ad91051250 Mon Sep 17 00:00:00 2001 From: Ruhanga <41738040+Ruhanga@users.noreply.github.com> Date: Wed, 2 Jul 2025 19:36:20 +0000 Subject: [PATCH 2/5] ADD-140: Fixed failing tests --- .../config/AddressConfiguration.java | 19 ++++++++------ .../AddressConfigurationLoaderTest.java | 25 ++++++++++++++----- .../include/addressConfiguration.json | 6 +---- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfiguration.java b/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfiguration.java index 33e38a47..f237e9bf 100644 --- a/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfiguration.java +++ b/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfiguration.java @@ -5,6 +5,8 @@ import org.openmrs.api.context.Context; import org.openmrs.util.OpenmrsUtil; +import com.fasterxml.jackson.annotation.JsonIgnore; + import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -76,6 +78,7 @@ public void setAddressHierarchyFile(AddressHierarchyFile addressHierarchyFile) { /** * @return a new AddressTemplate instance for the given configuration */ + @JsonIgnore public Object getAddressTemplate() { Object addressTemplate = null; try { @@ -136,19 +139,19 @@ public boolean equals(Object obj) { if (this.getAddressComponents().size() != that.getAddressComponents().size()) { return false; } - for (int i=0; i that.getAddressComponents().contains(item)); } + if (this.getLineByLineFormat().size() != that.getLineByLineFormat().size()) { return false; } - for (int i=0; i that.getLineByLineFormat().contains(item)); } + if (!OpenmrsUtil.nullSafeEquals(this.getAddressHierarchyFile(), that.getAddressHierarchyFile())) { return false; } diff --git a/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java b/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java index 6537eb56..6bae8fbb 100644 --- a/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java +++ b/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java @@ -1,5 +1,6 @@ package org.openmrs.module.addresshierarchy.config; +import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.nio.file.Files; @@ -8,11 +9,14 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.openmrs.GlobalProperty; +import org.openmrs.api.AdministrationService; import org.openmrs.module.addresshierarchy.AddressField; import org.openmrs.test.jupiter.BaseContextSensitiveTest; import org.openmrs.util.OpenmrsClassLoader; +import org.springframework.beans.factory.annotation.Autowired; public class AddressConfigurationLoaderTest extends BaseContextSensitiveTest { @@ -20,16 +24,25 @@ public class AddressConfigurationLoaderTest extends BaseContextSensitiveTest { public static final String CONFIG_RESOURCE = "org/openmrs/module/addresshierarchy/include/addressConfiguration.json"; - @BeforeAll - public static void setup() throws IOException { + @Autowired + private AdministrationService adminService; + + @BeforeEach + public void setup() throws IOException { System.setProperty("user.home", Files.createTempDirectory(null).toString()); // see OpenmrsUtil.getApplicationDataDirectory() + adminService.saveGlobalProperty( + new GlobalProperty("addressHierarchy.configuration.serializer.whitelist.types", + "org.openmrs.module.addresshierarchy.**")); + adminService.saveGlobalProperty( + new GlobalProperty("layout.address.format", + " address1 address2 cityVillage stateProvince country postalCode ")); } @Test public void should_writeToString() throws Exception { AddressConfiguration config = getAddressConfiguration(); - String actualJson = IOUtils.toString(OpenmrsClassLoader.getInstance().getResourceAsStream(CONFIG_RESOURCE), "UTF-8"); - String expectedJson = AddressConfigurationLoader.writeToString(config); + String expectedJson = IOUtils.toString(OpenmrsClassLoader.getInstance().getResourceAsStream(CONFIG_RESOURCE), "UTF-8"); + String actualJson = AddressConfigurationLoader.writeToString(config); assertEquals(StringUtils.deleteWhitespace(expectedJson), StringUtils.deleteWhitespace(actualJson)); } @@ -39,7 +52,7 @@ public void should_readFromString() throws Exception { String serialized = IOUtils.toString(OpenmrsClassLoader.getInstance().getResourceAsStream(CONFIG_RESOURCE), "UTF-8"); AddressConfiguration actualConfig = AddressConfigurationLoader.readFromString(serialized); - assertEquals(expectedConfig, actualConfig); + assertTrue(expectedConfig.equals(actualConfig)); } protected AddressConfiguration getAddressConfiguration() { diff --git a/api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.json b/api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.json index 2f7af908..7fae53b9 100644 --- a/api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.json +++ b/api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.json @@ -12,35 +12,31 @@ "field":"STATE_PROVINCE", "nameMapping":"Province/Area", "sizeMapping":40, - "elementDefault":null, "requiredInHierarchy":true }, { "field":"COUNTY_DISTRICT", "nameMapping":"District", "sizeMapping":40, - "elementDefault":null, "requiredInHierarchy":false }, { "field":"CITY_VILLAGE", "nameMapping":"Chiefdom", "sizeMapping":40, - "elementDefault":null, "requiredInHierarchy":false }, { "field":"ADDRESS_1", "nameMapping":"Address", "sizeMapping":80, - "elementDefault":null, "requiredInHierarchy":false } ], "lineByLineFormat":[ "address1", "cityVillage", - "countyDistrict, stateProvince", + "countyDistrict,stateProvince", "country" ], "addressHierarchyFile":{ From f1520cf99611e5942805c406c8f0bb4cc90fd102 Mon Sep 17 00:00:00 2001 From: Ruhanga <41738040+Ruhanga@users.noreply.github.com> Date: Thu, 3 Jul 2025 18:01:32 +0000 Subject: [PATCH 3/5] ADDR-140: Finalize migration from XStream to Jackson --- .../config/AddressConfigurationLoader.java | 2 +- .../AddressHierarchyActivatorTest.java | 36 +++++++------- .../AddressConfigurationLoaderTest.java | 8 +--- .../include/addressConfiguration.xml | 47 ------------------- .../addressConfiguration.json | 46 ++++++++++++++++++ .../addresshierarchy/addressConfiguration.xml | 46 ------------------ .../AddressHierarchyAjaxControllerTest.java | 8 ++-- 7 files changed, 70 insertions(+), 123 deletions(-) delete mode 100644 api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.xml create mode 100644 api/src/test/resources/testAppDataDir/configuration/addresshierarchy/addressConfiguration.json delete mode 100644 api/src/test/resources/testAppDataDir/configuration/addresshierarchy/addressConfiguration.xml diff --git a/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoader.java b/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoader.java index 8cb8e5cf..67091465 100644 --- a/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoader.java +++ b/api/src/main/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoader.java @@ -28,7 +28,7 @@ */ public class AddressConfigurationLoader { - protected static final String ADDR_CONFIG_FILE_NAME = "addressConfiguration.xml"; + protected static final String ADDR_CONFIG_FILE_NAME = "addressConfiguration.json"; public static final String NOT_COMPUTABLE_CHECKSUM = "not_computable_checksum"; public static final String NOT_READABLE_CHECKSUM = "not_readadble_checksum"; diff --git a/api/src/test/java/org/openmrs/module/addresshierarchy/AddressHierarchyActivatorTest.java b/api/src/test/java/org/openmrs/module/addresshierarchy/AddressHierarchyActivatorTest.java index 419ce381..0276998a 100644 --- a/api/src/test/java/org/openmrs/module/addresshierarchy/AddressHierarchyActivatorTest.java +++ b/api/src/test/java/org/openmrs/module/addresshierarchy/AddressHierarchyActivatorTest.java @@ -1,42 +1,44 @@ package org.openmrs.module.addresshierarchy; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openmrs.GlobalProperty; import org.openmrs.api.context.Context; import org.openmrs.module.addresshierarchy.config.AddressConfigurationLoader; import org.openmrs.module.addresshierarchy.config.ConfigDirUtil; import org.openmrs.module.addresshierarchy.service.AddressHierarchyService; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.openmrs.test.Verifies; +import org.openmrs.test.jupiter.BaseContextSensitiveTest; import org.openmrs.util.OpenmrsConstants; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.util.CollectionUtils; import java.io.File; import java.util.HashSet; import java.util.List; -import java.util.Properties; import java.util.Set; -@DirtiesContext -public class AddressHierarchyActivatorTest extends BaseModuleContextSensitiveTest { +public class AddressHierarchyActivatorTest extends BaseContextSensitiveTest { private static String APP_DATA_TEST_DIRECTORY = "testAppDataDir"; @Autowired private AddressHierarchyActivator activator; - @Before + @BeforeEach public void setup() { Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(AddressHierarchyConstants.GLOBAL_PROP_INITIALIZE_ADDRESS_HIERARCHY_CACHE_ON_STARTUP, "true")); setAppDataDirPath(APP_DATA_TEST_DIRECTORY); + Context.getAdministrationService().saveGlobalProperty( + new GlobalProperty("addressHierarchy.configuration.serializer.whitelist.types", + "org.openmrs.module.addresshierarchy.**")); + Assert.assertTrue(CollectionUtils.isEmpty(Context.getService(AddressHierarchyService.class).getAddressHierarchyLevels())); } @@ -46,7 +48,6 @@ private void setAppDataDirPath(String strPath) { } @Test - @Verifies(value = "should load new address hierarchy configuration from configuration/addresshierarchy", method = "started()") public void started_shouldLoadAddressHierachyConfig() { // Setup @@ -91,7 +92,6 @@ private void assertConfigurationAsExpected() { } @Test - @Verifies(value = "should not load again an address hierarchy configuration from configuration/addresshierarchy", method = "started()") public void started_shouldNotReLoadAddressHierachyConfig() { // Setup @@ -119,7 +119,6 @@ public void started_shouldNotReLoadAddressHierachyConfig() { } @Test - @Verifies(value = "should keep existing entries when wipe is set to false", method = "started()") public void started_shouldNotWipeExistingEntries() { // Setup @@ -162,9 +161,8 @@ public void started_shouldNotWipeExistingEntries() { Assert.assertEquals("Point Shirley", pointShirley.getName()); } - @Ignore + @Disabled @Test - @Verifies(value = "should wipe existing entries when wipe is set to true", method = "started()") public void started_shouldWipeExistingEntries() { // Setup @@ -202,9 +200,9 @@ public void started_shouldWipeExistingEntries() { for (AddressHierarchyEntry entry : entries) { entryNames.add(entry.getName()); } - Assert.assertFalse(entryNames.contains("Beacon Hill")); - Assert.assertFalse(entryNames.contains("Jamaica Plain")); - Assert.assertTrue(entryNames.contains("Auburndale")); - Assert.assertTrue(entryNames.contains("Chestnut Hill")); + assertFalse(entryNames.contains("Beacon Hill")); + assertFalse(entryNames.contains("Jamaica Plain")); + assertTrue(entryNames.contains("Auburndale")); + assertTrue(entryNames.contains("Chestnut Hill")); } } \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java b/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java index 6bae8fbb..acf3b3ef 100644 --- a/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java +++ b/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java @@ -1,10 +1,9 @@ package org.openmrs.module.addresshierarchy.config; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.nio.file.Files; - import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -28,14 +27,11 @@ public class AddressConfigurationLoaderTest extends BaseContextSensitiveTest { private AdministrationService adminService; @BeforeEach - public void setup() throws IOException { + public void setup() throws IOException, Exception { System.setProperty("user.home", Files.createTempDirectory(null).toString()); // see OpenmrsUtil.getApplicationDataDirectory() adminService.saveGlobalProperty( new GlobalProperty("addressHierarchy.configuration.serializer.whitelist.types", "org.openmrs.module.addresshierarchy.**")); - adminService.saveGlobalProperty( - new GlobalProperty("layout.address.format", - " address1 address2 cityVillage stateProvince country postalCode ")); } @Test diff --git a/api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.xml b/api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.xml deleted file mode 100644 index ddc9a3ee..00000000 --- a/api/src/test/resources/org/openmrs/module/addresshierarchy/include/addressConfiguration.xml +++ /dev/null @@ -1,47 +0,0 @@ - - false - - - COUNTRY - Country - 40 - Sierra Leone - true - - - STATE_PROVINCE - Province/Area - 40 - true - - - COUNTY_DISTRICT - District - 40 - false - - - CITY_VILLAGE - Chiefdom - 40 - false - - - ADDRESS_1 - Address - 80 - false - - - - address1 - cityVillage - countyDistrict, stateProvince - country - - - address-hierarchy-entries.csv - | - ^ - - \ No newline at end of file diff --git a/api/src/test/resources/testAppDataDir/configuration/addresshierarchy/addressConfiguration.json b/api/src/test/resources/testAppDataDir/configuration/addresshierarchy/addressConfiguration.json new file mode 100644 index 00000000..fad14a26 --- /dev/null +++ b/api/src/test/resources/testAppDataDir/configuration/addresshierarchy/addressConfiguration.json @@ -0,0 +1,46 @@ +{ + "addressComponents": [ + { + "field": "COUNTRY", + "nameMapping": "Country", + "sizeMapping": "40", + "elementDefault": "United States", + "requiredInHierarchy": true + }, + { + "field": "STATE_PROVINCE", + "nameMapping": "State", + "sizeMapping": "40", + "requiredInHierarchy": true + }, + { + "field": "COUNTY_DISTRICT", + "nameMapping": "County", + "sizeMapping": "40", + "requiredInHierarchy": true + }, + { + "field": "CITY_VILLAGE", + "nameMapping": "Citi", + "sizeMapping": "40", + "requiredInHierarchy": true + }, + { + "field": "NEIGHBORHOOD_CELL", + "nameMapping": "Neighborhood", + "sizeMapping": "80", + "requiredInHierarchy": false + } + ], + "lineByLineFormat": [ + "neighborhoodCell", + "cityVillage", + "countyDistrict, stateProvince", + "country" + ], + "addressHierarchyFile": { + "filename": "address-hierarchy-entries.csv", + "entryDelimiter": ",", + "identifierDelimiter": "^" + } +} \ No newline at end of file diff --git a/api/src/test/resources/testAppDataDir/configuration/addresshierarchy/addressConfiguration.xml b/api/src/test/resources/testAppDataDir/configuration/addresshierarchy/addressConfiguration.xml deleted file mode 100644 index e721c100..00000000 --- a/api/src/test/resources/testAppDataDir/configuration/addresshierarchy/addressConfiguration.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - COUNTRY - Country - 40 - United States - true - - - STATE_PROVINCE - State - 40 - true - - - COUNTY_DISTRICT - County - 40 - true - - - CITY_VILLAGE - Citi - 40 - true - - - NEIGHBORHOOD_CELL - Neighborhood - 80 - false - - - - neighborhoodCell - cityVillage - countyDistrict, stateProvince - country - - - address-hierarchy-entries.csv - , - ^ - - \ No newline at end of file diff --git a/omod/src/test/java/org/openmrs/module/addresshierarchy/web/controller/ajax/AddressHierarchyAjaxControllerTest.java b/omod/src/test/java/org/openmrs/module/addresshierarchy/web/controller/ajax/AddressHierarchyAjaxControllerTest.java index 64161ddc..f3e4f9b5 100644 --- a/omod/src/test/java/org/openmrs/module/addresshierarchy/web/controller/ajax/AddressHierarchyAjaxControllerTest.java +++ b/omod/src/test/java/org/openmrs/module/addresshierarchy/web/controller/ajax/AddressHierarchyAjaxControllerTest.java @@ -3,9 +3,9 @@ import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openmrs.test.jupiter.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.ModelMap; @@ -24,7 +24,7 @@ public class AddressHierarchyAjaxControllerTest extends BaseModuleContextSensiti @Autowired private AddressHierarchyAjaxController controller; - @Before + @BeforeEach public void setupDatabase() throws Exception { initializeInMemoryDatabase(); authenticate(); From 1ecb90a7e0d8d1dffdf58ead7464878a3f9c76ed Mon Sep 17 00:00:00 2001 From: Ruhanga <41738040+Ruhanga@users.noreply.github.com> Date: Fri, 4 Jul 2025 10:03:00 +0000 Subject: [PATCH 4/5] ADDR-140: Use BaseModuleContextSensitiveTest instead of BaseContextSensitiveTest --- .../addresshierarchy/AddressHierarchyActivatorTest.java | 4 ++-- .../config/AddressConfigurationLoaderTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/addresshierarchy/AddressHierarchyActivatorTest.java b/api/src/test/java/org/openmrs/module/addresshierarchy/AddressHierarchyActivatorTest.java index 0276998a..d25b11d2 100644 --- a/api/src/test/java/org/openmrs/module/addresshierarchy/AddressHierarchyActivatorTest.java +++ b/api/src/test/java/org/openmrs/module/addresshierarchy/AddressHierarchyActivatorTest.java @@ -11,7 +11,7 @@ import org.openmrs.module.addresshierarchy.config.AddressConfigurationLoader; import org.openmrs.module.addresshierarchy.config.ConfigDirUtil; import org.openmrs.module.addresshierarchy.service.AddressHierarchyService; -import org.openmrs.test.jupiter.BaseContextSensitiveTest; +import org.openmrs.test.jupiter.BaseModuleContextSensitiveTest; import org.openmrs.util.OpenmrsConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; @@ -21,7 +21,7 @@ import java.util.List; import java.util.Set; -public class AddressHierarchyActivatorTest extends BaseContextSensitiveTest { +public class AddressHierarchyActivatorTest extends BaseModuleContextSensitiveTest { private static String APP_DATA_TEST_DIRECTORY = "testAppDataDir"; diff --git a/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java b/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java index acf3b3ef..4db0b9a2 100644 --- a/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java +++ b/api/src/test/java/org/openmrs/module/addresshierarchy/config/AddressConfigurationLoaderTest.java @@ -13,11 +13,11 @@ import org.openmrs.GlobalProperty; import org.openmrs.api.AdministrationService; import org.openmrs.module.addresshierarchy.AddressField; -import org.openmrs.test.jupiter.BaseContextSensitiveTest; +import org.openmrs.test.jupiter.BaseModuleContextSensitiveTest; import org.openmrs.util.OpenmrsClassLoader; import org.springframework.beans.factory.annotation.Autowired; -public class AddressConfigurationLoaderTest extends BaseContextSensitiveTest { +public class AddressConfigurationLoaderTest extends BaseModuleContextSensitiveTest { protected final Log log = LogFactory.getLog(getClass()); From 46394fb79c2ffe9e8f0c62ed1cc54d1c9faf0549 Mon Sep 17 00:00:00 2001 From: Ruhanga <41738040+Ruhanga@users.noreply.github.com> Date: Wed, 9 Jul 2025 09:33:07 +0000 Subject: [PATCH 5/5] ADDR-140: Updated OpenMRS version to 3.0.0-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 39a0cb5d..55f3baf3 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,7 @@ - 2.8.0-SNAPSHOT + 3.0.0-SNAPSHOT UTF-8 1.1.0-SNAPSHOT 1.22.0